Class: ActiveRecord::Extensions::Registry
- Inherits:
-
Object
- Object
- ActiveRecord::Extensions::Registry
- 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
-
#initialize ⇒ Registry
constructor
:nodoc:.
-
#options(extension) ⇒ Object
:nodoc:.
-
#process(field, value, caller) ⇒ Object
:nodoc:.
-
#register(extension, options) ⇒ Object
:nodoc:.
-
#registers?(extension) ⇒ Boolean
:nodoc:.
Constructor Details
#initialize ⇒ Registry
: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 ( 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,)| adapters = [:adapters] adapters.map!{ |e| e.to_s } unless adapters == :all next if [: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, ) # :nodoc: @registry << [ extension, ] end |
#registers?(extension) ⇒ Boolean
:nodoc:
126 127 128 |
# File 'lib/ar-extensions/extensions.rb', line 126 def registers?( extension ) # :nodoc: @registry.detect{ |arr| arr.first == extension } end |