Module: Linker::Attributes
- Extended by:
- ActiveSupport::Concern
- Includes:
- ConfigurationMethods
- Included in:
- Linker
- Defined in:
- lib/linker/forms/attributes.rb
Constant Summary collapse
- USELESS_COLUMNS_REGEX =
%r{^(updated_at|created_at)$}
Instance Method Summary collapse
- #get_main_model ⇒ Object
- #prepare_attrs ⇒ Object
- #set_delegations ⇒ Object
- #set_reader_for_main_model ⇒ Object
Instance Method Details
#get_main_model ⇒ Object
10 11 12 |
# File 'lib/linker/forms/attributes.rb', line 10 def get_main_model @main_model ||= self.class._main_model.constantize end |
#prepare_attrs ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/linker/forms/attributes.rb', line 14 def prepare_attrs get_main_model set_reader_for_main_model set_delegations set_fields_for_methods(map_has_many_associations) set_fields_for_methods(map_belongs_to_associations, true) set_fields_for_methods(map_has_one_associations, true) create_list_accessors_for(map_has_one_associations) create_list_accessors_for(map_has_and_belongs_to_many_associations) set_remove_accessor(map_has_many_associations) end |
#set_delegations ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/linker/forms/attributes.rb', line 31 def set_delegations # Delegate fields for main model filter_columns(@main_model).each do |c| delegate_attr(c, @main_model.to_s.underscore) end [map_has_one_associations, map_belongs_to_associations].each do |rgroup| rgroup.each do |c| return unless c[:columns] c[:columns].each do |cc| # ap "delegating #{cc} and #{cc}= for #{c[:name]}__#{cc}" self.class.__send__(:delegate, cc, "#{cc}=", to: c[:name].underscore.to_sym, prefix: "#{c[:name]}_") end end end end |
#set_reader_for_main_model ⇒ Object
26 27 28 29 |
# File 'lib/linker/forms/attributes.rb', line 26 def set_reader_for_main_model # Create attr reader for main model self.class.__send__(:attr_reader, @main_model.to_s.underscore) end |