Module: Octopi::Resource::ClassMethods

Defined in:
lib/octopi/resource.rb

Instance Method Summary collapse

Instance Method Details

#create_path(path) ⇒ Object



23
24
25
# File 'lib/octopi/resource.rb', line 23

def create_path(path)
  (@path_spec||={})[:create] = path
end

#declassify(s) ⇒ Object



61
62
63
# File 'lib/octopi/resource.rb', line 61

def declassify(s)
  (s.split('::').last || '').downcase if s
end

#delete_path(path) ⇒ Object



35
36
37
# File 'lib/octopi/resource.rb', line 35

def delete_path(path)
  (@path_spec||={})[:delete] = path
end

#find(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/octopi/resource.rb', line 39

def find(*args)
  args = args.join('/') if args.is_a? Array
  result = Api.api.find(path_for(:resource), @resource_name[:singular], args, self, @cache)
  key = result.keys.first

  if result[key].is_a? Array
    result[key].map { |r| new(r) }
  else
    Resource.for(key).new(result[key])
  end
end

#find_all(*s) ⇒ Object



51
52
53
# File 'lib/octopi/resource.rb', line 51

def find_all(*s)
  find_plural(s, :find)
end

#find_path(path) ⇒ Object



27
28
29
# File 'lib/octopi/resource.rb', line 27

def find_path(path)
  (@path_spec||={})[:find] = path
end

#find_plural(s, path) ⇒ Object



55
56
57
58
59
# File 'lib/octopi/resource.rb', line 55

def find_plural(s, path)
  s = s.join('/') if s.is_a? Array
  resources = Api.api.find_all(path_for(path), @resource_name[:plural], s, self)
  resources.map { |item| self.new(item) }
end

#path_for(type) ⇒ Object



65
66
67
# File 'lib/octopi/resource.rb', line 65

def path_for(type)
  @path_spec[type]
end

#resource_name(key) ⇒ Object



19
20
21
# File 'lib/octopi/resource.rb', line 19

def resource_name(key)
  @resource_name[key]
end

#resource_path(path) ⇒ Object



31
32
33
# File 'lib/octopi/resource.rb', line 31

def resource_path(path)
  (@path_spec||={})[:resource] = path
end

#set_resource_name(singular, plural = "#{singular}s") ⇒ Object



15
16
17
# File 'lib/octopi/resource.rb', line 15

def set_resource_name(singular, plural = "#{singular}s")
  @resource_name = {:singular => declassify(singular), :plural => declassify(plural)}
end