class Syrup::FormObject

Public Class Methods

attributes_protected_by_default() click to toggle source
# File lib/syrup/form_object.rb, line 41
def self.attributes_protected_by_default
  []
end
find(params) click to toggle source
# File lib/syrup/form_object.rb, line 20
def find(params)
  form = self.new
  form.find_relations(params)
  form.after_find(params)
  form
end
form_name(form_name) click to toggle source
# File lib/syrup/form_object.rb, line 27
    def form_name(form_name)
      instance_eval <<-EOH
        def self.model_name
          ActiveModel::Name.new(self, nil, '#{form_name.to_s}')
        end
      EOH
    end
new(params={}) click to toggle source
# File lib/syrup/form_object.rb, line 45
def initialize(params={})
  build_relations
  build(params)
  self.assign_attributes(params)
end
reflect_on_association(*) click to toggle source
# File lib/syrup/form_object.rb, line 39
def self.reflect_on_association(*); end
standalone() click to toggle source
# File lib/syrup/form_object.rb, line 16
def standalone
  include Syrup::Form::Standalone
end
wraps(klass) click to toggle source
# File lib/syrup/form_object.rb, line 10
def wraps(klass)
  has_one(klass)
  @wrapped_class_name = klass
  include Syrup::Form::Wrapped
end

Public Instance Methods

add_to_transaction() click to toggle source
# File lib/syrup/form_object.rb, line 40
def add_to_transaction; end
after_find(params) click to toggle source
# File lib/syrup/form_object.rb, line 57
def after_find(params); end
build(params) click to toggle source
# File lib/syrup/form_object.rb, line 56
def build(params); end
clear_transaction_record_state(*) click to toggle source
# File lib/syrup/form_object.rb, line 38
def clear_transaction_record_state(*); end
create() click to toggle source
# File lib/syrup/form_object.rb, line 78
def create
  run_callbacks(:create) { save_form }
end
create_record() click to toggle source
# File lib/syrup/form_object.rb, line 70
def create_record
  run_callbacks(:create) {save_form}
end
remember_transaction_record_state(*) click to toggle source
# File lib/syrup/form_object.rb, line 36
def remember_transaction_record_state(*); end
restore_transaction_record_state(*) click to toggle source
# File lib/syrup/form_object.rb, line 37
def restore_transaction_record_state(*); end
run_validations!(*) click to toggle source
Calls superclass method
# File lib/syrup/form_object.rb, line 59
def run_validations!(*)
  super
  self.related_objects.each do |klass, related|
    unless related.valid?
      self.errors.add(klass, related.errors)
    end
  end
end
update(attributes=[]) click to toggle source
# File lib/syrup/form_object.rb, line 82
def update(attributes=[])
  run_callbacks(:update) { save_form }
end
update_attributes(params) click to toggle source
# File lib/syrup/form_object.rb, line 51
def update_attributes(params)
  self.assign_attributes(params)
  self.save
end
update_record(attributes=[]) click to toggle source
# File lib/syrup/form_object.rb, line 74
def update_record(attributes=[])
  run_callbacks(:update) {save_form}
end