Module: SchoolgirlUniform::Uniformable
- Defined in:
- app/forms/uniformable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #current_step ⇒ Object
- #current_step_index ⇒ Object
- #first_step? ⇒ Boolean
- #last_step? ⇒ Boolean
- #next_step ⇒ Object
- #persisted? ⇒ Boolean
- #previous_step ⇒ Object
- #save! ⇒ Object
- #save_form! ⇒ Object
- #steps ⇒ Object
- #steps_details ⇒ Object
Class Method Details
.included(base) ⇒ Object
27 28 29 30 31 |
# File 'app/forms/uniformable.rb', line 27 def self.included(base) base.extend(ClassMethods) base.include ActiveModel::Model base.include ActiveModel::Attributes end |
Instance Method Details
#current_step ⇒ Object
55 56 57 |
# File 'app/forms/uniformable.rb', line 55 def current_step step end |
#current_step_index ⇒ Object
85 86 87 |
# File 'app/forms/uniformable.rb', line 85 def current_step_index Array(steps).index(current_step) end |
#first_step? ⇒ Boolean
69 70 71 |
# File 'app/forms/uniformable.rb', line 69 def first_step? current_step == self.class.defined_steps.first end |
#last_step? ⇒ Boolean
73 74 75 |
# File 'app/forms/uniformable.rb', line 73 def last_step? current_step == self.class.defined_steps.last end |
#next_step ⇒ Object
59 60 61 62 |
# File 'app/forms/uniformable.rb', line 59 def next_step return if last_step? || !valid? shift_step(1) end |
#persisted? ⇒ Boolean
89 90 91 |
# File 'app/forms/uniformable.rb', line 89 def persisted? false end |
#previous_step ⇒ Object
64 65 66 67 |
# File 'app/forms/uniformable.rb', line 64 def previous_step return if first_step? shift_step(-1) end |
#save! ⇒ Object
33 34 35 |
# File 'app/forms/uniformable.rb', line 33 def save! raise NotImplementedError, "#{self.class.name} must implement #save!" end |
#save_form! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/forms/uniformable.rb', line 37 def save_form! unless defined?(ActiveRecord::Base) raise "ActiveRecord::Base not available for transaction" end ActiveRecord::Base.transaction do save! rescue => e if e.respond_to?(:record) && e.record.respond_to?(:errors) e.record.errors.each { |error| errors.add(error.attribute, error.) } else errors.add(:base, e.) end raise ActiveRecord::Rollback end errors.empty? end |
#steps ⇒ Object
77 78 79 |
# File 'app/forms/uniformable.rb', line 77 def steps self.class.defined_steps end |
#steps_details ⇒ Object
81 82 83 |
# File 'app/forms/uniformable.rb', line 81 def steps_details self.class.steps_details end |