Module: SourcedAttributes::ClassMethods
- Defined in:
- lib/sourced_attributes/sourced_attributes.rb
Instance Method Summary collapse
-
#sources_attributes_from(source_name, **opts, &block) ⇒ Object
Configure a new Source for a model.
-
#update_sourced_attributes(source_name = nil) ⇒ Object
Apply all Sources to the model.
Instance Method Details
#sources_attributes_from(source_name, **opts, &block) ⇒ Object
Configure a new Source for a model.
8 9 10 11 12 13 |
# File 'lib/sourced_attributes/sourced_attributes.rb', line 8 def sources_attributes_from source_name, **opts, &block @sources ||= {} @sources[source_name] ||= Source.create(source_name, opts, self) @sources[source_name].instance_eval(&block) @sources[source_name] end |
#update_sourced_attributes(source_name = nil) ⇒ Object
Apply all Sources to the model. If source_name is specified, only apply changes from that Source.
17 18 19 20 21 22 23 |
# File 'lib/sourced_attributes/sourced_attributes.rb', line 17 def update_sourced_attributes source_name=nil if source_name @sources[source_name].apply else @sources.values.each(&:apply) end end |