Sha256: 04526478062b4f0e9e2fd4459513996f8365d05e9f3ae42481b8d781018adca1

Contents?: true

Size: 749 Bytes

Versions: 18

Compression:

Stored size: 749 Bytes

Contents

module Schemacop
  module V3
    # @abstract
    class CombinationNode < Node
      def self.dsl_methods
        super + NodeRegistry.dsl_methods(false)
      end

      supports_children

      def init
        @items = []
      end

      def as_json
        process_json([], type => @items.map(&:as_json))
      end

      def cast(value)
        item = match(value)
        return value unless item

        return item.cast(value)
      end

      def add_child(node)
        @items << node
      end

      protected

      def type
        fail NotImplementedError
      end

      def match(data)
        matches(data).first
      end

      def matches(data)
        @items.filter { |i| item_matches?(i, data) }
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
schemacop-3.0.11 lib/schemacop/v3/combination_node.rb
schemacop-3.0.10 lib/schemacop/v3/combination_node.rb
schemacop-3.0.9 lib/schemacop/v3/combination_node.rb
schemacop-3.0.8 lib/schemacop/v3/combination_node.rb
schemacop-3.0.7 lib/schemacop/v3/combination_node.rb
schemacop-3.0.6 lib/schemacop/v3/combination_node.rb
schemacop-3.0.5 lib/schemacop/v3/combination_node.rb
schemacop-3.0.4 lib/schemacop/v3/combination_node.rb
schemacop-3.0.3 lib/schemacop/v3/combination_node.rb
schemacop-3.0.2 lib/schemacop/v3/combination_node.rb
schemacop-3.0.1 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0.rc5 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0.rc4 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0.rc3 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0.rc2 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0.rc1 lib/schemacop/v3/combination_node.rb
schemacop-3.0.0.rc0 lib/schemacop/v3/combination_node.rb