songkick/oauth2-provider

View on GitHub
lib/songkick/oauth2/model/hashing.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Songkick
  module OAuth2
    module Model

      module Hashing
        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
      end

    end
  end
end