Sha256: 325de33d1553d8b8c87b30997e30261b31361d7ad8e8d5ac1b65b5d848f50031

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require 'librarian/specfile'

module Librarian
  class Dsl
    class Receiver

      def initialize(target)
        singleton_class = class << self; self end
        singleton_class.class_eval do
          define_method(target.dependency_name) do |*args, &block|
            target.dependency(*args, &block)
          end
          define_method(:source) do |*args, &block|
            target.source(*args, &block)
          end
          target.source_types.each do |source_type|
            name = source_type[0]
            define_method(name) do |*args, &block|
              target.source(name, *args, &block)
            end
          end
        end
      end

      def run(specfile = nil)
        specfile = Proc.new if block_given?

        case specfile
        when Specfile
          eval(specfile.path.read, instance_binding, specfile.path.to_s, 1)
        when String
          eval(specfile, instance_binding)
        when Proc
          instance_eval(&specfile)
        else
          raise ArgumentError, "specfile must be a #{Specfile}, #{String}, or #{Proc} if no block is given (it was #{specfile.inspect})"
        end
      end

      def instance_binding
        binding
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
librarian-0.1.0.beta.1 lib/librarian/dsl/receiver.rb
librarian-puppet-lmco-0.9.8.2 vendor/librarian/lib/librarian/dsl/receiver.rb
librarian-0.0.26 lib/librarian/dsl/receiver.rb
librarian-0.0.25 lib/librarian/dsl/receiver.rb