Class: HatTrick::StepDefinition
- Inherits:
-
Object
- Object
- HatTrick::StepDefinition
- Defined in:
- lib/hat_trick/step_definition.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#fieldset ⇒ Object
Returns the value of attribute fieldset.
-
#first ⇒ Object
writeonly
Sets the attribute first.
-
#include_data_key ⇒ Object
readonly
Returns the value of attribute include_data_key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#skipped ⇒ Object
writeonly
Sets the attribute skipped.
-
#wizard ⇒ Object
Returns the value of attribute wizard.
Instance Method Summary collapse
- #add_button(button) ⇒ Object
- #after_callback=(block) ⇒ Object
- #after_callbacks ⇒ Object
- #back_button ⇒ Object
- #before_callback=(block) ⇒ Object
- #before_callbacks ⇒ Object
- #buttons ⇒ Object
- #default_button(type) ⇒ Object
- #delete_button(type) ⇒ Object
- #first? ⇒ Boolean
- #get_button(type) ⇒ Object
- #include_data(context, model) ⇒ Object
- #include_data=(hash) ⇒ Object
-
#initialize(args = {}) ⇒ StepDefinition
constructor
A new instance of StepDefinition.
- #last=(_last) ⇒ Object
- #last? ⇒ Boolean
- #next_button ⇒ Object
- #run_after_callback(context, model) ⇒ Object
- #run_before_callback(context, model) ⇒ Object
- #run_include_data_callback(context, model) ⇒ Object
- #run_step_contents_callback(context, model) ⇒ Object
- #skipped? ⇒ Boolean
- #step_contents(context, model) ⇒ Object
- #step_contents_callback=(block) ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ StepDefinition
Returns a new instance of StepDefinition.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hat_trick/step_definition.rb', line 9 def initialize(args={}) args.each_pair do |k,v| setter = "#{k}=" if respond_to?(setter) send(setter,v) end end @callbacks = {} @buttons = [ { next: (:next) }, { back: (:back) } ] @skipped ||= false @last ||= false @first ||= false end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
3 4 5 |
# File 'lib/hat_trick/step_definition.rb', line 3 def callbacks @callbacks end |
#fieldset ⇒ Object
Returns the value of attribute fieldset.
4 5 6 |
# File 'lib/hat_trick/step_definition.rb', line 4 def fieldset @fieldset end |
#first=(value) ⇒ Object (writeonly)
Sets the attribute first
5 6 7 |
# File 'lib/hat_trick/step_definition.rb', line 5 def first=(value) @first = value end |
#include_data_key ⇒ Object (readonly)
Returns the value of attribute include_data_key.
3 4 5 |
# File 'lib/hat_trick/step_definition.rb', line 3 def include_data_key @include_data_key end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/hat_trick/step_definition.rb', line 4 def name @name end |
#skipped=(value) ⇒ Object (writeonly)
Sets the attribute skipped
5 6 7 |
# File 'lib/hat_trick/step_definition.rb', line 5 def skipped=(value) @skipped = value end |
#wizard ⇒ Object
Returns the value of attribute wizard.
4 5 6 |
# File 'lib/hat_trick/step_definition.rb', line 4 def wizard @wizard end |
Instance Method Details
#add_button(button) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/hat_trick/step_definition.rb', line 55 def () @buttons.delete_if do |b| b.keys.first == .keys.first && b[b.keys.first][:default] end @buttons << end |
#after_callback=(block) ⇒ Object
114 115 116 |
# File 'lib/hat_trick/step_definition.rb', line 114 def after_callback=(block) callbacks[:after] = block end |
#after_callbacks ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/hat_trick/step_definition.rb', line 163 def after_callbacks after_callbacks = [callbacks[:after]] if wizard.after_callback_for_all_steps after_callbacks.unshift wizard.after_callback_for_all_steps end after_callbacks end |
#back_button ⇒ Object
42 43 44 |
# File 'lib/hat_trick/step_definition.rb', line 42 def (:back) end |
#before_callback=(block) ⇒ Object
110 111 112 |
# File 'lib/hat_trick/step_definition.rb', line 110 def before_callback=(block) callbacks[:before] = block end |
#before_callbacks ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/hat_trick/step_definition.rb', line 143 def before_callbacks before_callbacks = [callbacks[:before]] if wizard.before_callback_for_all_steps before_callbacks.unshift wizard.before_callback_for_all_steps end before_callbacks end |
#buttons ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hat_trick/step_definition.rb', line 26 def # We should check for a new translation every time because the user may # have changed their desired localization. @buttons.map do |b| = b.keys.first if b[][:default] b[][:label] = () end b end end |
#default_button(type) ⇒ Object
51 52 53 |
# File 'lib/hat_trick/step_definition.rb', line 51 def (type) { :label => (type), :default => true } end |
#delete_button(type) ⇒ Object
62 63 64 |
# File 'lib/hat_trick/step_definition.rb', line 62 def (type) @buttons.delete_if { |b| b.keys.first == type } end |
#first? ⇒ Boolean
95 96 97 |
# File 'lib/hat_trick/step_definition.rb', line 95 def first? @first end |
#get_button(type) ⇒ Object
46 47 48 49 |
# File 'lib/hat_trick/step_definition.rb', line 46 def (type) = .detect { |b| b.keys.first == type.to_sym } [type.to_sym] unless .nil? end |
#include_data(context, model) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/hat_trick/step_definition.rb', line 136 def include_data(context, model) inc_data = run_include_data_callback(context, model) return {} unless inc_data.respond_to?(:as_json) key = include_data_key.to_s.camelize(:lower) { key => camelize_hash_keys(inc_data) } end |
#include_data=(hash) ⇒ Object
118 119 120 121 |
# File 'lib/hat_trick/step_definition.rb', line 118 def include_data=(hash) callbacks[:include_data] = hash.values.first @include_data_key = hash.keys.first end |
#last=(_last) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/hat_trick/step_definition.rb', line 82 def last=(_last) @last = _last if @last @buttons.delete_if { |b| b.keys.include?(:next) } else @buttons << { :next => } end end |
#last? ⇒ Boolean
91 92 93 |
# File 'lib/hat_trick/step_definition.rb', line 91 def last? @last end |
#next_button ⇒ Object
38 39 40 |
# File 'lib/hat_trick/step_definition.rb', line 38 def (:next) end |
#run_after_callback(context, model) ⇒ Object
171 172 173 |
# File 'lib/hat_trick/step_definition.rb', line 171 def run_after_callback(context, model) run_callbacks(after_callbacks, context, model) end |
#run_before_callback(context, model) ⇒ Object
151 152 153 |
# File 'lib/hat_trick/step_definition.rb', line 151 def run_before_callback(context, model) run_callbacks(before_callbacks, context, model) end |
#run_include_data_callback(context, model) ⇒ Object
155 156 157 |
# File 'lib/hat_trick/step_definition.rb', line 155 def run_include_data_callback(context, model) run_callbacks([callbacks[:include_data]], context, model) end |
#run_step_contents_callback(context, model) ⇒ Object
159 160 161 |
# File 'lib/hat_trick/step_definition.rb', line 159 def run_step_contents_callback(context, model) run_callbacks([callbacks[:step_contents]], context, model) end |
#skipped? ⇒ Boolean
78 79 80 |
# File 'lib/hat_trick/step_definition.rb', line 78 def skipped? @skipped end |
#step_contents(context, model) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/hat_trick/step_definition.rb', line 127 def step_contents(context, model) contents = run_step_contents_callback(context, model) { :hatTrickStepContents => { name.to_s.camelize(:lower).to_sym => contents } } end |
#step_contents_callback=(block) ⇒ Object
123 124 125 |
# File 'lib/hat_trick/step_definition.rb', line 123 def step_contents_callback=(block) callbacks[:step_contents] = block end |
#to_s ⇒ Object
99 100 101 102 103 104 |
# File 'lib/hat_trick/step_definition.rb', line 99 def to_s str = "<HatTrick::Step:0x%08x :#{name}" % (object_id * 2) str += " fieldset: #{fieldset}" if fieldset != name str += ">" str end |
#to_sym ⇒ Object
106 107 108 |
# File 'lib/hat_trick/step_definition.rb', line 106 def to_sym name.to_sym end |