Module: ActsAsTable::ValueProviderAssociationMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_table/value_provider_association_methods.rb
Overview
ActsAsTable value provider association methods (concern).
Class Method Summary collapse
-
.reflect_on_acts_as_table_value_provider_associations(macro = nil, **options) ⇒ Array<ActiveRecord::Reflection::MacroReflection>
Returns an array of ActiveRecord::Reflection::MacroReflection objects for all ActsAsTable value provider associations in the class.
Instance Method Summary collapse
-
#each_acts_as_table_value_provider(macro = nil, **options, &block) ⇒ Enumerable<ActsAsTable::ValueProvider::InstanceMethods>
Enumerates all associated records for all ActsAsTable value provider associations in the class.
Class Method Details
.reflect_on_acts_as_table_value_provider_associations(macro = nil, **options) ⇒ Array<ActiveRecord::Reflection::MacroReflection>
If you only want to reflect on a certain association type, pass in the symbol (:has_many
, :has_one
, :belongs_to
) as the first parameter.
Returns an array of ActiveRecord::Reflection::MacroReflection objects for all ActsAsTable value provider associations in the class.
16 17 18 19 20 21 22 23 24 |
# File 'app/models/concerns/acts_as_table/value_provider_association_methods.rb', line 16 def reflect_on_acts_as_table_value_provider_associations(macro = nil, **) .assert_valid_keys(:except, :only) self.reflect_on_all_associations(macro).select { |reflection| reflection.klass.acts_as_table_value_provider? }.select { |reflection| ([:except].nil? || ![:except].collect(&:to_sym).include?(reflection.name.to_sym)) && ([:only].nil? || [:only].collect(&:to_sym).include?(reflection.name.to_sym)) } end |
Instance Method Details
#each_acts_as_table_value_provider(macro = nil, **options, &block) ⇒ Enumerable<ActsAsTable::ValueProvider::InstanceMethods>
If you only want to reflect on a certain association type, pass in the symbol (:has_many
, :has_one
, :belongs_to
) as the first parameter.
Enumerates all associated records for all ActsAsTable value provider associations in the class.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/concerns/acts_as_table/value_provider_association_methods.rb', line 36 def each_acts_as_table_value_provider(macro = nil, **, &block) ::Enumerator.new { |enumerator| { belongs_to: [], has_one: [], has_many: [:each], has_and_belongs_to_many: [:each], }.each do |method_name, args| if macro.nil? || (macro == method_name) reflections = self.class.reflect_on_acts_as_table_value_provider_associations(method_name, **) reflections.each do |reflection| self.send(reflection.name).try(*args) { |value_provider| enumerator << value_provider } end end end }.each(&block) end |