module SimpleFormObject

Constants

VERSION

Public Class Methods

new(attributes={}) click to toggle source
Calls superclass method
# File lib/simple_form_object.rb, line 77
def initialize(attributes={})
  super
  self.class._attributes.each do |attribute|
    attribute.apply_default_to(self)
  end
end

Public Instance Methods

_delegation_target() click to toggle source
# File lib/simple_form_object.rb, line 59
def _delegation_target
  target = self.class._delegation_target

  if target.is_a? Symbol
    self.send(target)
  else
    target
  end
end
attributes() click to toggle source
# File lib/simple_form_object.rb, line 84
def attributes
  attribs = {}
  self.class._attributes.each do |a|
    attribs[a.name] = self.send(a.name)
  end
  attribs
end
column_for_attribute(attribute) click to toggle source
# File lib/simple_form_object.rb, line 69
def column_for_attribute(attribute)
  self.class._attribute(attribute).fake_column
end
delegatable?(method) click to toggle source
# File lib/simple_form_object.rb, line 50
def delegatable?(method)

  if !_delegation_target.nil?
    _delegation_target.respond_to?(method)
  else
    false
  end
end
has_attribute?(attribute_name) click to toggle source
# File lib/simple_form_object.rb, line 73
def has_attribute?(attribute_name)
  self.class._attribute(attribute_name).present?
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/simple_form_object.rb, line 37
def method_missing(method, *args, &block)
  return super unless delegatable?(method)

  # TODO: Figure out why self.class.delegate(method, to: self.class._delegation_target)
  # doesn't work.

  self.class.send(:define_method, method) do |*args, &block|
    _delegation_target.send(method, *args, &block)
  end

  send(method, *args, &block)
end