Class: Printfection::Relation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/printfection/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Relation

Returns a new instance of Relation.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/printfection/relation.rb', line 9

def initialize(options={})
  options = {
    parent:   nil,
    children: [],
    klass:    Hashie::Mash,
    path:     "",
    keys:     {},
    actions:  []
  }.merge(options)

  @parent   = options.fetch(:parent)
  @children = options.fetch(:children)
  @klass    = options.fetch(:klass)
  @path     = options.fetch(:path)
  @keys     = options.fetch(:keys)
  @actions  = options.fetch(:actions)

  actions.each do |mod|
    self.extend(mod)
  end

  children.each do |child|
    apply_relation(child)
  end
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



7
8
9
# File 'lib/printfection/relation.rb', line 7

def actions
  @actions
end

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/printfection/relation.rb', line 7

def children
  @children
end

#keysObject (readonly)

Returns the value of attribute keys.



7
8
9
# File 'lib/printfection/relation.rb', line 7

def keys
  @keys
end

#klassObject (readonly)

Returns the value of attribute klass.



7
8
9
# File 'lib/printfection/relation.rb', line 7

def klass
  @klass
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/printfection/relation.rb', line 7

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/printfection/relation.rb', line 7

def path
  @path
end

Instance Method Details

#new(*args) ⇒ Object



39
40
41
42
43
# File 'lib/printfection/relation.rb', line 39

def new(*args)
  child = klass.new(*args)
  apply_relation(child)
  return child
end

#uriObject



35
36
37
# File 'lib/printfection/relation.rb', line 35

def uri
  Util.join_uri(parent.uri, path)
end