Class: Weavr::Resource

Inherits:
Object
  • Object
show all
Includes:
Gorillib::Builder
Defined in:
lib/weavr/resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.child_resourcesObject



25
26
27
# File 'lib/weavr/resource.rb', line 25

def child_resources
  @resources ||= []
end

.extract_class_params(params) ⇒ Object



12
13
14
# File 'lib/weavr/resource.rb', line 12

def extract_class_params params
  params.merge(params[label] || {})
end

.labelObject



16
17
18
# File 'lib/weavr/resource.rb', line 16

def label
  name.demodulize.pluralize
end

.load_definitions!Object



29
30
31
32
33
# File 'lib/weavr/resource.rb', line 29

def load_definitions!
  child_resources.each do |name|
    require File.expand_path("../resource/#{name.underscore}", __FILE__)
  end
end

.predefine_class(name) ⇒ Object



20
21
22
23
# File 'lib/weavr/resource.rb', line 20

def predefine_class name
  Weavr.const_set(name, Class.new(self))
  child_resources << name
end

.receive(params, &blk) ⇒ Object



8
9
10
# File 'lib/weavr/resource.rb', line 8

def receive(params, &blk)
  super extract_class_params(params, &blk)
end

Instance Method Details

#connectionObject



40
41
42
# File 'lib/weavr/resource.rb', line 40

def connection
  Weavr.connection
end

#receive!(params) ⇒ Object



36
37
38
# File 'lib/weavr/resource.rb', line 36

def receive! params
  super self.class.extract_class_params(params)
end

#refresh!Object



48
49
50
51
# File 'lib/weavr/resource.rb', line 48

def refresh!
  receive! resource_action(:get)
  self
end

#resource_action(action, data = {}) ⇒ Object



44
45
46
# File 'lib/weavr/resource.rb', line 44

def resource_action(action, data = {})
  connection.resource(action, href, data)
end