Sha256: 69ad731d46cbedaa90b7295f7c6d4ead8ce2536e016844fbaa32ef7700acc57a

Contents?: true

Size: 926 Bytes

Versions: 6

Compression:

Stored size: 926 Bytes

Contents

module VkontakteApi
  # A mixin for classes that will resolve other classes' objects via `#method_missing`.
  module Resolver
    # A `Hashie::Mash` structure holding the name and token of current instance.
    # @return [Hashie::Mash]
    def resolver
      @resolver ||= Hashie::Mash.new(name: @name, token: token)
    end
    
  private
    def create_namespace(name)
      Namespace.new(name, resolver: resolver)
    end
    
    def create_method(name)
      Method.new(name, resolver: resolver)
    end
    
    def call_method(args, &block)
      create_method(args.shift).call(args.first || {}, &block)
    end
    
    class << self
      # When this module is included, it undefines the `:send` instance method in the `base_class`
      # so it can be resolved via `method_missing`.
      def included(base_class)
        base_class.class_eval do
          undef_method :send
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vkontakte_api-1.4.4 lib/vkontakte_api/resolver.rb
vkontakte_api-1.4.3 lib/vkontakte_api/resolver.rb
vkontakte_api-1.4.2 lib/vkontakte_api/resolver.rb
vkontakte_api-1.4 lib/vkontakte_api/resolver.rb
vkontakte_api-1.3.1 lib/vkontakte_api/resolver.rb
vkontakte_api-1.3 lib/vkontakte_api/resolver.rb