Sha256: 862a688f1ee63c25368be807845468deeee619da833f689c8cf9f7031742ffd0

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require 'virtus'

module Mashery
  class RpcClient
    class Base
      include Virtus

      def self.count
        default_query.items(1).to_json["result"]["total_items"]
      end

      def self.all
        default_query.all
      end

      def self.select(argument)
        default_query.select(argument)
      end

      def self.items(argument)
        default_query.items(argument)
      end

      def self.where(argument)
        default_query.where(argument)
      end

      def self.page(argument)
        default_query.page(argument)
      end

      def self.find_each(&block)
        default_query.find_each(&block)
      end

      def self.first
        new(standard_query.items(1).all.items[0])
      end

      protected

      def self.standard_query
        Mashery.rpc.query_builder(self).from(object_type).items(100)
      end

      def self.default_query
        standard_query
      end

      def self.object_type
        self.name.underscore.split('/').last.pluralize
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mashery_rails-0.6.9.pre4 lib/mashery/rpc_client/base.rb
mashery_rails-0.6.9.pre3 lib/mashery/rpc_client/base.rb
mashery_rails-0.6.9.pre1 lib/mashery/rpc_client/base.rb
mashery_rails-0.6.8 lib/mashery/rpc_client/base.rb