Class: Finder
- Inherits:
-
Object
- Object
- Finder
- Defined in:
- lib/record-locator-finder.rb
Instance Method Summary collapse
- #find(id) ⇒ Object
- #find_all(id) ⇒ Object
-
#initialize(model, record_locator_field) ⇒ Finder
constructor
A new instance of Finder.
Constructor Details
#initialize(model, record_locator_field) ⇒ Finder
Returns a new instance of Finder.
3 4 5 6 |
# File 'lib/record-locator-finder.rb', line 3 def initialize(model,record_locator_field) @model = model @record_locator_field = record_locator_field end |
Instance Method Details
#find(id) ⇒ Object
8 9 10 |
# File 'lib/record-locator-finder.rb', line 8 def find(id) find_all(id).first end |
#find_all(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/record-locator-finder.rb', line 12 def find_all(id) # for Rails > 4.0, use ActiveRecord where method #@model.where("#{@record_locator_field}=?", Util::Base::decode(id.to_s)) # supported until rails 4.0 from rails 2.3 records = @model.find(:all, :conditions => "#{@record_locator_field}='#{Util::Base::decode(id.to_s)}'") if records.empty? records = @model.find(:all, :conditions => "#{@record_locator_field}='#{id}'") end return records end |