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
- #model_class(klass) ⇒ 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
148 149 150 151 152 153 154 155 |
# File 'lib/hat_trick/dsl.rb', line 148 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
139 140 141 142 143 144 145 146 |
# File 'lib/hat_trick/dsl.rb', line 139 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
102 103 104 |
# File 'lib/hat_trick/dsl.rb', line 102 def (type, label) wizard_def.config.send("#{type}_button_label=", label) end |
#button_label_i18n_key(type, i18n_key) ⇒ Object
106 107 108 |
# File 'lib/hat_trick/dsl.rb', line 106 def (type, i18n_key) wizard_def.config.send("#{type}_button_label_i18n_key=", i18n_key) end |
#button_to(step_name, options = {}) ⇒ Object
128 129 130 131 |
# File 'lib/hat_trick/dsl.rb', line 128 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
93 94 95 96 |
# File 'lib/hat_trick/dsl.rb', line 93 def configure(&block) raise "Must pass a block to configure" unless block_given? self.configure_callback = block end |
#hide_button(button_type) ⇒ Object
133 134 135 136 137 |
# File 'lib/hat_trick/dsl.rb', line 133 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
157 158 159 160 |
# File 'lib/hat_trick/dsl.rb', line 157 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
123 124 125 126 |
# File 'lib/hat_trick/dsl.rb', line 123 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 |
#model_class(klass) ⇒ Object
98 99 100 |
# File 'lib/hat_trick/dsl.rb', line 98 def model_class(klass) klass.send(:include, HatTrick::ModelMethods) end |
#set_contents(&block) ⇒ Object
162 163 164 165 |
# File 'lib/hat_trick/dsl.rb', line 162 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
116 117 118 119 120 121 |
# File 'lib/hat_trick/dsl.rb', line 116 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
110 111 112 113 114 |
# File 'lib/hat_trick/dsl.rb', line 110 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 |
# File 'lib/hat_trick/dsl.rb', line 78 def wizard(&block) if block_given? include HatTrick::DSL::ControllerInstanceMethods include HatTrick::ControllerHooks config = HatTrick::Config.new @wizard_def = HatTrick::WizardDefinition.new(config) yield else raise ArgumentError, "wizard called without a block" end end |