Module: Rubysolo::Hashdown::Finder

Defined in:
lib/finder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/finder.rb', line 5

def self.included(base)
  base.instance_eval do
    validates_uniqueness_of finder_attribute

    cattr_accessor :cache_store
    self.cache_store ||= ActiveSupport::Cache::MemoryStore.new

    def self.[](token)
      cache_store.fetch("[]:#{token}", :force => Rubysolo::Hashdown.force_cache_miss?) {
        returning find(:first, :conditions => { finder_attribute => token.to_s}) do |record|
          raise "Could not find #{self.class_name} with #{finder_attribute} '#{token}'" unless record
        end
      }
    end
  end
end

Instance Method Details

#is?(token) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/finder.rb', line 22

def is?(token)
  self[self.class.finder_attribute] == token.to_s
end