Module: Isomorphic::Node::Internal::InstanceMethodsForMember

Extended by:
ActiveSupport::Concern
Included in:
Association, Attribute, Element, GuardMember, Member, Namespace, RootMember
Defined in:
lib/isomorphic/node.rb

Overview

Included when the base class is a member.

Instance Method Summary collapse

Instance Method Details

#attribute(method_name, isomorphism_xmlattr_class = nil, **options) {|node| ... } ⇒ self

Build an Isomorphic node for an attribute.

Parameters:

  • method_name (#to_s)

    the method name for the target

  • isomorphism_xmlattr_class (Class) (defaults to: nil)

    the class for the target

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


235
236
237
238
239
# File 'lib/isomorphic/node.rb', line 235

def attribute(method_name, isomorphism_xmlattr_class = nil, **options, &block)
  node = Isomorphic::Node::Attribute.new(self, method_name, isomorphism_xmlattr_class, **options, &block)
  @__child_nodes << node
  node
end

#attribute_for(lens_or_attribute_name, method_name, isomorphism_xmlattr_class = nil, **options) {|node| ... } ⇒ self

Build an Isomorphic node for an attribute using the given lens.

Parameters:

  • lens_or_attribute_name (Isomorphic::Lens::AbstractLens, #to_s)

    the Isomorphic lens or the name of the attribute

  • method_name (#to_s)

    the method name for the target

  • isomorphism_xmlattr_class (Class) (defaults to: nil)

    the class for the target

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


252
253
254
255
256
257
258
259
# File 'lib/isomorphic/node.rb', line 252

def attribute_for(lens_or_attribute_name, method_name, isomorphism_xmlattr_class = nil, **options, &block)
  lens = lens_or_attribute_name.is_a?(Isomorphic::Lens::AbstractLens) ? lens_or_attribute_name : reflect_on_attribute(lens_or_attribute_name)

  attribute(method_name, isomorphism_xmlattr_class, **options.merge({
    get: ::Proc.new { |record| lens.get(record) },
    set: ::Proc.new { |record, value, xmlattr_acc| lens.set(record, value, xmlattr_acc) },
  }), &block)
end

#collection(method_name, isomorphism_class, **options) {|node| ... } ⇒ self

Build an Isomorphic node for a collection.

Parameters:

  • method_name (#to_s)

    the method name for the target

  • isomorphism_class (Class)

    the class for the target

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


271
272
273
274
275
# File 'lib/isomorphic/node.rb', line 271

def collection(method_name, isomorphism_class, **options, &block)
  node = Isomorphic::Node::Collection.new(self, method_name, isomorphism_class, **options, &block)
  @__child_nodes << node
  node
end

#from(**options) {|instance, record, xmlattr_acc, scope| ... } ⇒ self

Build an Isomorphic node for a Proc that is called in the reverse direction only.

Parameters:

  • options (Hash<Symbol, Object>)

    the options

Yield Parameters:

  • instance (Object)

    the instance

  • record (ActiveRecord::Base)

    the record

  • xmlattr_acc (ActiveSupport::HashWithIndifferentAccess)

    the accumulator for XML attributes

  • scope (Isomorphic::Node::Internal::Scope)

    the scope

Yield Returns:

  • (ActiveRecord::Record)

    the record

Returns:

  • (self)


286
287
288
289
290
# File 'lib/isomorphic/node.rb', line 286

def from(**options, &block)
  node = Isomorphic::Node::ProcFrom.new(self, **options, &block)
  @__child_nodes << node
  node
end

#guard_attribute_for(lens_or_attribute_name, *values, **options) {|node| ... } ⇒ self

Build an Isomorphic node for a “guard” statement for an attribute using an Isomorphic lens.

Parameters:

  • lens_or_attribute_name (Isomorphic::Lens::AbstractLens, #to_s)

    the Isomorphic lens or the name of the attribute

  • values (Array<Object>)

    the included values

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

  • :default (Object) — default: nil

    the default value, where more than one included value is given

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


303
304
305
306
307
308
309
# File 'lib/isomorphic/node.rb', line 303

def guard_attribute_for(lens_or_attribute_name, *values, **options, &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::GuardMember.new(self, lens, *values, **options, &block)
  @__child_nodes << node
  node
end

#member(method_name, isomorphism_class, **options) {|node| ... } ⇒ self

Build an Isomorphic node for a member.

Parameters:

  • method_name (#to_s)

    the method name for the target

  • isomorphism_class (Class)

    the class for the target

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


321
322
323
324
325
# File 'lib/isomorphic/node.rb', line 321

def member(method_name, isomorphism_class, **options, &block)
  node = Isomorphic::Node::Member.new(self, method_name, isomorphism_class, **options, &block)
  @__child_nodes << node
  node
end

#namespace(namespace, lens_or_attribute_name, **options) {|node| ... } ⇒ self

Build an Isomorphic node for a “namespace” statement using an Isomorphic lens.

Parameters:

  • namespace (#to_s)

    the namespace name

  • lens_or_attribute_name (Isomorphic::Lens::AbstractLens, #to_s)

    the Isomorphic lens or the name of the attribute

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


337
338
339
340
341
342
343
# File 'lib/isomorphic/node.rb', line 337

def namespace(namespace, lens_or_attribute_name, **options, &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::Namespace.new(self, namespace, lens, **options, &block)
  @__child_nodes << node
  node
end

#namespace_attribute_for(namespace, terms, method_name, isomorphism_xmlattr_class = nil, **options) {|node| ... } ⇒ self

Build an Isomorphic node for a value of a “namespace” statement that is within scope.

Parameters:

  • namespace (#to_s)

    the namespace name

  • terms (Array<Object>)

    the inflectable terms

  • method_name (#to_s)

    the method name for the target

  • isomorphism_xmlattr_class (Class) (defaults to: nil)

    the class for the target

  • options (Hash<Symbol, Object>)

    the options

Options Hash (**options):

  • :allow_blank (Boolean) — default: false

    true if the new node should always return a non-nil target

  • :attributes (Hash<Symbol, Object>) — default: {}

    default attributes for the target

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)

Raises:



358
359
360
361
362
363
364
# File 'lib/isomorphic/node.rb', line 358

def namespace_attribute_for(namespace, terms, method_name, isomorphism_xmlattr_class = nil, **options, &block)
  key = inflector.isomorphism(terms)

  node = Isomorphic::Node::NamespaceAttribute.new(self, namespace, key, method_name, isomorphism_xmlattr_class, **options, &block)
  @__child_nodes << node
  node
end

#to(**options) {|record, instance, scope| ... } ⇒ self

Build an Isomorphic node for a Proc that is called in the forward direction only.

Parameters:

  • options (Hash<Symbol, Object>)

    the options

Yield Parameters:

Yield Returns:

  • (Object)

    the instance

Returns:

  • (self)


374
375
376
377
378
# File 'lib/isomorphic/node.rb', line 374

def to(**options, &block)
  node = Isomorphic::Node::ProcTo.new(self, **options, &block)
  @__child_nodes << node
  node
end