Class: Upmin::Graph::ModelNode

Inherits:
Object
  • Object
show all
Defined in:
lib/upmin/graph/model_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ ModelNode

Returns a new instance of ModelNode.



3
4
5
6
# File 'lib/upmin/graph/model_node.rb', line 3

def initialize(model, options = {})
  @model = model
  @options = options
end

Instance Method Details

#attributesObject



57
58
59
# File 'lib/upmin/graph/model_node.rb', line 57

def attributes
  return @attributes ||= create_attributes
end

#childrenObject



61
62
63
64
65
66
67
# File 'lib/upmin/graph/model_node.rb', line 61

def children
  if depth >= 1
    return [] # nothing beyond a depth of 2
  else
    return @children ||= create_children
  end
end

#collectionsObject



75
76
77
78
79
# File 'lib/upmin/graph/model_node.rb', line 75

def collections
  return @collections if @collections
  create_children # backfill this if not defined
  return @collections
end

#colorObject



43
44
45
# File 'lib/upmin/graph/model_node.rb', line 43

def color
  return model.upmin_color
end

#depthObject



17
18
19
# File 'lib/upmin/graph/model_node.rb', line 17

def depth
  return options[:depth] ||= 0
end

#editable?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/upmin/graph/model_node.rb', line 21

def editable?
  return options[:editable] if options[:editable]
  return options[:editable] = true
end

#method_nameObject



30
31
32
# File 'lib/upmin/graph/model_node.rb', line 30

def method_name
  return options[:method_name] || nil
end

#modelObject Also known as: object



8
9
10
# File 'lib/upmin/graph/model_node.rb', line 8

def model
  return @model
end

#nameObject



34
35
36
# File 'lib/upmin/graph/model_node.rb', line 34

def name
  return model.upmin_name(:singular)
end

#optionsObject



13
14
15
# File 'lib/upmin/graph/model_node.rb', line 13

def options
  return @options
end

#path_hashObject



47
48
49
50
51
52
# File 'lib/upmin/graph/model_node.rb', line 47

def path_hash
  return {
    model_name: model.class.to_s,
    id: model.id
  }
end

#singletonsObject



69
70
71
72
73
# File 'lib/upmin/graph/model_node.rb', line 69

def singletons
  return @singletons if @singletons
  create_children # backfill this if not defined
  return @singletons
end

#titleObject



38
39
40
41
# File 'lib/upmin/graph/model_node.rb', line 38

def title
  # TODO(jon): Add block option for custom defined titles
  return "#{name} # #{model.id}"
end

#typeObject



26
27
28
# File 'lib/upmin/graph/model_node.rb', line 26

def type
  return options[:type] ||= determine_type
end

#type_prefixObject



81
82
83
84
# File 'lib/upmin/graph/model_node.rb', line 81

def type_prefix
  name = model.class.to_s.underscore
  return name
end

#type_suffixObject



86
87
88
89
90
91
92
93
94
# File 'lib/upmin/graph/model_node.rb', line 86

def type_suffix
  if depth == 0
    return "_model"
  elsif depth >= 1
    return "_model_nested"
  # else
  #   return "_model_badge"
  end
end