Sha256: 5446fdf299f16aa2cc8a4927a04b9ada6b80150f44ff0a3bafabe7fe03ace154

Contents?: true

Size: 998 Bytes

Versions: 8

Compression:

Stored size: 998 Bytes

Contents

module WialonApi
  # An API method namespace (such as `users` or `friends`).
  #
  # It includes `Resolvable` and `Resolver` and calls API methods via `Resolver#call_method`.
  # It also holds the list of all known namespaces.
  class Namespace
    include Resolvable
    include Resolver

    # Creates and calls the `WialonApi::Method` using `WialonApi::Resolver#call_method`.
    def method_missing(*args, &block)
      call_method(args, &block)
    end

    class << self
      # An array of all method namespaces.
      #
      # Lazily loads the list from `namespaces.yml` and caches it.
      # @return [Array] An array of strings
      def names
        if @names.nil?
          filename = File.expand_path('../namespaces.yml', __FILE__)
          @names   = YAML.load_file(filename) || []
        end

        @names
      end

      # Does a given namespace exist?
      # @param [String, Symbol] name
      def exists?(name)
        names.include?(name.to_s)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wialon_api-0.0.8 lib/wialon_api/namespace.rb
wialon_api-0.0.7 lib/wialon_api/namespace.rb
wialon_api-0.0.6 lib/wialon_api/namespace.rb
wialon_api-0.0.5 lib/wialon_api/namespace.rb
wialon_api-0.0.4 lib/wialon_api/namespace.rb
wialon_api-0.0.3 lib/wialon_api/namespace.rb
wialon_api-0.0.2 lib/wialon_api/namespace.rb
wialon_api-0.0.1 lib/wialon_api/namespace.rb