Module: RVC::InventoryObject

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ObjectWithFields::ClassMethods

field, fields

Methods included from ObjectWithFields

#field, #field_properties, #perfmetrics

Instance Attribute Details

#rvc_arcObject (readonly)

Returns the value of attribute rvc_arc.



57
58
59
# File 'lib/rvc/inventory.rb', line 57

def rvc_arc
  @rvc_arc
end

#rvc_parentObject (readonly)

Returns the value of attribute rvc_parent.



57
58
59
# File 'lib/rvc/inventory.rb', line 57

def rvc_parent
  @rvc_parent
end

Class Method Details

.included(m) ⇒ Object



49
50
51
# File 'lib/rvc/inventory.rb', line 49

def self.included m
  m.extend ClassMethods
end

Instance Method Details

#childrenObject



71
72
73
# File 'lib/rvc/inventory.rb', line 71

def children
  {}
end

#display_infoObject



59
60
61
# File 'lib/rvc/inventory.rb', line 59

def display_info
  puts "class: #{self.class.name}"
end

#ls_text(r) ⇒ Object



63
64
65
# File 'lib/rvc/inventory.rb', line 63

def ls_text r
  self.class.folder? ? '/' : ''
end

#rvc_childrenObject



75
76
77
78
79
80
81
# File 'lib/rvc/inventory.rb', line 75

def rvc_children
  out = self.children
  methods.grep(/rvc_list_children_/).each do |method|
    out.merge!(self.send(method))
  end
  out
end


114
115
116
117
118
# File 'lib/rvc/inventory.rb', line 114

def rvc_link parent, arc
  return if @rvc_parent
  @rvc_parent = parent
  @rvc_arc = arc
end

#rvc_pathObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/rvc/inventory.rb', line 83

def rvc_path
  [].tap do |a|
    cur = self
    while cur != nil
      a << [cur.rvc_arc, cur]
      cur = cur.rvc_parent
    end
    a.reverse!
  end
end

#rvc_path_strObject



94
95
96
# File 'lib/rvc/inventory.rb', line 94

def rvc_path_str
  rvc_path.map { |k,v| k } * '/'
end

#rvc_relative_path(ref) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rvc/inventory.rb', line 98

def rvc_relative_path ref
  my_path = rvc_path
  ref_path = ref.rvc_path
  ref_objs = Set.new(ref_path.map { |x| x[1] })
  common = my_path.take_while { |x| ref_objs.member? x[1] }
  fail unless common
  path_to_ref = my_path.reverse.take_while { |x| x[1] != common.last[1] }.reverse
  num_ups = ref_path.size - common.size
  ups = (['..']*num_ups).zip(ref_path.reverse[1..-1].map(&:first))
  ups + path_to_ref
end

#rvc_relative_path_str(ref) ⇒ Object



110
111
112
# File 'lib/rvc/inventory.rb', line 110

def rvc_relative_path_str ref
  rvc_relative_path(ref).map { |k,v| k } * '/'
end

#traverse_one(arc) ⇒ Object



67
68
69
# File 'lib/rvc/inventory.rb', line 67

def traverse_one arc
  rvc_children[arc]
end