Class: BPMN::Definitions

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/bpmn/definitions.rb

Constant Summary collapse

MODEL_ATTRIBUTES =
%i[
  id name target_namespace exporter exporter_version execution_platform execution_platform_version
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Definitions

Returns a new instance of Definitions.



28
29
30
31
32
33
34
35
36
37
# File 'lib/bpmn/definitions.rb', line 28

def initialize(attributes={})
  super(attributes.slice(*MODEL_ATTRIBUTES))

  @messages = Array.wrap(attributes[:message]).map { |atts| Message.new(atts) }
  @signals = Array.wrap(attributes[:signal]).map { |atts| Signal.new(atts) }
  @errors = Array.wrap(attributes[:error]).map { |atts| Error.new(atts) }
  @escalations = Array.wrap(attributes[:escalation]).map { |atts| Escalation.new(atts) }
  @item_definitions = Array.wrap(attributes[:item_definition]).map { |atts| ItemDefinition.new(atts) }
  @processes = Array.wrap(attributes[:process]).map { |atts| Process.new(atts) }
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



12
13
14
# File 'lib/bpmn/definitions.rb', line 12

def errors
  @errors
end

#escalationsObject (readonly)

Returns the value of attribute escalations.



12
13
14
# File 'lib/bpmn/definitions.rb', line 12

def escalations
  @escalations
end

#execution_platformObject

Returns the value of attribute execution_platform.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def execution_platform
  @execution_platform
end

#execution_platform_versionObject

Returns the value of attribute execution_platform_version.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def execution_platform_version
  @execution_platform_version
end

#exporterObject

Returns the value of attribute exporter.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def exporter
  @exporter
end

#exporter_versionObject

Returns the value of attribute exporter_version.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def exporter_version
  @exporter_version
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def id
  @id
end

#item_definitionsObject (readonly)

Returns the value of attribute item_definitions.



12
13
14
# File 'lib/bpmn/definitions.rb', line 12

def item_definitions
  @item_definitions
end

#messagesObject (readonly)

Returns the value of attribute messages.



12
13
14
# File 'lib/bpmn/definitions.rb', line 12

def messages
  @messages
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def name
  @name
end

#processesObject (readonly)

Returns the value of attribute processes.



12
13
14
# File 'lib/bpmn/definitions.rb', line 12

def processes
  @processes
end

#signalsObject (readonly)

Returns the value of attribute signals.



12
13
14
# File 'lib/bpmn/definitions.rb', line 12

def signals
  @signals
end

#target_namespaceObject

Returns the value of attribute target_namespace.



11
12
13
# File 'lib/bpmn/definitions.rb', line 11

def target_namespace
  @target_namespace
end

Class Method Details

.from_xml(xml) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bpmn/definitions.rb', line 14

def self.from_xml(xml)
  XmlHasher.configure do |config|
    config.snakecase = true
    config.ignore_namespaces = true
    config.string_keys = false
  end
  hash = XmlHasher.parse(xml)
  Definitions.new(hash[:definitions].except(:bpmn_diagram)).tap do |definitions|
    definitions.processes.each do |process|
      process.wire_references(definitions)
    end
  end
end

Instance Method Details

#error_by_id(id) ⇒ Object



47
48
49
# File 'lib/bpmn/definitions.rb', line 47

def error_by_id(id)
  errors.find { |error| error.id == id }
end

#escalation_by_id(id) ⇒ Object



51
52
53
# File 'lib/bpmn/definitions.rb', line 51

def escalation_by_id(id)
  escalations.find { |escalation| escalation.id == id }
end

#inspectObject



63
64
65
# File 'lib/bpmn/definitions.rb', line 63

def inspect
  "#<BPMN::Definitions @id=#{id.inspect} @name=#{name.inspect} @messages=#{messages.inspect} @signals=#{signals.inspect} @errors=#{errors.inspect} @escalations=#{escalations.inspect} @item_definitions=#{item_definitions.inspect} @processes=#{processes.inspect}>"
end

#item_definition_by_id(id) ⇒ Object



59
60
61
# File 'lib/bpmn/definitions.rb', line 59

def item_definition_by_id(id)
  item_definitions.find { |item| item.id == id }
end

#message_by_id(id) ⇒ Object



39
40
41
# File 'lib/bpmn/definitions.rb', line 39

def message_by_id(id)
  messages.find { |message| message.id == id }
end

#process_by_id(id) ⇒ Object



55
56
57
# File 'lib/bpmn/definitions.rb', line 55

def process_by_id(id)
  processes.find { |process| process.id == id }
end

#signal_by_id(id) ⇒ Object



43
44
45
# File 'lib/bpmn/definitions.rb', line 43

def signal_by_id(id)
  signals.find { |signal| signal.id == id }
end