Sha256: d6aa6b6d6a6b011eab799d5174ff46cebdafffe9ba1c9e58da4a2b2bbbf67479

Contents?: true

Size: 814 Bytes

Versions: 4

Compression:

Stored size: 814 Bytes

Contents

require 'sham/util'

module Sham
  module Shammable
    def add_sham_config(name, config)
      @sham_configs ||= {}
      @sham_configs[name] = config
    end

    def sham_config(name)
      if @sham_configs && @sham_configs.has_key?(name)
        @sham_configs[name]
      elsif superclass.respond_to?(:sham_config)
        superclass.sham_config(name)
      end
    end

    def sham!(*args)
      build = extract_build!(args)
      type = extract_type!(args) || :default
      build ||= extract_build!(args)

      sham_config(type).object(self).options(*args).sham(build == :build)
    end

    alias :sham_alternate! :sham!

    private

    def extract_build!(args)
      args.shift if args.first == :build
    end

    def extract_type!(args)
      args.shift if sham_config(args.first)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sham-2.0.0 lib/sham/shammable.rb
sham-1.2.0 lib/sham/shammable.rb
sham-1.1.0 lib/sham/shammable.rb
sham-1.0.3 lib/sham/shammable.rb