Module: ActiveModel::AttributeFilters::Common::Join::ClassMethods
- Defined in:
- lib/attribute-filters/common_filters/join.rb
Overview
This submodule contains class methods needed to describe attribute joining.
Instance Method Summary collapse
-
#join_attributes(atr_name, parameters = nil)
(also: #join_attribute, #joint_attribute, #joint_attributes, #join_attributes_to, #join_attributes_into, #joins_attribute, #joins_attributes_to, #joins_attributes_into)
This method parametrizes joining operation for an attribute of the given name.
Instance Method Details
#join_attributes(atr_name, parameters = nil) Also known as: join_attribute, joint_attribute, joint_attributes, join_attributes_to, join_attributes_into, joins_attribute, joins_attributes_to, joins_attributes_into
This method returns an undefined value.
This method parametrizes joining operation for an attribute of the given name. It uses attribute set annotations to register parameters used when joining.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/attribute-filters/common_filters/join.rb', line 67 def join_attributes(atr_name, parameters = nil) atr_name.is_a?(Hash) and return atr_name.each_pair { |k, v| join_attribute(k, v) } # process reversed notation p = parameters if atr_name.is_a?(Array) if p.is_a?(Hash) p = p.dup dst = [:into, :in, :destination, :join_into].find { |k| p.key?(k) } dst.nil? and raise ArgumentError, "you must specify destination attribute using :into => 'attribute_name'" p[:from] = atr_name return join_attribute(p.delete(dst), p) else return join_attribute(p, atr_name) end end # setup attribute set setup_attributes_that :should_be_joined, { atr_name => p }, { :join_separator => [ :with, :separator, :join_separator ], :join_from => [ :from, :source, :sources, :join_from ], :join_compact => [ :compact, :join_compact ] }, :join_from end |