Module: SchoolgirlUniform::Uniformable

Defined in:
app/forms/uniformable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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_stepObject



55
56
57
# File 'app/forms/uniformable.rb', line 55

def current_step
  step
end

#current_step_indexObject



85
86
87
# File 'app/forms/uniformable.rb', line 85

def current_step_index
  Array(steps).index(current_step)
end

#first_step?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


73
74
75
# File 'app/forms/uniformable.rb', line 73

def last_step?
  current_step == self.class.defined_steps.last
end

#next_stepObject



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

Returns:

  • (Boolean)


89
90
91
# File 'app/forms/uniformable.rb', line 89

def persisted?
  false
end

#previous_stepObject



64
65
66
67
# File 'app/forms/uniformable.rb', line 64

def previous_step
  return if first_step?
  shift_step(-1)
end

#save!Object

Raises:

  • (NotImplementedError)


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.message) }
    else
      errors.add(:base, e.message)
    end
    raise ActiveRecord::Rollback
  end
  errors.empty?
end

#stepsObject



77
78
79
# File 'app/forms/uniformable.rb', line 77

def steps
  self.class.defined_steps
end

#steps_detailsObject



81
82
83
# File 'app/forms/uniformable.rb', line 81

def steps_details
  self.class.steps_details
end