Sha256: 67f313830a829761206cf5b96d805f41a6a0fb11027704480610b6c9449a6a33

Contents?: true

Size: 1.28 KB

Versions: 13

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, :replace => options[:to])
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
ianwhite-pickle-0.1.10 lib/pickle/config.rb
ianwhite-pickle-0.1.11 lib/pickle/config.rb
ianwhite-pickle-0.1.12 lib/pickle/config.rb
ianwhite-pickle-0.1.13 lib/pickle/config.rb
ianwhite-pickle-0.1.14 lib/pickle/config.rb
ianwhite-pickle-0.1.6 lib/pickle/config.rb
ianwhite-pickle-0.1.8 lib/pickle/config.rb
ianwhite-pickle-0.1.9 lib/pickle/config.rb
mrflip-pickle-0.1.13 lib/pickle/config.rb
schlick-pickle-0.1.5.1 lib/pickle/config.rb
schlick-pickle-0.1.5.2 lib/pickle/config.rb
schlick-pickle-0.1.5.3 lib/pickle/config.rb
schlick-schlick-pickle-0.1.5.1 lib/pickle/config.rb