class Printfection::Relation
Attributes
actions[R]
children[R]
keys[R]
klass[R]
parent[R]
path[R]
Public Class Methods
new(options={})
click to toggle source
# 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
Public Instance Methods
new(*args)
click to toggle source
# File lib/printfection/relation.rb, line 39 def new(*args) child = klass.new(*args) apply_relation(child) return child end
uri()
click to toggle source
# File lib/printfection/relation.rb, line 35 def uri Util.join_uri(parent.uri, path) end
Private Instance Methods
apply_relation(child)
click to toggle source
# File lib/printfection/relation.rb, line 47 def apply_relation(child) keys.each do |primary, foreign| child[foreign] = parent[primary] end if child.respond_to? :relation= child.relation = self end end