Sha256: e42933de99efed49697d5851cf90c586e735177ed977196185655ece33b32f66

Contents?: true

Size: 749 Bytes

Versions: 8

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.select { |i| item_matches?(i, data) }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
schemacop-3.0.19 lib/schemacop/v3/combination_node.rb
schemacop-3.0.18 lib/schemacop/v3/combination_node.rb
schemacop-3.0.17 lib/schemacop/v3/combination_node.rb
schemacop-3.0.16 lib/schemacop/v3/combination_node.rb
schemacop-3.0.15 lib/schemacop/v3/combination_node.rb
schemacop-3.0.14 lib/schemacop/v3/combination_node.rb
schemacop-3.0.13 lib/schemacop/v3/combination_node.rb
schemacop-3.0.12 lib/schemacop/v3/combination_node.rb