module FreeForm::Property::ClassMethods

Public Instance Methods

allow_destroy_on_save() click to toggle source
# File lib/freeform/form/property.rb, line 15
def allow_destroy_on_save
  # Define _destroy method for marked-for-destruction handling
  attr_accessor :_destroy
  define_method(:_destroy=) do |value|
    false_values  = [nil, 0 , false, "0", "false"]
    true_values  = [1 , true, "1", "true"]

    #TODO: Test this!!
    @_destroy = !false_values.include?(value)  # Mark initially
    # if (@_destroy == false) # Can only switch if false
    #   @_destroy = true if true_values.include?(value)
    # end
  end
  alias_method :marked_for_destruction?, :_destroy
  define_method(:mark_for_destruction) do
    @_destroy = true
  end
end
property(attribute, options={}) click to toggle source
# File lib/freeform/form/property.rb, line 34
def property(attribute, options={})
  @property_mappings ||= Hash.new
  model = options[:on] ? options [:on] : :self
  field = options[:as] ? options[:as] : attribute.to_sym
  ignore_blank = options[:ignore_blank] ? options[:ignore_blank] : false
  @property_mappings.merge!({field => {:model => model, :field => attribute.to_sym, :ignore_blank => ignore_blank}})

  if model == :self
    attr_accessor attribute
  else
    define_method("#{field}") do
      send("#{model}").send("#{attribute}")
    end

    define_method("#{field}=") do |value|
      send("#{model}").send("#{attribute}=", value)
    end
  end
end
property_mappings() click to toggle source
# File lib/freeform/form/property.rb, line 10
def property_mappings
  # Take the form of {:property => {:model => model, :field => field, :ignore_blank => false}}
  @property_mappings ||= Hash.new
end