Skip to content

Commit

Permalink
Adds install generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kurenn committed Apr 23, 2014
1 parent da95817 commit a50812c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in sabisu.gemspec
gemspec

gem 'railties', github: 'rails/rails'
gem 'activemodel', github: 'rails/rails'
gem 'actionpack', github: 'rails/rails'
13 changes: 13 additions & 0 deletions lib/generators/sabisu/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Sabisu
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)

desc "Creates a Sabisu initializer in your application"

def copy_initializer
template "sabisu.rb", "config/initializers/sabisu.rb"
end
end
end
end
14 changes: 14 additions & 0 deletions lib/generators/sabisu/templates/sabisu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Use this module to configure the sabisu available options

Sabisu.setup do |config|

# Base uri for posting the
# config.base_api_uri = nil

# Ignored attributes for building the forms
# config.ignored_attributes = %w{ created_at updated_at id }

# HTTP methods
# config.http_methods = %w{ GET POST PUT DELETE PATCH }

end
33 changes: 32 additions & 1 deletion lib/sabisu.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
require "sabisu/version"

module Sabisu
# Your code goes here...

# We ignore some attribues that might cause a collision between models
@@default_ignored_attributes = %w{ created_at updated_at id }

# We append the extra attributes you want to ignore to the default ones
mattr_accessor :ignored_attributes
@@ignored_attributes = @@ignored_attributes.to_a + @@default_ignored_attributes

# Base api uri for the endpoints
mattr_accessor :base_api_uri
@@base_api_uri = nil

# HTTP methods for the api
@@default_http_methods = %w{ GET POST PUT DELETE PATCH }

mattr_accessor :http_methods
@@http_methods = @@http_methods.to_a + @@default_http_methods

@@configured = false

def self.configured? #:nodoc:
@@configured
end

#Method to configure sabisu
def self.setup
@@configured = true
yield self
end

end

require 'sabisu/railtie'
14 changes: 14 additions & 0 deletions lib/sabisu/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rails/railtie'

module Sabisu
class Railtie < Rails::Railtie
config.eager_load_namespaces << Sabisu

config.after_initialize do
unless Sabisu.configured?
warn '[Sabisu] Sabisu is not configured in the application and will use the default values.' +
' We recommend you to check the file just created with the installer and setup it up.'
end
end
end
end
1 change: 1 addition & 0 deletions sabisu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Gem::Specification.new do |spec|

spec.add_dependency "activemodel", '~> 4.0'
spec.add_dependency "actionpack", '~> 4.0'
spec.add_dependency "httparty"
end

0 comments on commit a50812c

Please sign in to comment.