Module: Isomorphic::Node::Internal::InstanceMethodsForCollection
- Extended by:
- ActiveSupport::Concern
- Included in:
- Collection, GuardCollection, RootCollection
- Defined in:
- lib/isomorphic/node.rb
Overview
Included when the base class is a collection.
Instance Method Summary collapse
-
#association(**options) {|node| ... } ⇒ self
Build an Isomorphic node for an Active Record association.
-
#association_for(lens_or_association, **options) {|node| ... } ⇒ self
Build an Isomorphic node for an Active Record association (as an attribute) using an Isomorphic lens.
-
#element(isomorphism_class, **options) {|node| ... } ⇒ self
Build an Isomorphic node for zero or more members of a collection.
-
#guard_association_for(lens_or_attribute_name, *values, **options) {|node| ... } ⇒ self
Build an Isomorphic node for a “guard” statement for an Active Record association using an Isomorphic lens.
-
#namespace_association_for(namespace, terms, **options) {|node| ... } ⇒ self
Build an Isomorphic node for a value of a “namespace” statement that is within scope.
Instance Method Details
#association(**options) {|node| ... } ⇒ self
Build an Isomorphic node for an Active Record association.
137 138 139 140 141 |
# File 'lib/isomorphic/node.rb', line 137 def association(**, &block) node = Isomorphic::Node::Association.new(self, **, &block) @__child_nodes << node node end |
#association_for(lens_or_association, **options) {|node| ... } ⇒ self
Build an Isomorphic node for an Active Record association (as an attribute) using an Isomorphic lens.
152 153 154 155 156 157 158 159 |
# File 'lib/isomorphic/node.rb', line 152 def association_for(lens_or_association, **, &block) lens = lens_or_association.is_a?(Isomorphic::Lens::AbstractLens) ? lens_or_association : reflect_on_attribute(lens_or_association) association(**.merge({ get: ::Proc.new { |record| lens.get(record) }, set: ::Proc.new { |record, value, xmlattr_acc| lens.set(record, value, xmlattr_acc) }, }), &block) end |
#element(isomorphism_class, **options) {|node| ... } ⇒ self
Build an Isomorphic node for zero or more members of a collection.
170 171 172 173 174 |
# File 'lib/isomorphic/node.rb', line 170 def element(isomorphism_class, **, &block) node = Isomorphic::Node::Element.new(self, isomorphism_class, **, &block) @__child_nodes << node node end |
#guard_association_for(lens_or_attribute_name, *values, **options) {|node| ... } ⇒ self
Build an Isomorphic node for a “guard” statement for an Active Record association using an Isomorphic lens.
187 188 189 190 191 192 193 |
# File 'lib/isomorphic/node.rb', line 187 def guard_association_for(lens_or_attribute_name, *values, **, &block) lens = lens_or_attribute_name.is_a?(Isomorphic::Lens::AbstractLens) ? lens_or_attribute_name : reflect_on_attribute(lens_or_attribute_name) node = Isomorphic::Node::GuardCollection.new(self, lens, *values, **, &block) @__child_nodes << node node end |
#namespace_association_for(namespace, terms, **options) {|node| ... } ⇒ self
Build an Isomorphic node for a value of a “namespace” statement that is within scope.
206 207 208 209 210 211 212 |
# File 'lib/isomorphic/node.rb', line 206 def namespace_association_for(namespace, terms, **, &block) key = inflector.isomorphism(terms) node = Isomorphic::Node::NamespaceAssociation.new(self, namespace, key, **, &block) @__child_nodes << node node end |