Class: Isomorphic::Node::AbstractNode Abstract
- Inherits:
-
Object
- Object
- Isomorphic::Node::AbstractNode
- Includes:
- Internal::DeepEquals
- Defined in:
- lib/isomorphic/node.rb
Overview
Subclass and override #from_isomorphism and #to_isomorphism to implement a custom class.
Generic base class for Isomorphic nodes.
Direct Known Subclasses
Association, Attribute, Collection, Element, Guard, Member, Namespace, ProcFrom, ProcTo, Root
Instance Attribute Summary collapse
-
#factory ⇒ Isomorphic::Factory::AbstractFactory
readonly
The Isomorphic factory.
-
#inflector ⇒ Isomorphic::Inflector::AbstractInflector
readonly
The Isomorphic inflector.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#from_isomorphism(scope, isomorphism_instance, record = nil, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) ⇒ ActiveRecord::Base
Converts the given instance to an Active Record record.
-
#initialize(parent, *args) {|| ... } ⇒ AbstractNode
constructor
Default constructor.
-
#to_isomorphism(scope, record, isomorphism_instance = nil) ⇒ Object
Converts the given Active Record record to an instance.
-
#to_isomorphism_for(record, *args) ⇒ Object
Returns the cached instance for the given Active Record record.
Methods included from Internal::DeepEquals
Constructor Details
#initialize(parent, *args) {|| ... } ⇒ AbstractNode
Default constructor.
506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/isomorphic/node.rb', line 506 def initialize(parent, *args, &block) super() @__cache_for_to_isomorphism_for = {} @__child_nodes = [] @parent = parent @options = args. unless block.nil? self.instance_exec(*args, &block) end end |
Instance Attribute Details
#factory ⇒ Isomorphic::Factory::AbstractFactory (readonly)
Returns the Isomorphic factory.
525 526 527 528 529 530 531 532 533 |
# File 'lib/isomorphic/node.rb', line 525 %i(factory inflector).each do |method_name| define_method(method_name) do if parent.is_a?(Isomorphic::Node::AbstractNode) parent.send(method_name) else instance_variable_get(:"@#{method_name}") end end end |
#inflector ⇒ Isomorphic::Inflector::AbstractInflector (readonly)
Returns the Isomorphic inflector.
525 526 527 528 529 530 531 532 533 |
# File 'lib/isomorphic/node.rb', line 525 %i(factory inflector).each do |method_name| define_method(method_name) do if parent.is_a?(Isomorphic::Node::AbstractNode) parent.send(method_name) else instance_variable_get(:"@#{method_name}") end end end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
498 499 500 |
# File 'lib/isomorphic/node.rb', line 498 def @options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
494 495 496 |
# File 'lib/isomorphic/node.rb', line 494 def parent @parent end |
Instance Method Details
#from_isomorphism(scope, isomorphism_instance, record = nil, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) ⇒ ActiveRecord::Base
Converts the given instance to an Active Record record.
542 543 544 |
# File 'lib/isomorphic/node.rb', line 542 def from_isomorphism(scope, isomorphism_instance, record = nil, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) raise ::NotImplementedError end |
#to_isomorphism(scope, record, isomorphism_instance = nil) ⇒ Object
Converts the given Active Record record to an instance.
552 553 554 |
# File 'lib/isomorphic/node.rb', line 552 def to_isomorphism(scope, record, isomorphism_instance = nil) raise ::NotImplementedError end |
#to_isomorphism_for(record, *args) ⇒ Object
Returns the cached instance for the given Active Record record.
561 562 563 564 565 |
# File 'lib/isomorphic/node.rb', line 561 def to_isomorphism_for(record, *args) args.inject(@__cache_for_to_isomorphism_for[record]) { |acc, arg| acc.try(:[], arg) } end |