Class: Mushy::Flow
- Inherits:
-
Object
- Object
- Mushy::Flow
- Defined in:
- lib/mushy/flow.rb
Instance Attribute Summary collapse
-
#fluxs ⇒ Object
Returns the value of attribute fluxs.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #fluxs_for(event) ⇒ Object
-
#initialize ⇒ Flow
constructor
A new instance of Flow.
Constructor Details
#initialize ⇒ Flow
Returns a new instance of Flow.
9 10 11 12 |
# File 'lib/mushy/flow.rb', line 9 def initialize self.id = SecureRandom.uuid self.fluxs = [] end |
Instance Attribute Details
#fluxs ⇒ Object
Returns the value of attribute fluxs.
7 8 9 |
# File 'lib/mushy/flow.rb', line 7 def fluxs @fluxs end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/mushy/flow.rb', line 6 def id @id end |
Class Method Details
.build_flux(record) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/mushy/flow.rb', line 20 def self.build_flux record type = record[:type] || record['type'] || record[:flux] || record['flux'] || 'Flux' flux = Object.const_get("Mushy::#{type}").new flux.id = record[:id] || record['id'] || flux.id flux.type = type flux.config = SymbolizedHash.new(record[:config] || record['config']) flux end |
.parse(data) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mushy/flow.rb', line 29 def self.parse data data = JSON.parse data data_fluxs = data['fluxs'] || [] data_fluxs.select { |x| x['parent'] }.map { |r| r["parents"] = [r["parent"]] } flow = new flow.fluxs = data_fluxs.map { |s| build_flux s } fluxs_with_parent_ids = flow.fluxs.reduce({}) { |t, i| t[i.id] = []; t } data_fluxs.map { |r| fluxs_with_parent_ids[r['id']] = r['parents'] || [] } flow.fluxs.each do |flux| flux.parent_fluxs = flow.fluxs.select { |x| fluxs_with_parent_ids[flux.id].include?(x.id) } end flow end |
Instance Method Details
#fluxs_for(event) ⇒ Object
14 15 16 17 18 |
# File 'lib/mushy/flow.rb', line 14 def fluxs_for event fluxs .select { |x| x.parent_fluxs.any? { |y| y.id == event.flux_id } } .flatten end |