Sha256: fc5cc4cc16ace3b30f01f444802d3253adadc8947dcdf2da8467ccd6ac4b4828

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module Loquor
  class Resource

    def initialize(data)
      @data = ObjectHash.new(data, strict: true)
    end

    def method_missing(name, *args)
      @data[name]
    rescue
      raise NameError.new("undefined local variable or method '#{name}' for #{self.class.name}")
    end

    def respond_to?(name)
      return true if super
      @data.respond_to?(name)
    end

    def self.path=(path)
      @path = path
    end

    def self.path
      @path
    end

    def self.cache=(value)
      @value = value
    end

    def self.cache
      @value
    end

    def self.find(id)
      ApiCall::Show.new(self, id).execute
    end

    def self.find_each(&block)
      ApiCall::Index.new(self).find_each(&block)
    end

    def self.select(*args)
      ApiCall::Index.new(self).select(*args)
    end

    def self.where(*args)
      ApiCall::Index.new(self).where(*args)
    end

    def self.create(payload)
      ApiCall::Create.new(self, payload: payload).execute
    end

    def self.update(id, payload)
      ApiCall::Update.new(self, id, payload: payload).execute
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
loquor-1.5.0 lib/loquor/resource.rb
loquor-1.4.0 lib/loquor/resource.rb
loquor-1.3.0 lib/loquor/resource.rb
loquor-1.2.1 lib/loquor/resource.rb
loquor-1.2.0 lib/loquor/resource.rb
loquor-1.1.1 lib/loquor/resource.rb
loquor-1.1.0 lib/loquor/resource.rb