Class: HatTrick::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/hat_trick/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_def, wizard) ⇒ Step

Returns a new instance of Step.



17
18
19
20
21
22
# File 'lib/hat_trick/step.rb', line 17

def initialize(step_def, wizard)
  @step_def = step_def
  @buttons = step_def.buttons.dup
  @wizard = wizard
  @skipped = step_def.skipped?
end

Instance Attribute Details

#buttonsObject (readonly)

Returns the value of attribute buttons.



5
6
7
# File 'lib/hat_trick/step.rb', line 5

def buttons
  @buttons
end

#next_stepObject

Returns the value of attribute next_step.



6
7
8
# File 'lib/hat_trick/step.rb', line 6

def next_step
  @next_step
end

#redirect_fromObject

Returns the value of attribute redirect_from.



6
7
8
# File 'lib/hat_trick/step.rb', line 6

def redirect_from
  @redirect_from
end

#skipped=(value) ⇒ Object (writeonly)

Sets the attribute skipped

Parameters:

  • value

    the value to set the attribute skipped to.



7
8
9
# File 'lib/hat_trick/step.rb', line 7

def skipped=(value)
  @skipped = value
end

#step_defObject (readonly)

Returns the value of attribute step_def.



5
6
7
# File 'lib/hat_trick/step.rb', line 5

def step_def
  @step_def
end

#wizardObject (readonly)

Returns the value of attribute wizard.



5
6
7
# File 'lib/hat_trick/step.rb', line 5

def wizard
  @wizard
end

Instance Method Details

#add_button(button) ⇒ Object



24
25
26
27
28
29
# File 'lib/hat_trick/step.rb', line 24

def add_button(button)
  @buttons.delete_if do |b|
    b.keys.first == button.keys.first && b[b.keys.first][:default]
  end
  @buttons << button
end

#as_json(options = nil) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/hat_trick/step.rb', line 51

def as_json(options = nil)
  json = { :name => name, :fieldset => fieldset }
  json[:buttons] = buttons.empty? ? [] : buttons
  json[:first] = first?
  json[:redirect] = redirect?
  json[:redirectFrom] = redirect_from
  json
end

#delete_button(type) ⇒ Object



31
32
33
# File 'lib/hat_trick/step.rb', line 31

def delete_button(type)
  @buttons.delete_if { |b| b.keys.first == type }
end

#mark_as_visitedObject



47
48
49
# File 'lib/hat_trick/step.rb', line 47

def mark_as_visited
  visited_steps << self.to_sym
end

#redirect?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/hat_trick/step.rb', line 39

def redirect?
  redirect_from.present?
end

#skipped?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/hat_trick/step.rb', line 35

def skipped?
  @skipped || (skipped_steps.include?(self.to_sym) && !visited?)
end

#visited?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/hat_trick/step.rb', line 43

def visited?
  visited_steps.include? self.to_sym
end