Class: Pickle::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pickle/config.rb

Defined Under Namespace

Classes: Mapping

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adaptersObject



13
14
15
# File 'lib/pickle/config.rb', line 13

def adapters
  @adapters ||= [:machinist, :factory_girl, :fabrication, :orm]
end

#factoriesObject



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

#mappingsObject



36
37
38
# File 'lib/pickle/config.rb', line 36

def mappings
  @mappings ||= []
end

#predicatesObject



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_classesObject



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

Yields:

  • (_self)

Yield Parameters:



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”'

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/pickle/config.rb', line 41

def map(*args)
  options = args.extract_options!
  raise ArgumentError, "Usage: map 'search' [, 'search2', ...] :to => 'replace'" unless args.any? && options[:to].is_a?(String)
  args.each do |search|
    self.mappings << Mapping.new(search, options[:to])
  end
end