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)
- - (Object) adapter_classes
- - (Object) configure {|_self| ... }
-
- (Config) initialize(&block)
constructor
A new instance of Config.
-
- (Object) map(*args)
Usage: map 'me', 'myself', 'I', :to => 'user: "me"'.
Constructor Details
- (Config) initialize(&block)
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
- (Object) adapters
13 14 15 |
# File 'lib/pickle/config.rb', line 13 def adapters @adapters ||= [:machinist, :factory_girl, :fabrication, :orm] end |
- (Object) factories
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 |
- (Object) mappings
36 37 38 |
# File 'lib/pickle/config.rb', line 36 def mappings @mappings ||= [] end |
- (Object) predicates
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
- (Object) adapter_classes
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 |
- (Object) configure {|_self| ... }
9 10 11 |
# File 'lib/pickle/config.rb', line 9 def configure(&block) yield(self) end |
- (Object) map(*args)
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 |