module Formotion::Formable::ClassMethods

Constants

INHERITABLE_ATTRIBUTES

Public Instance Methods

form_properties() click to toggle source
# File lib/formotion/model/formable.rb, line 21
def form_properties
  @form_properties ||= self.superclass.form_properties if is_kvo_subclass?
  @form_properties ||= []
end
form_property(property, row_type, options = {}) click to toggle source

Relates a property to a RowType. @param property is the name of the attribute to KVO @param row_type is the Formotion::RowType to use for that attribute @param options are the extra options for this model. Keys can include

any usual Formotion::Row keys to override, plus :transform, which is
a single-argument lambda for transforming the row's string value before
it's synced to your model.

EX form_property :my_title => :string form_property :my_date => :date, :transform => lambda { |value| some_function(date) }

# File lib/formotion/model/formable.rb, line 36
def form_property(property, row_type, options = {})
  self.form_properties << { property: property, row_type: row_type}.merge(options)
end
form_title(title = -1) click to toggle source

Sets the top bar title for this model EX form_title “Some Settings”

# File lib/formotion/model/formable.rb, line 43
def form_title(title = -1)
  @form_title ||= self.superclass.form_title if is_kvo_subclass?
  @form_title = title if title != -1
  @form_title
end
inherited(subclass) click to toggle source

Does NOT get called when KVO occurs. (KVO uses isa swizzling and not proper subclassing)

# File lib/formotion/model/formable.rb, line 14
def inherited(subclass)
  INHERITABLE_ATTRIBUTES.each do |inheritable_attribute|
    instance_var = "@#{inheritable_attribute}"
    subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
  end
end

Private Instance Methods

is_kvo_subclass?() click to toggle source

Terrible, terrible hack.

# File lib/formotion/model/formable.rb, line 51
def is_kvo_subclass?
  self.to_s =~ /^NSKVONotifying_/
end