Sha256: 6f5b8d10f157057bae9bc6d86f1688d40a24ee8d93224b4e80ab940e02bd8b80

Contents?: true

Size: 713 Bytes

Versions: 14

Compression:

Stored size: 713 Bytes

Contents

module Parametric
  class Top
    attr_reader :errors

    def initialize
      @errors = {}
    end

    def add_error(key, msg)
      errors[key] ||= []
      errors[key] << msg
    end
  end

  class Context
    def initialize(path = nil, top = Top.new)
      @top = top
      @path = Array(path).compact
    end

    def errors
      top.errors
    end

    def add_error(msg)
      top.add_error(string_path, msg)
    end

    def sub(key)
      self.class.new(path + [key], top)
    end

    protected
    attr_reader :path, :top

    def string_path
      path.reduce(['$']) do |m, segment|
        m << (segment.is_a?(Integer) ? "[#{segment}]" : ".#{segment}")
        m
      end.join
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
parametric-0.2.10 lib/parametric/context.rb
parametric-0.2.9 lib/parametric/context.rb
parametric-0.2.8 lib/parametric/context.rb
parametric-0.2.7 lib/parametric/context.rb
parametric-0.2.6 lib/parametric/context.rb
parametric-0.2.5 lib/parametric/context.rb
parametric-0.2.4 lib/parametric/context.rb
parametric-0.2.3 lib/parametric/context.rb
parametric-0.2.2 lib/parametric/context.rb
parametric-0.2.1 lib/parametric/context.rb
parametric-0.2.0 lib/parametric/context.rb
parametric-0.1.3 lib/parametric/context.rb
parametric-0.1.2 lib/parametric/context.rb
parametric-0.1.1 lib/parametric/context.rb