Class: RecordLoaderGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- RecordLoaderGenerator
- Defined in:
- lib/generators/record_loader/record_loader_generator.rb
Overview
Rails generator to automatically build record loaders
Constant Summary collapse
- IGNORED_COLUMNS =
%w[created_at updated_at].freeze
Instance Method Summary collapse
- #build_example_hash(size = 2) ⇒ Object
-
#create_directories ⇒ Object
Builds all templates in the templates directory.
-
#initial_setup ⇒ Object
Generally this will only run on generating the first loader.
Instance Method Details
#build_example_hash(size = 2) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/generators/record_loader/record_loader_generator.rb', line 34 def build_example_hash(size = 2) (1..size).each_with_object({}) do |iteration, store| store["Unique #{record_key} #{iteration}"] = loader_attributes.each_with_object({}) do |attribute, config| config[attribute.name] = attribute.value(iteration) end end end |
#create_directories ⇒ Object
Builds all templates in the templates directory
18 19 20 |
# File 'lib/generators/record_loader/record_loader_generator.rb', line 18 def create_directories directory '.', './' end |
#initial_setup ⇒ Object
Generally this will only run on generating the first loader
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/record_loader/record_loader_generator.rb', line 23 def initial_setup # Copy across the application_record_loader.rb unless it already exists copy_file '../static_files/application_record_loader.rb', 'lib/record_loader/application_record_loader.rb', skip: true # Copy across the record_loader.rake unless it already exists copy_file '../static_files/record_loader.rake', 'lib/tasks/record_loader.rake', skip: true end |