Class: Cephalopod::Repos::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cephalopod/repos/base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: Cephalopod.client, model: default_model, resource_route: default_resource_route) ⇒ Base

Returns a new instance of Base.



30
31
32
33
34
# File 'lib/cephalopod/repos/base.rb', line 30

def initialize(client: Cephalopod.client, 
                model: default_model, 
                resource_route: default_resource_route)
  @client, @model, @resource_route = client, model, resource_route
end

Class Attribute Details

.default_modelObject

Returns the value of attribute default_model.



5
6
7
# File 'lib/cephalopod/repos/base.rb', line 5

def default_model
  @default_model
end

.default_resource_routeObject

Returns the value of attribute default_resource_route.



5
6
7
# File 'lib/cephalopod/repos/base.rb', line 5

def default_resource_route
  @default_resource_route
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



28
29
30
# File 'lib/cephalopod/repos/base.rb', line 28

def model
  @model
end

#resource_routeObject (readonly)

Returns the value of attribute resource_route.



28
29
30
# File 'lib/cephalopod/repos/base.rb', line 28

def resource_route
  @resource_route
end

Class Method Details

.model(model) ⇒ Object



7
8
9
# File 'lib/cephalopod/repos/base.rb', line 7

def model(model)
  self.default_model = model
end

.resource_route(path) ⇒ Object



11
12
13
# File 'lib/cephalopod/repos/base.rb', line 11

def resource_route(path)
  self.default_resource_route = path
end

.routeObject



21
22
23
# File 'lib/cephalopod/repos/base.rb', line 21

def route
  @route ||= Mustermann.new(default_resource_route)
end

.unsupported(*methods) ⇒ Object



15
16
17
18
19
# File 'lib/cephalopod/repos/base.rb', line 15

def unsupported(*methods)
  self.class_eval do
    methods.each { |method| alias_method method, :undefined }
  end
end

Instance Method Details

#get(method: :get, headers: {}, query: {}, body: nil, **params, &block) ⇒ Object



36
37
38
# File 'lib/cephalopod/repos/base.rb', line 36

def get(method: :get, headers: {}, query: {}, body: nil, **params, &block)
  @get ||= parse_response(@client.run_request(method, build_path(query: query, **params), body, headers, &block))
end