Class: Deadwood::Katello::Base

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/deadwood/model/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collection_path(prefix_options = {}, query_options = nil) ⇒ Object



32
33
34
35
# File 'lib/deadwood/model/base.rb', line 32

def collection_path(prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
end

.configObject



57
58
59
# File 'lib/deadwood/model/base.rb', line 57

def config
  @@config
end

.config=(conf = {}) ⇒ Object



61
62
63
64
# File 'lib/deadwood/model/base.rb', line 61

def config=(conf={})
  @@config = conf
  self.site = @@config[:site]
end

.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object



27
28
29
30
# File 'lib/deadwood/model/base.rb', line 27

def element_path(id, prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
end

.get(method_name, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/deadwood/model/base.rb', line 48

def get(method_name, options = {})
  object_array = connection.get(custom_method_collection_url(method_name, options), headers)
  if object_array.class.to_s=="Array"
    object_array.collect! {|record| self.class.new.load(record)}
  else
    self.class.new.load(object_array)
  end
end

.instantiate_collection(collection, prefix_options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/deadwood/model/base.rb', line 37

def instantiate_collection(collection, prefix_options = {})
  if collection.kind_of? Array
    collection.collect! { |record| instantiate_record(record, prefix_options) }
  elsif collection.kind_of? String
    collection
  else
    [instantiate_record(collection, prefix_options)]
  end
  rescue ArgumentError
end

.use_oauth?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/deadwood/model/base.rb', line 66

def use_oauth?
  config[:consumer_key] && config[:consumer_secret] && config[:site]
end

Instance Method Details

#collection_path(prefix_options = {}, query_options = nil) ⇒ Object



78
79
80
81
82
# File 'lib/deadwood/model/base.rb', line 78

def collection_path(prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  query_options.merge!(self.attributes)
  "#{self.class.prefix(prefix_options)}#{self.class.collection_name}#{query_string(query_options)}"
end

#load_attributes_from_response(response) ⇒ Object



71
72
73
74
75
76
# File 'lib/deadwood/model/base.rb', line 71

def load_attributes_from_response(response)
  if response['Content-Length'] != "0" && response.body.strip.size > 0
    load(self.class.format.decode(response.body))
  end
  rescue ArgumentError
end

#query_string(options) ⇒ Object



84
85
86
# File 'lib/deadwood/model/base.rb', line 84

def query_string(options)
  "?#{options.to_query}" unless options.nil? || options.empty?
end