Class: NoSE::Model
Overview
A conceptual data model of a set of entities
Constant Summary collapse
- LOAD_PATH =
The subdirectory models are loaded from
'models'
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
Attributes included from Loader
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare all entities.
-
#[](name) ⇒ Entity
Retrieve an entity by name.
-
#add_entity(entity) ⇒ Entity
Add an Entity to the workload.
-
#find_field(field) ⇒ Field
Find a field given an
Enumerable
of identifiers. -
#initialize(&block) ⇒ Model
constructor
A new instance of Model.
-
#output(format, filename, include_fields = false) ⇒ Object
Output a PNG representation of entities in the model.
Methods included from Loader
Constructor Details
#initialize(&block) ⇒ Model
Returns a new instance of Model.
17 18 19 20 21 22 |
# File 'lib/nose/model.rb', line 17 def initialize(&block) @entities = {} # Apply the DSL WorkloadDSL.new(self).instance_eval(&block) if block_given? end |
Instance Attribute Details
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
15 16 17 |
# File 'lib/nose/model.rb', line 15 def entities @entities end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare all entities
26 27 28 |
# File 'lib/nose/model.rb', line 26 def ==(other) other.is_a?(Model) && @entities = other.entities end |
#[](name) ⇒ Entity
Retrieve an entity by name
33 34 35 36 |
# File 'lib/nose/model.rb', line 33 def [](name) return @entities[name] if @entities.key? name fail EntityNotFound end |
#add_entity(entity) ⇒ Entity
Add an Entity to the workload
40 41 42 43 |
# File 'lib/nose/model.rb', line 40 def add_entity(entity) fail InvalidEntity, 'no primary key defined' if entity.id_field.nil? @entities[entity.name] = entity end |
#find_field(field) ⇒ Field
Find a field given an Enumerable
of identifiers
47 48 49 50 51 52 53 |
# File 'lib/nose/model.rb', line 47 def find_field(field) if field.count > 2 find_field_chain field else find_entity_field(*field) end end |
#output(format, filename, include_fields = false) ⇒ Object
Output a PNG representation of entities in the model
56 57 58 59 60 61 62 |
# File 'lib/nose/model.rb', line 56 def output(format, filename, include_fields = false) graph = GraphViz.new :G, type: :digraph nodes = add_graph_nodes graph, include_fields add_graph_edges graph, nodes graph.output(**{ format => filename }) end |