Class: GhostRb::Controllers::BaseController

Inherits:
Object
  • Object
show all
Defined in:
lib/ghost_rb/controllers/base_controller.rb

Overview

Author:

  • Rene Hernandez

Since:

  • 0.2

Direct Known Subclasses

PostsController, TagsController, UsersController

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, params = nil) ⇒ BaseController

Returns a new instance of BaseController.

Since:

  • 0.2



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

#clientObject (readonly)

Since:

  • 0.2



12
13
14
# File 'lib/ghost_rb/controllers/base_controller.rb', line 12

def client
  @client
end

#paramsObject (readonly)

Since:

  • 0.2



12
13
14
# File 'lib/ghost_rb/controllers/base_controller.rb', line 12

def params
  @params
end

Instance Method Details

#allObject

Since:

  • 0.2



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

Since:

  • 0.2



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

Since:

  • 0.2



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

Since:

  • 0.2



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

Since:

  • 0.2



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

Since:

  • 0.2



23
24
25
# File 'lib/ghost_rb/controllers/base_controller.rb', line 23

def limit(limit)
  where(limit: limit)
end

#order(order_str) ⇒ Object

Since:

  • 0.2



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

Since:

  • 0.2



27
28
29
# File 'lib/ghost_rb/controllers/base_controller.rb', line 27

def page(page)
  where(page: page)
end

#where(hash) ⇒ Object

Since:

  • 0.2



47
48
49
# File 'lib/ghost_rb/controllers/base_controller.rb', line 47

def where(hash)
  self.class.new(client, @params.merge(hash))
end