Class: ActiveRecord::Extensions::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/ar-extensions/extensions.rb

Overview

ActiveRecored::Extensions::Registry is used to register finder extensions. Extensions are processed in last in first out order, like a stack.

Instance Method Summary collapse

Constructor Details

#initializeRegistry

:nodoc:



134
135
136
# File 'lib/ar-extensions/extensions.rb', line 134

def initialize # :nodoc:
  @registry = []
end

Instance Method Details

#options(extension) ⇒ Object

:nodoc:



120
121
122
123
124
# File 'lib/ar-extensions/extensions.rb', line 120

def options( extension )
  extension_arr = @registry.detect{ |arr| arr.first == extension }
  return unless extension_arr
  extension_arr.last
end

#process(field, value, caller) ⇒ Object

:nodoc:



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/ar-extensions/extensions.rb', line 138

def process( field, value, caller ) # :nodoc:
  current_adapter = caller.connection.adapter_name.downcase
  @registry.reverse.each do |(extension,options)|
    adapters = options[:adapters]
    adapters.map!{ |e| e.to_s } unless adapters == :all
    next if options[:adapters] != :all and adapters.grep( /#{current_adapter}/ ).empty?
    if result=extension.process( field, value, caller )
      return result
    end
  end
  nil
end

#register(extension, options) ⇒ Object

:nodoc:



130
131
132
# File 'lib/ar-extensions/extensions.rb', line 130

def register( extension, options ) # :nodoc:
  @registry << [ extension, options ]
end

#registers?(extension) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


126
127
128
# File 'lib/ar-extensions/extensions.rb', line 126

def registers?( extension ) # :nodoc:
  @registry.detect{ |arr| arr.first == extension }
end