Sha256: c06b8fb38793c998965ff4317664347f73e44514996e9383fc19e4da94f34a87

Contents?: true

Size: 358 Bytes

Versions: 1

Compression:

Stored size: 358 Bytes

Contents

class Token < ActiveRecord::Base
  belongs_to :parent, :polymorphic => true
  
  named_scope :for, lambda{|k| {:conditions => {:parent_type => k.to_s.classify}} }
  
  def self.get(value)
    find_by_value(value).try(:parent)
  end
  
  def self.get!(value)
    token = find_by_value!(value)
    token.parent_type.constantize.find(token.parent_id)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
laserlemon-has_token-0.3.3 lib/token.rb