module SimpleFormObject
Originally from: github.com/reinteractive-open/simple_form_object Copied here (along with specs) so we can add Rails 5 support and tweak as needed
Public Class Methods
new(attributes = {})
click to toggle source
Calls superclass method
# File lib/simple_form_object.rb, line 90 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 72 def _delegation_target target = self.class._delegation_target if target.is_a? Symbol self.send(target) else target end end
attribute?(attribute_name)
click to toggle source
# File lib/simple_form_object.rb, line 86 def attribute?(attribute_name) self.class._attribute(attribute_name).present? end
attributes()
click to toggle source
# File lib/simple_form_object.rb, line 97 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 82 def column_for_attribute(attribute) self.class._attribute(attribute).fake_column end
delegatable?(method)
click to toggle source
rubocop:enable Style/MethodMissing
# File lib/simple_form_object.rb, line 64 def delegatable?(method) if !_delegation_target.nil? _delegation_target.respond_to?(method) else false end end
method_missing(method, *args, &block)
click to toggle source
TODO: Currently having to eat this rubocop error until such time as we understand what form the respond_to_missing? should take rubocop:disable Style/MethodMissing
Calls superclass method
# File lib/simple_form_object.rb, line 46 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. # TODO: At this time don't understand enough about the gem to understand how # best to resolve this issue. # rubocop:disable Lint/ShadowingOuterLocalVariable self.class.send(:define_method, method) do |*args, &block| _delegation_target.send(method, *args, &block) end # rubocop:enable Lint/ShadowingOuterLocalVariable send(method, *args, &block) end