module ModelManage::ClassMethods

Public Instance Methods

field(name, options = {}) click to toggle source
Calls superclass method
# File lib/model_manage/base.rb, line 23
def field(name, options = {})
  super

  min =   1
  validates = {}
  validates[:in] = options.delete(:in)  || options.delete(:within)
  if options[:limit] && (! validates[:in])
    validates[:in] = (min..options.delete(:limit)) 
  end

  validates[:allow_nil  ] = options.delete(:allow_nil)   || false
  validates[:allow_blank] = options.delete(:allow_blank) || false

  null_ok = validates[:allow_nil] || validates[:allow_blank]
  form_attributes = {
    owner:   self,
    name:    name.to_s,
    type:    options[:type] || String,
    limit:   nil,
    null:    null_ok,
    primary: key?(name),
    scale:   nil
  }

  if validates[:in].present?
    validates_length_of name, validates
    form_attributes[:limit] = validates[:in].max
    form_attributes.merge!(validates)
  end


  if options[:hidden]
    forms.delete(name)
  else
    forms[name] = OpenStruct.new(form_attributes)
  end
end
forms() click to toggle source
# File lib/model_manage/base.rb, line 12
def forms
  const_get(:FORMS)
end
key?(key) click to toggle source
# File lib/model_manage/base.rb, line 16
def key?(key)
  const_get(:KEYS).member? key.to_s
rescue
  const_set :KEYS, []
  false
end
relation_form_set(name, options = {}) click to toggle source
# File lib/model_manage/base.rb, line 61
def relation_form_set(name, options = {})
  relation_attributes = {
    owner:    self,
    name:     name.to_s,
    options:  options
  }.tap{|o| o[:data] = o.dup }
  relation = relations[name.to_s]
  relation.form = OpenStruct.new(relation_attributes)
end