Class: Larynx::Form
- Inherits:
-
Application
- Object
- Application
- Larynx::Form
- Defined in:
- lib/larynx/form.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
Attributes inherited from Application
Class Method Summary collapse
Instance Method Summary collapse
- #attempt ⇒ Object
- #current_field ⇒ Object
- #field_index(name) ⇒ Object
-
#initialize(*args, &block) ⇒ Form
constructor
A new instance of Form.
- #last_attempt? ⇒ Boolean
- #next_field(field_name = nil) ⇒ Object
- #restart_form ⇒ Object
- #run ⇒ Object
Methods inherited from Application
Constructor Details
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
8 9 10 |
# File 'lib/larynx/form.rb', line 8 def fields @fields end |
Class Method Details
.field(name, options = {}, &block) ⇒ Object
15 16 17 18 |
# File 'lib/larynx/form.rb', line 15 def field(name, ={}, &block) self.field_definitions << {:name => name, :options => , :block => block} attr_accessor name end |
.setup(&block) ⇒ Object
11 12 13 |
# File 'lib/larynx/form.rb', line 11 def setup(&block) self.setup_block = block end |
Instance Method Details
#attempt ⇒ Object
58 59 60 |
# File 'lib/larynx/form.rb', line 58 def attempt current_field.attempt end |
#current_field ⇒ Object
49 50 51 |
# File 'lib/larynx/form.rb', line 49 def current_field @fields[@field_index] end |
#field_index(name) ⇒ Object
53 54 55 56 |
# File 'lib/larynx/form.rb', line 53 def field_index(name) field = @fields.find {|f| f.name == name } @fields.index(field) end |
#last_attempt? ⇒ Boolean
62 63 64 |
# File 'lib/larynx/form.rb', line 62 def last_attempt? current_field.last_attempt? end |
#next_field(field_name = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/larynx/form.rb', line 37 def next_field(field_name=nil) if field_name @field_index = field_index(field_name) else @field_index += 1 end if field = current_field field.run(self) field end end |
#restart_form ⇒ Object
32 33 34 35 |
# File 'lib/larynx/form.rb', line 32 def restart_form @field_index = -1 run end |
#run ⇒ Object
27 28 29 30 |
# File 'lib/larynx/form.rb', line 27 def run instance_eval &self.class.setup_block if self.class.setup_block next_field end |