Class: DataShift::GeneratorBase
- Defined in:
- lib/generators/generator_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#remove_list ⇒ Object
Returns the value of attribute remove_list.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename) ⇒ GeneratorBase
constructor
A new instance of GeneratorBase.
-
#prep_remove_list(options) ⇒ Object
Take options and create a list of symbols to remove from headers Rails columns like id, created_at etc are added to the remove list by default Specify :include_rails to keep them in.
-
#prepare_model_headers(method_details_mgr, options = {}) ⇒ Object
Parse options and build collection of headers for a method_details_mgr wrapping a class based on association requirements,.
- #remove_headers(options) ⇒ Object
Constructor Details
#initialize(filename) ⇒ GeneratorBase
Returns a new instance of GeneratorBase.
14 15 16 17 18 |
# File 'lib/generators/generator_base.rb', line 14 def initialize(filename) @filename = filename @headers = [] @remove_list =[] end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
12 13 14 |
# File 'lib/generators/generator_base.rb', line 12 def filename @filename end |
#headers ⇒ Object
Returns the value of attribute headers.
12 13 14 |
# File 'lib/generators/generator_base.rb', line 12 def headers @headers end |
#remove_list ⇒ Object
Returns the value of attribute remove_list.
12 13 14 |
# File 'lib/generators/generator_base.rb', line 12 def remove_list @remove_list end |
Class Method Details
.rails_columns ⇒ Object
20 21 22 |
# File 'lib/generators/generator_base.rb', line 20 def self.rails_columns @rails_standard_columns ||= [:id, :created_at, :created_on, :updated_at, :updated_on] end |
Instance Method Details
#prep_remove_list(options) ⇒ Object
Take options and create a list of symbols to remove from headers Rails columns like id, created_at etc are added to the remove list by default Specify :include_rails to keep them in
82 83 84 85 86 87 88 |
# File 'lib/generators/generator_base.rb', line 82 def prep_remove_list( ) remove_list = [ *[:remove] ].compact.collect{|x| x.to_s.downcase.to_sym } remove_list += GeneratorBase::rails_columns unless([:include_rails]) remove_list end |
#prepare_model_headers(method_details_mgr, options = {}) ⇒ Object
Parse options and build collection of headers for a method_details_mgr wrapping a class based on association requirements,
Default is to include everything
-
:exclude - Association TYPE(s) to exclude completely.
Possible association_type values are given by MethodDetail::supported_types_enum ... [:assignment, :belongs_to, :has_one, :has_many] -
:remove - Array of header names to remove
Rails DB columns like id, created_at, updated_at are removed by default
- :include_rails - Specify to keep Rails columns in mappings
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/generator_base.rb', line 41 def prepare_model_headers(method_details_mgr, = {}) work_list = MethodDetail::supported_types_enum.to_a - [ *[:exclude] ] @headers = [] work_list.each do |assoc_type| method_details_for_assoc_type = method_details_mgr.get_list_of_method_details(assoc_type) next if(method_details_for_assoc_type.nil? || method_details_for_assoc_type.empty?) method_details_for_assoc_type.each do |md| #comparable_association = md.operator.to_s.downcase.to_sym #i = remove_list.index { |r| r == comparable_association } #(i) ? remove_list.delete_at(i) : @headers << "#{md.operator}" @headers << md.operator end end remove_headers() end |
#remove_headers(options) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/generators/generator_base.rb', line 71 def remove_headers() remove_list = prep_remove_list( ) #TODO - more efficient way ? headers.delete_if { |h| remove_list.include?( h.to_sym ) } unless(remove_list.empty?) end |