Module: OAuth2::Model::Hashing

Included in:
Authorization
Defined in:
lib/oauth2/model/hashing.rb

Instance Method Summary collapse

Instance Method Details

#hashes_attributes(*attributes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/oauth2/model/hashing.rb', line 5

def hashes_attributes(*attributes)
  attributes.each do |attribute|
    define_method("#{attribute}=") do |value|
      instance_variable_set("@#{attribute}", value)
      __send__("#{attribute}_hash=", value && OAuth2.hashify(value))
    end
    attr_reader attribute
  end
  
  class_eval <<-RUBY
    def reload(*args)
      super
      #{ attributes.inspect }.each do |attribute|
        instance_variable_set('@' + attribute.to_s, nil)
      end
    end
  RUBY
end