Module: HatTrick::DSL::ClassMethods
- Defined in:
- lib/hat_trick/dsl.rb
Instance Attribute Summary collapse
-
#wizard_def ⇒ Object
readonly
Returns the value of attribute wizard_def.
Instance Method Summary collapse
- #after(scope = :current_step, &block) ⇒ Object
- #before(scope = :current_step, &block) ⇒ Object
- #button_label(type, label) ⇒ Object
- #button_label_i18n_key(type, i18n_key) ⇒ Object
- #button_to(step_name, options = {}) ⇒ Object
- #configure(&block) ⇒ Object
- #hide_button(button_type) ⇒ Object
- #include_data(key, &block) ⇒ Object
- #last_step ⇒ Object
- #set_contents(&block) ⇒ Object
- #skip_this_step ⇒ Object
- #step(name, args = {}, &block) ⇒ Object
- #wizard(&block) ⇒ Object
Instance Attribute Details
#wizard_def ⇒ Object (readonly)
Returns the value of attribute wizard_def.
76 77 78 |
# File 'lib/hat_trick/dsl.rb', line 76 def wizard_def @wizard_def end |
Instance Method Details
#after(scope = :current_step, &block) ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/hat_trick/dsl.rb', line 146 def after(scope=:current_step, &block) raise "after must be called from within a wizard block" unless wizard_def if scope == :each wizard_def.after_callback_for_all_steps = block else wizard_def.last_step.after_callback = block end end |
#before(scope = :current_step, &block) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/hat_trick/dsl.rb', line 137 def before(scope=:current_step, &block) raise "before must be called from within a wizard block" unless wizard_def if scope == :each wizard_def.before_callback_for_all_steps = block else wizard_def.last_step.before_callback = block end end |
#button_label(type, label) ⇒ Object
100 101 102 |
# File 'lib/hat_trick/dsl.rb', line 100 def (type, label) wizard_def.config.send("#{type}_button_label=", label) end |
#button_label_i18n_key(type, i18n_key) ⇒ Object
104 105 106 |
# File 'lib/hat_trick/dsl.rb', line 104 def (type, i18n_key) wizard_def.config.send("#{type}_button_label_i18n_key=", i18n_key) end |
#button_to(step_name, options = {}) ⇒ Object
126 127 128 129 |
# File 'lib/hat_trick/dsl.rb', line 126 def (step_name, ={}) raise "button_to must be called from within a wizard block" unless wizard_def wizard_def.last_step. (step_name, ) end |
#configure(&block) ⇒ Object
95 96 97 98 |
# File 'lib/hat_trick/dsl.rb', line 95 def configure(&block) raise "Must pass a block to configure" unless block_given? self.configure_callback = block end |
#hide_button(button_type) ⇒ Object
131 132 133 134 135 |
# File 'lib/hat_trick/dsl.rb', line 131 def () raise "before must be called from within a wizard block" unless wizard_def step = wizard_def.last_step step. end |
#include_data(key, &block) ⇒ Object
155 156 157 158 |
# File 'lib/hat_trick/dsl.rb', line 155 def include_data(key, &block) raise "include_data must be called from within a wizard block" unless wizard_def wizard_def.last_step.include_data = { key.to_sym => block } end |
#last_step ⇒ Object
121 122 123 124 |
# File 'lib/hat_trick/dsl.rb', line 121 def last_step raise "skip_this_step must be called from within a wizard block" unless wizard_def wizard_def.last_step.last = true end |
#set_contents(&block) ⇒ Object
160 161 162 163 |
# File 'lib/hat_trick/dsl.rb', line 160 def set_contents(&block) raise "set_contents must be called from within a wizard block" unless wizard_def wizard_def.last_step.step_contents_callback = block end |
#skip_this_step ⇒ Object
114 115 116 117 118 119 |
# File 'lib/hat_trick/dsl.rb', line 114 def skip_this_step # skip_this_step in wizard definition (class) context means the step # can be explicitly jumped to, but won't be visited in the normal flow raise "skip_this_step must be called from within a wizard block" unless wizard_def wizard_def.last_step.skipped = true end |
#step(name, args = {}, &block) ⇒ Object
108 109 110 111 112 |
# File 'lib/hat_trick/dsl.rb', line 108 def step(name, args={}, &block) raise "step must be called from within a wizard block" unless wizard_def wizard_def.add_step(name, args) instance_eval &block if block_given? end |
#wizard(&block) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/hat_trick/dsl.rb', line 78 def wizard(&block) if block_given? include HatTrick::DSL::ControllerInstanceMethods include HatTrick::ControllerHooks ::ActiveRecord::Base.send(:include, HatTrick::ModelMethods) config = HatTrick::Config.new @wizard_def = HatTrick::WizardDefinition.new(config) yield else raise ArgumentError, "wizard called without a block" end end |