Permalink
Browse files

added railtie that adds autoload path to app/enums

  • Loading branch information...
1 parent 636c416 commit c2805904c6bdccfe6cdda2d1c1dc55d375524d43 @kristianmandrup committed Aug 7, 2012
Showing with 17 additions and 1 deletion.
  1. +2 −0 lib/classy_enum.rb
  2. +9 −0 lib/classy_enum/railtie.rb
  3. +6 −1 lib/generators/classy_enum/classy_enum_generator.rb
View
@@ -4,3 +4,5 @@
require 'classy_enum/valid_values'
require 'classy_enum/base'
require 'classy_enum/active_record'
+
+require 'classy_enum/railtie' if defined?(Rails) && defined?(Rails::Railtie)
@@ -0,0 +1,9 @@
+module ClassyEnum
+ module Rails
+ module Railtie < ::Rails::Railtie
+ initializer "classy enum" do |app|
+ ActiveSupport::Dependencies.autoload_paths << "#{Rails.root}/app/enums"
+ end
+ end
+ end
+end
@@ -6,16 +6,21 @@ class ClassyEnumGenerator < Rails::Generators::NamedBase
class_option :macro, :type => :boolean, :default => false, :banner => 'Generate enums using macros'
class_option :simple, :type => :boolean, :default => false, :banner => 'Use simple macro enum'
+ class_option :file, :type => :string, :default => nil, :banner => 'Override filename'
source_root File.expand_path("../templates", __FILE__)
def copy_files # :nodoc:
empty_directory 'app/enums'
- template "#{template_name}.rb", "app/enums/#{file_name}.rb"
+ template "#{template_name}.rb", "app/enums/#{target_file}.rb"
end
protected
+ def target_file
+ options[:file] || file_name
+ end
+
def template_name
macro? "#{prefix}macro_enum" : 'enum'
end

0 comments on commit c280590

Please sign in to comment.