Class: ActiveRecord::Generators::SqlPagerGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::SqlPagerGenerator
- Defined in:
- lib/generators/active_record/sql_pager_generator.rb
Instance Method Summary collapse
- #copy_migration ⇒ Object
- #create_model ⇒ Object
- #inject_model_content ⇒ Object
- #model_data ⇒ Object
- #model_exists? ⇒ Boolean
-
#model_path ⇒ Object
Helpers.
Instance Method Details
#copy_migration ⇒ Object
8 9 10 |
# File 'lib/generators/active_record/sql_pager_generator.rb', line 8 def copy_migration migration_template "migration.rb", "db/migrate/sql_pager_create_#{table_name}" end |
#create_model ⇒ Object
12 13 14 |
# File 'lib/generators/active_record/sql_pager_generator.rb', line 12 def create_model invoke 'active_record:model', [name], :migration => false end |
#inject_model_content ⇒ Object
16 17 18 |
# File 'lib/generators/active_record/sql_pager_generator.rb', line 16 def inject_model_content inject_into_class model_path, class_name, model_data if model_exists? end |
#model_data ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/active_record/sql_pager_generator.rb', line 28 def model_data " # Attributes\n attr_accessible :body, :format, :handler, :path, :partial, :locale\n \n # Validation\n validates :body, :presence => true\n validates :handler, :inclusion => ActionView::Template::Handlers.extensions.map(&:to_s)\n validates :format, :inclusion => Mime::SET.symbols.map(&:to_s)\n validates :locale, :inclusion => I18n.available_locales.map(&:to_s)\n validates :path, :presence => true\n \n after_save do\n SqlPager::Resolver.instance(self.class.model_name.underscore).clear_cache\n end\n" end |
#model_exists? ⇒ Boolean
24 25 26 |
# File 'lib/generators/active_record/sql_pager_generator.rb', line 24 def model_exists? File.exists?(File.join(destination_root, model_path)) end |
#model_path ⇒ Object
Helpers
21 22 23 |
# File 'lib/generators/active_record/sql_pager_generator.rb', line 21 def model_path @model_path ||= File.join("app", "models", "#{file_path}.rb") end |