Class: Upmin::Graph::ModelNode
- Inherits:
-
Object
- Object
- Upmin::Graph::ModelNode
- Defined in:
- lib/upmin/graph/model_node.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #children ⇒ Object
- #collections ⇒ Object
- #color ⇒ Object
- #depth ⇒ Object
- #editable? ⇒ Boolean
-
#initialize(model, options = {}) ⇒ ModelNode
constructor
A new instance of ModelNode.
- #method_name ⇒ Object
- #model ⇒ Object (also: #object)
- #name ⇒ Object
- #options ⇒ Object
- #path_hash ⇒ Object
- #singletons ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
- #type_prefix ⇒ Object
- #type_suffix ⇒ Object
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, = {}) @model = model @options = end |
Instance Method Details
#attributes ⇒ Object
57 58 59 |
# File 'lib/upmin/graph/model_node.rb', line 57 def attributes return @attributes ||= create_attributes end |
#children ⇒ Object
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 |
#collections ⇒ Object
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 |
#color ⇒ Object
43 44 45 |
# File 'lib/upmin/graph/model_node.rb', line 43 def color return model.upmin_color end |
#depth ⇒ Object
17 18 19 |
# File 'lib/upmin/graph/model_node.rb', line 17 def depth return [:depth] ||= 0 end |
#editable? ⇒ Boolean
21 22 23 24 |
# File 'lib/upmin/graph/model_node.rb', line 21 def editable? return [:editable] if [:editable] return [:editable] = true end |
#method_name ⇒ Object
30 31 32 |
# File 'lib/upmin/graph/model_node.rb', line 30 def method_name return [:method_name] || nil end |
#model ⇒ Object Also known as: object
8 9 10 |
# File 'lib/upmin/graph/model_node.rb', line 8 def model return @model end |
#name ⇒ Object
34 35 36 |
# File 'lib/upmin/graph/model_node.rb', line 34 def name return model.upmin_name(:singular) end |
#options ⇒ Object
13 14 15 |
# File 'lib/upmin/graph/model_node.rb', line 13 def return @options end |
#path_hash ⇒ Object
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 |
#singletons ⇒ Object
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 |
#title ⇒ Object
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 |
#type ⇒ Object
26 27 28 |
# File 'lib/upmin/graph/model_node.rb', line 26 def type return [:type] ||= determine_type end |
#type_prefix ⇒ Object
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_suffix ⇒ Object
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 |