class Safrano::RelationManager
some usefull stuff
Public Class Methods
build_id(arg)
click to toggle source
# File lib/odata/relations.rb, line 68 def self.build_id(arg) arg.sort.map(&:to_s).join('_') end
new()
click to toggle source
# File lib/odata/relations.rb, line 64 def initialize @list = {} end
Public Instance Methods
each_rel() { |rel| ... }
click to toggle source
# File lib/odata/relations.rb, line 72 def each_rel raise ArgumentError unless block_given? @list.each { |_rid, rel| yield rel } end
get(arg)
click to toggle source
# File lib/odata/relations.rb, line 78 def get(arg) rid = Safrano::RelationManager.build_id(arg) if @list.key?(rid) @list[rid] else rel = Safrano::Relation.new(arg) @list[rid] = rel end end
get_metadata_xml_attribs(from, to, assoc_type, xnamespace, attrname)
click to toggle source
# File lib/odata/relations.rb, line 88 def get_metadata_xml_attribs(from, to, assoc_type, xnamespace, attrname) rel = get([from, to]) # use Sequel reflection to get multiplicity (will be used later # in 2. Associations below) case assoc_type # TODO: use multiplicity 1 when needed instead of '0..1' when :one_to_one rel.set_multiplicity(from, '0..1') rel.set_multiplicity(to, '0..1') when :one_to_many rel.set_multiplicity(from, '0..1') rel.set_multiplicity(to, '*') when :many_to_one rel.set_multiplicity(from, '*') rel.set_multiplicity(to, '0..1') when :many_to_many rel.set_multiplicity(from, '*') rel.set_multiplicity(to, '*') end # <NavigationProperty Name="Supplier" # Relationship="ODataDemo.Product_Supplier_Supplier_Products" # FromRole="Product_Supplier" ToRole="Supplier_Products"/> { 'Name' => attrname, 'Relationship' => "#{xnamespace}.#{rel.name}", 'FromRole' => from, 'ToRole' => to } end