Module: Songkick::OAuth2::Model::Hashing

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

Instance Method Summary collapse

Instance Method Details

#hashes_attributes(*attributes) ⇒ Object


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

def hashes_attributes(*attributes)
  attributes.each do |attribute|
    define_method("#{attribute}=") do |value|
      instance_variable_set("@#{attribute}", value)
      __send__("#{attribute}_hash=", value && Songkick::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