Class: Hummer::Client::Model::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hummer/client/model/base.rb

Direct Known Subclasses

Feature, Project, Suite

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



40
41
42
43
44
# File 'lib/hummer/client/model/base.rb', line 40

def initialize(params = {})
  params.each do |key, value|
    send("#{key}=", value) if respond_to? "#{key}="
  end
end

Class Method Details

.all(resource = nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/hummer/client/model/base.rb', line 32

def self.all(resource = nil)
  JSON(@@server[resource || @resource].get).collect do |params|
    new(params)
  end
rescue => e
  puts "API error: #{e.message}"
  exit(1)
end

.attributes(*args) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/hummer/client/model/base.rb', line 18

def self.attributes *args
  @attributes = []
  args.each do |arg|
    @attributes << arg
    self.class_eval("def #{arg};@#{arg};end")
    self.class_eval("def #{arg}=(val);@#{arg}=val;end")
  end
end

.configure(options) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/hummer/client/model/base.rb', line 6

def self.configure(options)
  @@server = RestClient::Resource.new(options[:server],
    :headers => {
      "X-User-ID" => options[:user],
      "X-User-Token" => options[:token],
      "Accept" => "application/json"
    }
  )
end

.find(id, resource = nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/hummer/client/model/base.rb', line 26

def self.find(id, resource = nil)
  new(JSON(@@server[resource || @resource][id].get))
rescue => e
  puts "API error: #{e.message}"
  exit(1)
end

.resource(res) ⇒ Object



15
16
17
# File 'lib/hummer/client/model/base.rb', line 15

def self.resource res
  @resource = res
end