Module: Octopi::Resource::ClassMethods

Public Visibility

Public Instance Method Summary

#create_path(path)
#declassify(s)
#delete_path(path)
#find(*args)
#find_all(*s)
#find_path(path)
#find_plural(s, path)
#path_for(type)
#resource_name(key)
#resource_path(path)
#set_resource_name(singular, plural = "#{singular}s")

Public Instance Method Details

create_path

public create_path(path)
[View source]


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

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

declassify

public declassify(s)
[View source]


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

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

delete_path

public delete_path(path)
[View source]


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

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

find

public find(*args)
[View source]


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)
  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

public find_all(*s)
[View source]


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

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

find_path

public find_path(path)
[View source]


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

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

find_plural

public find_plural(s, path)
[View source]


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

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

path_for

public path_for(type)
[View source]


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

def path_for(type)
  @path_spec[type]
end

resource_name

public resource_name(key)
[View source]


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

def resource_name(key)
  @resource_name[key]
end

resource_path

public resource_path(path)
[View source]


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

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

set_resource_name

public set_resource_name(singular, plural = "#{singular}s")
[View source]


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
Generated on Friday, July 31 2009 at 05:01:54 PM by YARD 0.2.3.2 (ruby-1.8.6).