Sha256: da4a388646a8f605b1c3e84263ab51a2d8747d70722c699c8b5be237063a7833

Contents?: true

Size: 997 Bytes

Versions: 3

Compression:

Stored size: 997 Bytes

Contents

# encoding: UTF-8

module Watchmaker
  module Learner
    extend ActiveSupport::Concern

    module ClassMethods

      # Learn a profile by taking explicit dependencies.
      #
      def define(name, dependencies = {}, &block)

        if name.is_a?(Hash)
          
          # Convert the hash into a profile name and a list of
          # dependencies that's either a hash of nested classes or
          # array.
          #
          name, dependencies = 
            name_and_dependencies_from_dependency_hash(name) 

          # Specifically store these as abstract dependencies.
          #
          dependencies = { :abstract => dependencies }

        end

        Configuration.learn(name, dependencies, &block)
      end

      alias :learn :define

      # Get the profile name out of a dependency hash.
      #
      def name_and_dependencies_from_dependency_hash(dependencies)
        name = dependencies.keys.first
        [name, dependencies[name]]
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
watchmaker-0.2.2 lib/watchmaker/learner.rb
watchmaker-0.2.1 lib/watchmaker/learner.rb
watchmaker-0.2.0 lib/watchmaker/learner.rb