Module: ExposableAttributes::ClassMethods

Defined in:
lib/exposable_attributes.rb

Instance Method Summary collapse

Instance Method Details

#exposable_attributes(*attributes) ⇒ Object

Defines exposable attributes for AR object.

Examples

class User < ActiveRecord::Base
  exposable_attributes :json, :only => [:id, :login]
  exposable_attributes :xml,  :except => [:encrypted_password, :salt, :single_access_token]
  exposable_attributes :json, :xml, :except => [:encrypted_password, :salt, :single_access_token]
end


20
21
22
23
24
25
# File 'lib/exposable_attributes.rb', line 20

def exposable_attributes(*attributes)
  init_default_accessors unless already_initialized?
  access_methods, options = parse_attributes(attributes)
  access_methods.each {|method_name| define_accessor(method_name, options) }
  send :include, InstanceMethods
end