Module: Resourceful::Model::Findable::ClassMethods
- Defined in:
- lib/resourceful/model/findable.rb
Instance Method Summary collapse
- #all ⇒ Object
- #find(id, opts = {}, force = false) ⇒ Object
- #findable_index ⇒ Object
- #findable_search ⇒ Object
- #first ⇒ Object
- #last ⇒ Object
Instance Method Details
#all ⇒ Object
23 24 25 |
# File 'lib/resourceful/model/findable.rb', line 23 def all find(:all) end |
#find(id, opts = {}, force = false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/resourceful/model/findable.rb', line 8 def find(id, opts={}, force=false) opts ||= {} opts = findable_default_opts.merge(opts) if respond_to?(:findable_default_opts) case id when :all self.get_collection("#{findable_index}.#{format}", opts, findable_search, force) when :first self.get_collection("#{findable_index}.#{format}", opts, findable_search, force).first when :last self.get_collection("#{findable_index}.#{format}", opts, findable_search, force).last else self.get("#{findable_index}/#{id}.#{format}", opts, findable_search, force) end end |
#findable_index ⇒ Object
33 34 35 |
# File 'lib/resourceful/model/findable.rb', line 33 def findable_index raise NotImplementedError, "Findable expects a public class method 'findable_index'" end |
#findable_search ⇒ Object
37 38 39 40 |
# File 'lib/resourceful/model/findable.rb', line 37 def findable_search # defaults to non namespaced downcased name of the class self.name.demodulize.underscore.to_s.gsub(/^.*::/, '') end |
#first ⇒ Object
26 27 28 |
# File 'lib/resourceful/model/findable.rb', line 26 def first find(:first) end |
#last ⇒ Object
29 30 31 |
# File 'lib/resourceful/model/findable.rb', line 29 def last find(:last) end |