class Mushy::Flow
Attributes
fluxs[RW]
id[RW]
Public Class Methods
build_flux(record)
click to toggle source
# File lib/mushy/flow.rb, line 26 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.flow = Mushy::Flow.new flux end
new()
click to toggle source
# File lib/mushy/flow.rb, line 9 def initialize self.id = SecureRandom.uuid self.fluxs = [] end
parse(data)
click to toggle source
# File lib/mushy/flow.rb, line 42 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| flow.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
Public Instance Methods
adjust_data(data)
click to toggle source
# File lib/mushy/flow.rb, line 20 def adjust_data data fluxs .select { |x| x.respond_to? :adjust_data } .reduce(data) { |t, i| i.adjust_data t } end
build_flux(record)
click to toggle source
# File lib/mushy/flow.rb, line 36 def build_flux record Mushy::Flow.build_flux(record).tap do |flux| flux.flow = self end end
fluxs_for(event)
click to toggle source
# 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