Module: Identifiable

Defined in:
lib/dragonfly_extensions/identifiable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/dragonfly_extensions/identifiable.rb', line 2

def self.included(base)
  base.extend ClassMethods
  
  base.has_many :identifiers, :as => :identifiable, :dependent => :destroy
  IdentifierType.uncached do
    for record in IdentifierType.all(true)
      base.has_many record.name.downcase.pluralize,  :as => :identifiable
      base.has_one  record.name.downcase,            :as => :identifiable, :order => "#{Identifier.table_name}.position ASC"
    end  
  end
end

Instance Method Details

#identified_by?(name) ⇒ Boolean

Determine if a value is an identifier for a model

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/dragonfly_extensions/identifiable.rb', line 29

def identified_by?(name)
  identifiers = self.identifiers.collect{|i| i.name}
  identifiers.include?(name)
end

#not_identified_by?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dragonfly_extensions/identifiable.rb', line 34

def not_identified_by?(name)
  !identified_by?(name)
end