Sha256: d0e194e274bb36f3fd05efa1510f5d250b9bc87c37ac81ecc26d49ce84900965

Contents?: true

Size: 906 Bytes

Versions: 6

Compression:

Stored size: 906 Bytes

Contents

module DuckPuncher
  module Ducks
    class << self
      def list
        @list ||= [
          Duck.new(:String),
          Duck.new(:Array),
          Duck.new(:Numeric),
          Duck.new(:Hash),
          Duck.new(:Object),
          Duck.new(:Method, before: ->(*) { DuckPuncher::GemInstaller.initialize! }),
          Duck.new(:ActiveRecord, class: 'ActiveRecord::Base', if: -> { defined? ::ActiveRecord })
        ]
      end

      def [](name)
        list.find { |duck| duck.name == name.to_sym } ||
          DuckPuncher.log.warn(%Q(Couldn't find "#{name}" in my list of Ducks! I know about: #{list.map(&:name).map(&:to_s)}))
      end

      def load_path_for(duck)
        "duck_puncher/ducks/#{duck.name.to_s.gsub(/\B([A-Z])/, '_\1').downcase}"
      end
    end

    #
    # Autoload our ducks
    #

    list.each do |duck|
      autoload duck.name, load_path_for(duck)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
duck_puncher-2.15.0 lib/duck_puncher/ducks.rb
duck_puncher-2.14.1 lib/duck_puncher/ducks.rb
duck_puncher-2.14.0 lib/duck_puncher/ducks.rb
duck_puncher-2.13.0 lib/duck_puncher/ducks.rb
duck_puncher-2.12.1 lib/duck_puncher/ducks.rb
duck_puncher-2.12.0 lib/duck_puncher/ducks.rb