Class: FAP::Paw

Inherits:
Object
  • Object
show all
Defined in:
lib/fap/paw.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, opts = {}) ⇒ Paw

Returns a new instance of Paw.



18
19
20
21
22
# File 'lib/fap/paw.rb', line 18

def initialize stream, opts={}
  data = stream.respond_to?(:read) ? stream.read : stream.to_s
  @_node = Nokogiri data
  @_cache = {}
end

Class Method Details

.inherited(subclass) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fap/paw.rb', line 6

def self.inherited subclass
  subclass.send :include, FAP::Mixins::Properties
  subclass.send :include, FAP::Mixins::Relations
  subclass.class_eval <<-EOS, __FILE__, __LINE__ + 1
    def self.inherited subclass
      super
      subclass.properties = self.properties.dup
      subclass.relations  = self.relations.dup
    end
  EOS
end

Instance Method Details

#from_relation(relation, node) ⇒ Object

Build object starting from a relation’s node

Parameters:

  • Object (FAP::Relation)

    relation

  • starting (Nokogiri::XML::Element)

    node

See Also:



31
32
33
34
35
36
37
38
# File 'lib/fap/paw.rb', line 31

def from_relation relation, node
  relation.from.class
  owners = self.relations.select { |rel| rel.type == :belongs_to && rel.klass == relation.from.class.to_s }
  @_cache ||= {}
  @_cache[owners.first.name] = relation.from if owners.size == 1
  @_node = node
  self
end