Sha256: ed3cf4b72a1f7cd1c1a27bb0cd251a4a0b5d19a6c965965e91d9db7e6bce0c0c

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 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)
        if block_given?
          instance_eval(&Proc.new)
        else
          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)
          end
        end
      end

      def instance_binding
        binding
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
librarian-0.0.9 lib/librarian/dsl/receiver.rb
librarian-0.0.8 lib/librarian/dsl/receiver.rb
librarian-0.0.7 lib/librarian/dsl/receiver.rb
librarian-0.0.6 lib/librarian/dsl/receiver.rb
librarian-0.0.5 lib/librarian/dsl/receiver.rb
librarian-0.0.4 lib/librarian/dsl/receiver.rb
librarian-0.0.3 lib/librarian/dsl/receiver.rb
librarian-0.0.2 lib/librarian/dsl/receiver.rb
librarian-0.0.1 lib/librarian/dsl/receiver.rb