Class: RailsOnboarding::Flow

Inherits:
ApplicationRecord show all
Defined in:
app/models/rails_onboarding/flow.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activate!(flow) ⇒ Object



34
35
36
37
38
39
# File 'app/models/rails_onboarding/flow.rb', line 34

def self.activate!(flow)
  transaction do
    where.not(id: flow.id).update_all(active: false)
    flow.update!(active: true)
  end
end

.seed_default!Object



25
26
27
28
29
30
31
32
# File 'app/models/rails_onboarding/flow.rb', line 25

def self.seed_default!
  create!(
    name: "Current Configuration",
    description: "Flow from current configuration",
    steps: RailsOnboarding.configuration.steps,
    active: true
  )
end

Instance Method Details

#[](key) ⇒ Object

Hash-style reader so views written against the old session-hash flows (flow, flow, ...) keep working against this AR-backed model.



13
14
15
# File 'app/models/rails_onboarding/flow.rb', line 13

def [](key)
  public_send(key)
end

#stepsObject

JSON round-trips a saved flow's steps back with string keys, but every view reads them with symbols (step, step, ...). Normalize on read so it doesn't matter whether a step hash was just assigned in memory or came back from the database.



21
22
23
# File 'app/models/rails_onboarding/flow.rb', line 21

def steps
  Array(super).map { |step| step.is_a?(Hash) ? step.with_indifferent_access : step }
end