Sha256: 15bd1ffa69acb6cf853199a5453e00b01f5e0654d8144045057eab163c6ae59b

Contents?: true

Size: 944 Bytes

Versions: 4

Compression:

Stored size: 944 Bytes

Contents

module Aquarium
  module Aspects
    # Some classes and modules support a :default_object flag and use it if no type or
    # object is specified. For "convenience", requires that classes and modules including
    # this module have a hash @specification defined with keys :default_object, :types,
    # and :objects.
    module DefaultObjectHandler
      def default_object_given
        @specification[:default_object]
      end

      def default_object_given?
        not (default_object_given.nil? or default_object_given.empty?)
      end
      
      def use_default_object_if_defined
        return unless default_object_given?
        object = default_object_given.to_a.first  # there will be only one...
        if (object.kind_of?(Class) || object.kind_of?(Module))
          @specification[:types] = default_object_given
        else
          @specification[:objects] = default_object_given
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aquarium-0.1.6 lib/aquarium/aspects/default_object_handler.rb
aquarium-0.1.0 lib/aquarium/aspects/default_object_handler.rb
aquarium-0.1.5 lib/aquarium/aspects/default_object_handler.rb
aquarium-0.1.7 lib/aquarium/aspects/default_object_handler.rb