Module: Googletastic::Mixins::Finders::ClassMethods
- Defined in:
- lib/googletastic/mixins/finders.rb
Instance Method Summary collapse
- #all(*args) ⇒ Object
- #find(*args) ⇒ Object
- #find_by_api(options) ⇒ Object
- #find_every(options) ⇒ Object
- #find_from_ids(ids, options) ⇒ Object
- #find_initial(options) ⇒ Object
- #find_last(options) ⇒ Object
- #find_one(id, options) ⇒ Object
- #find_some(ids, options) ⇒ Object
- #first(*args) ⇒ Object
- #head(*args) ⇒ Object
- #last(*args) ⇒ Object
Instance Method Details
#all(*args) ⇒ Object
23 24 25 |
# File 'lib/googletastic/mixins/finders.rb', line 23 def all(*args) find(:all, *args) end |
#find(*args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/googletastic/mixins/finders.rb', line 27 def find(*args) = args. case args.first when :first then find_initial() when :last then find_last() when :all then find_every() else find_from_ids(args, ) end end |
#find_by_api(options) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/googletastic/mixins/finders.rb', line 77 def find_by_api() url = build_url() agent = .has_key?(:client) ? [:client] : client data = agent.get(url) return data if .has_key?(:raw) and [:raw] == true records = unmarshall(Nokogiri::XML(data.body)).collect {|r| r.response = data; r} end |
#find_every(options) ⇒ Object
46 47 48 |
# File 'lib/googletastic/mixins/finders.rb', line 46 def find_every() find_by_api() end |
#find_from_ids(ids, options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/googletastic/mixins/finders.rb', line 50 def find_from_ids(ids, ) expects_array = ids.first.kind_of?(Array) return ids.first if expects_array && ids.first.empty? ids = ids.flatten.compact.uniq case ids.size when 0 raise "Couldn't find #{self.to_s} without an ID" when 1 result = find_one(ids.first, ) expects_array ? [ result ] : result else find_some(ids, ) end end |
#find_initial(options) ⇒ Object
38 39 40 |
# File 'lib/googletastic/mixins/finders.rb', line 38 def find_initial() find_by_api(.merge({:limit => 1})).first end |
#find_last(options) ⇒ Object
42 43 44 |
# File 'lib/googletastic/mixins/finders.rb', line 42 def find_last() end |
#find_one(id, options) ⇒ Object
67 68 69 70 71 |
# File 'lib/googletastic/mixins/finders.rb', line 67 def find_one(id, ) [:id] = id [:url] = self.show_url(id) find_by_api().first end |
#find_some(ids, options) ⇒ Object
73 74 75 |
# File 'lib/googletastic/mixins/finders.rb', line 73 def find_some(ids, ) end |
#first(*args) ⇒ Object
15 16 17 |
# File 'lib/googletastic/mixins/finders.rb', line 15 def first(*args) find(:first, *args) end |
#head(*args) ⇒ Object
9 10 11 12 13 |
# File 'lib/googletastic/mixins/finders.rb', line 9 def head(*args) = args. result = find_by_api(.merge(:limit => 1)).first result.nil? ? nil : result.head end |
#last(*args) ⇒ Object
19 20 21 |
# File 'lib/googletastic/mixins/finders.rb', line 19 def last(*args) find(:last, *args) end |