Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install generator #29

Merged
merged 1 commit into from
Nov 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
47 changes: 47 additions & 0 deletions lib/generators/enumerate_it/enum/enum_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module EnumerateIt
module Generators
class EnumGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)

argument :attributes, :type => 'array', :default => []

class_option :singular, :type => 'string', :desc => 'Singular name for i18n'

class_option :lang, :type => 'string', :desc => 'Lang to use in i18n', :default => 'en'

desc "Creates an initializer file on config/initializers that extends ActiveRecord::Base with Enumerate_it"
def create_locale
template "locale.yml", File.join('config/locales', "#{singular_name}.yml")
end

desc "Creates an initializer file on config/initializers that extends ActiveRecord::Base with Enumerate_it"
def create_enumerate_it
template "enumerate_it.rb", File.join('app/enumerations', "#{singular_name}.rb")
end

protected

def default_lang
options[:lang]
end

def singular
singular_name
end

def locale_fields
attributes.map(&:name)
end

def fields
if attributes.first.type == :string
attributes.map(&:name)
else
attributes.map do |attribute|
[attribute.name, attribute.type]
end
end
end
end
end
end
8 changes: 8 additions & 0 deletions lib/generators/enumerate_it/install/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Description:
Creates an initializer file for EnumerateIt

Example:
rails generate enumerate_it:install

This will create:
config/initializers/enumerate_it.rb
11 changes: 11 additions & 0 deletions lib/generators/enumerate_it/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module EnumerateIt
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)

def copy_initializer_file
template "enumerate_it_initializer.rb", File.join('config/initializers/', "enumerate_it.rb")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ActiveRecord::Base.extend EnumerateIt
41 changes: 0 additions & 41 deletions lib/generators/enumerate_it_generator.rb

This file was deleted.