Class: Pickle::Config
- Inherits:
-
Object
- Object
- Pickle::Config
- Defined in:
- lib/pickle/config.rb
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.
7 8 9 |
# File 'lib/pickle/config.rb', line 7 def initialize(&block) configure(&block) if block_given? end |
Instance Attribute Details
#adapters ⇒ Object
15 16 17 |
# File 'lib/pickle/config.rb', line 15 def adapters @adapters ||= [:machinist, :factory_girl, :active_record] end |
#factories ⇒ Object
23 24 25 26 27 |
# File 'lib/pickle/config.rb', line 23 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
35 36 37 |
# File 'lib/pickle/config.rb', line 35 def mappings @mappings ||= [] end |
#predicates ⇒ Object
29 30 31 32 33 |
# File 'lib/pickle/config.rb', line 29 def predicates @predicates ||= Pickle::Adapter.model_classes.map do |k| k.public_instance_methods.select{|m| m =~ /\?$/} + k.column_names end.flatten.uniq end |
Instance Method Details
#adapter_classes ⇒ Object
19 20 21 |
# File 'lib/pickle/config.rb', line 19 def adapter_classes adapters.map {|a| a.is_a?(Class) ? a : "pickle/adapter/#{a}".classify.constantize} end |
#configure {|_self| ... } ⇒ Object
11 12 13 |
# File 'lib/pickle/config.rb', line 11 def configure(&block) yield(self) end |
#map(*args) ⇒ Object
Usage: map ‘me’, ‘myself’, ‘I’, :to => ‘user: “me”’
40 41 42 43 44 45 46 |
# File 'lib/pickle/config.rb', line 40 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 << OpenStruct.new(:search => search, :replace => [:to]) end end |