Class: Pickle::Config
- Inherits:
-
Object
- Object
- Pickle::Config
- Defined in:
- lib/pickle/config.rb
Defined Under Namespace
Classes: Mapping
Instance Attribute Summary collapse
Instance Method Summary collapse
- #adapter_classes ⇒ Object
- #configure {|_self| ... } ⇒ Object
-
#initialize(&block) ⇒ Config
constructor
A new instance of Config.
-
#map(*args) ⇒ Object
Usage: map ‘me’, ‘myself’, ‘I’, :to => ‘user: “me”’.
Constructor Details
#initialize(&block) ⇒ Config
Returns a new instance of Config.
5 6 7 |
# File 'lib/pickle/config.rb', line 5 def initialize(&block) configure(&block) if block_given? end |
Instance Attribute Details
#adapters ⇒ Object
13 14 15 |
# File 'lib/pickle/config.rb', line 13 def adapters @adapters ||= [:machinist, :factory_girl, :orm] end |
#factories ⇒ Object
21 22 23 24 25 |
# File 'lib/pickle/config.rb', line 21 def factories @factories ||= adapter_classes.reverse.inject({}) do |factories, adapter| factories.merge(adapter.factories.inject({}){|h, f| h.merge(f.name => f)}) end end |
#mappings ⇒ Object
36 37 38 |
# File 'lib/pickle/config.rb', line 36 def mappings @mappings ||= [] end |
#predicates ⇒ Object
27 28 29 30 31 |
# File 'lib/pickle/config.rb', line 27 def predicates @predicates ||= Pickle::Adapter.model_classes.map do |k| k.public_instance_methods.select {|m| m =~ /\?$/} + Pickle::Adapter.column_names(k) end.flatten.uniq end |
Instance Method Details
#adapter_classes ⇒ Object
17 18 19 |
# File 'lib/pickle/config.rb', line 17 def adapter_classes adapters.map {|a| a.is_a?(Class) ? a : "pickle/adapter/#{a}".classify.constantize} end |
#configure {|_self| ... } ⇒ Object
9 10 11 |
# File 'lib/pickle/config.rb', line 9 def configure(&block) yield(self) end |
#map(*args) ⇒ Object
Usage: map ‘me’, ‘myself’, ‘I’, :to => ‘user: “me”’
41 42 43 44 45 46 47 |
# File 'lib/pickle/config.rb', line 41 def map(*args) = args. raise ArgumentError, "Usage: map 'search' [, 'search2', ...] :to => 'replace'" unless args.any? && [:to].is_a?(String) args.each do |search| self.mappings << Mapping.new(search, [:to]) end end |