Module: Expose::Model::ClassMethods

Defined in:
lib/expose.rb

Instance Method Summary collapse

Instance Method Details

#expose(*config) ⇒ Object

USAGE expose :attribute_name, :if => Proc.new {|model condition} expose :attribute_name, :state => :new, :state => [:new,:locked]

  • this will add :param_name to the ‘attr_accessible’ params if the condition is true



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/expose.rb', line 22

def expose(*config)
  options = config.extract_options!
  options.symbolize_keys!
  options.assert_valid_keys(:if, :unless, :state, :not_state)
      
  # TODO - warnings of improper use
  # :name (attribute)
  # validate in attr_protected or not in attr_accessible, otherwise no need to expose
  #
  # :state + :not_state
  # include warning if any similarities in :state and :not_state, as they would cancel each other out

  config.each do |attr|
    if self.attribute_method?(attr.to_sym)
      # if _exposures.has_key?(name.to_sym)
      #   # log duplication ?
      # end
      _exposures[attr.to_sym] = options
    else
     raise "Expose: invalid attribute - #{name.to_s}"
    end
  end
end