Class: GhostRb::Controllers::BaseController
- Inherits:
-
Object
- Object
- GhostRb::Controllers::BaseController
show all
- Defined in:
- lib/ghost_rb/controllers/base_controller.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, params = nil) ⇒ BaseController
Returns a new instance of BaseController.
14
15
16
17
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 14
def initialize(client, params = nil)
@client = client
@params = Support::HashWithIndifferentAccess.new(params)
end
|
Instance Attribute Details
#client ⇒ Object
12
13
14
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 12
def client
@client
end
|
#params ⇒ Object
12
13
14
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 12
def params
@params
end
|
Instance Method Details
#all ⇒ Object
19
20
21
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 19
def all
fetch_list.map { |r| @resource_klass.generate(r) }
end
|
#fields(fields_str) ⇒ Object
35
36
37
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 35
def fields(fields_str)
where(fields: fields_str)
end
|
#filter(filter_query) ⇒ Object
39
40
41
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 39
def filter(filter_query)
where(filter: filter_query)
end
|
#find_by(kvp) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 51
def find_by(kvp)
@params.keys.reject { |k| k == :include }.each do |key|
@params.delete(key)
end
content = fetch_single(kvp)
resource_klass.generate(content)
end
|
#include(resources_str) ⇒ Object
43
44
45
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 43
def include(resources_str)
where(include: resources_str)
end
|
#limit(limit) ⇒ Object
23
24
25
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 23
def limit(limit)
where(limit: limit)
end
|
#order(order_str) ⇒ Object
31
32
33
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 31
def order(order_str)
where(order: order_str)
end
|
#page(page) ⇒ Object
27
28
29
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 27
def page(page)
where(page: page)
end
|
#where(hash) ⇒ Object
47
48
49
|
# File 'lib/ghost_rb/controllers/base_controller.rb', line 47
def where(hash)
self.class.new(client, @params.merge(hash))
end
|