Sha256: 507c9de611c689f22806b8fa1e7d1efde068b30997348c30e9e6dc3985cfdc13

Contents?: true

Size: 1.28 KB

Versions: 26

Compression:

Stored size: 1.28 KB

Contents

require 'ostruct'

module Pickle
  class Config
    attr_writer :adapters, :factories, :mappings, :predicates
    
    def initialize(&block)
      configure(&block) if block_given?
    end
    
    def configure(&block)
      yield(self)
    end
    
    def adapters
      @adapters ||= [:machinist, :factory_girl, :active_record]
    end
    
    def adapter_classes
      adapters.map {|a| a.is_a?(Class) ? a : "pickle/adapter/#{a}".classify.constantize}
    end
    
    def factories
      @factories ||= adapter_classes.reverse.inject({}) do |factories, adapter|
        factories.merge(adapter.factories.inject({}){|h, f| h.merge(f.name => f)})
      end
    end
    
    def predicates
      @predicates ||= Pickle::Adapter.model_classes.map do |k|
        k.public_instance_methods.select{|m| m =~ /\?$/} + k.column_names
      end.flatten.uniq
    end
    
    def mappings
      @mappings ||= []
    end
    
    # Usage: map 'me', 'myself', 'I', :to => 'user: "me"'
    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 << OpenStruct.new(:search => search, :replacement => options[:to])
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
ianwhite-pickle-0.1.15 lib/pickle/config.rb
pickle-0.2.12 lib/pickle/config.rb
pickle-0.2.11 lib/pickle/config.rb
pickle-0.2.10 lib/pickle/config.rb
pickle-0.2.9 lib/pickle/config.rb
pickle-0.2.8 lib/pickle/config.rb
pickle-0.2.7 lib/pickle/config.rb
pickle-0.2.6 lib/pickle/config.rb
pickle-0.2.5 lib/pickle/config.rb
pickle-0.2.4 lib/pickle/config.rb
pickle-0.2.3 lib/pickle/config.rb
pickle-0.2.2 lib/pickle/config.rb
kbaum-pickle-0.2.1.4 lib/pickle/config.rb
kbaum-pickle-0.2.1.3 lib/pickle/config.rb
kbaum-pickle-0.2.1.2 lib/pickle/config.rb
kbaum-pickle-0.2.1.1 lib/pickle/config.rb
pickle-0.2.1 lib/pickle/config.rb
pickle-0.2.0 lib/pickle/config.rb
pickle-0.1.23 lib/pickle/config.rb
pickle-0.1.22 lib/pickle/config.rb