Sha256: b72e626c50e6cfd85acd518253f3e3b58a03c50412667b09c6ae0e22310c7e5e

Contents?: true

Size: 1.24 KB

Versions: 15

Compression:

Stored size: 1.24 KB

Contents

#coding: utf-8

module Wombat
  module DSL
    class PropertyGroup < Hash
      attr_accessor :wombat_property_name

      def initialize(name = nil)
        @wombat_property_name = name
      end

      def method_missing(method, *args, &block)
        property_name = method.to_s

        if args.empty? && block
          # TODO: Verify if another property with same name already exists
          # before overwriting
          property_group = self[property_name] || PropertyGroup.new(property_name)
          self[property_name] = property_group
          property_group.instance_eval(&block)
        else
          it = build_property(property_name, *args, &block)
          self[property_name] = it
          it.instance_eval(&block) if block_given? && !it.instance_of?(Property)
        end
      end

      def to_ary
      end

      def wombat_property_format
        :container
      end

      def wombat_property_namespaces
        nil
      end

      protected

      def build_property(name, *args, &block)
        if args[1] == :iterator
          Iterator.new(name, args.first)
        elsif args[1] == :follow
          Follower.new(name, args.first)
        else
          Property.new(name, *args, &block)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
wombat-3.0.0 lib/wombat/dsl/property_group.rb
wombat-2.10.0 lib/wombat/dsl/property_group.rb
wombat-2.9.0 lib/wombat/dsl/property_group.rb
wombat-2.8.0 lib/wombat/dsl/property_group.rb
wombat-2.7.0 lib/wombat/dsl/property_group.rb
wombat-2.6.0 lib/wombat/dsl/property_group.rb
wombat-2.5.1 lib/wombat/dsl/property_group.rb
wombat-2.5.0 lib/wombat/dsl/property_group.rb
wombat-2.4.0 lib/wombat/dsl/property_group.rb
wombat-2.3.0 lib/wombat/dsl/property_group.rb
wombat-2.2.1 lib/wombat/dsl/property_group.rb
wombat-2.2.0 lib/wombat/dsl/property_group.rb
wombat-2.1.3 lib/wombat/dsl/property_group.rb
wombat-2.1.2 lib/wombat/dsl/property_group.rb
wombat-2.1.1 lib/wombat/dsl/property_group.rb