Module: Schemacop

Defined in:
lib/schemacop.rb,
lib/schemacop/v3.rb,
lib/schemacop/schema.rb,
lib/schemacop/railtie.rb,
lib/schemacop/schema2.rb,
lib/schemacop/schema3.rb,
lib/schemacop/v2/node.rb,
lib/schemacop/v3/node.rb,
lib/schemacop/v3/result.rb,
lib/schemacop/scoped_env.rb,
lib/schemacop/v3/context.rb,
lib/schemacop/base_schema.rb,
lib/schemacop/v3/dsl_scope.rb,
lib/schemacop/v3/hash_node.rb,
lib/schemacop/v3/array_node.rb,
lib/schemacop/v3/all_of_node.rb,
lib/schemacop/v3/any_of_node.rb,
lib/schemacop/v3/is_not_node.rb,
lib/schemacop/v3/number_node.rb,
lib/schemacop/v3/object_node.rb,
lib/schemacop/v3/one_of_node.rb,
lib/schemacop/v3/string_node.rb,
lib/schemacop/v3/symbol_node.rb,
lib/schemacop/v3/boolean_node.rb,
lib/schemacop/v3/integer_node.rb,
lib/schemacop/v3/numeric_node.rb,
lib/schemacop/v3/node_registry.rb,
lib/schemacop/v3/global_context.rb,
lib/schemacop/v3/reference_node.rb,
lib/schemacop/v3/combination_node.rb,
lib/schemacop/v2/validator/hash_validator.rb,
lib/schemacop/v2/validator/array_validator.rb,
lib/schemacop/v2/validator/float_validator.rb,
lib/schemacop/v2/validator/number_validator.rb,
lib/schemacop/v2/validator/object_validator.rb,
lib/schemacop/v2/validator/string_validator.rb,
lib/schemacop/v2/validator/integer_validator.rb

Overview

Schemacop module

Defined Under Namespace

Modules: Exceptions, V2, V3 Classes: BaseSchema, Railtie, Result, Schema, Schema2, Schema3, ScopedEnv

Constant Summary collapse

CONTEXT_THREAD_KEY =
:schemacop_schema_context

Class Method Summary collapse

Class Method Details

.contextObject



107
108
109
# File 'lib/schemacop.rb', line 107

def self.context
  Thread.current[CONTEXT_THREAD_KEY] ||= V3::Context.new
end

.register_string_formatter(name, pattern:, handler:) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/schemacop.rb', line 23

def self.register_string_formatter(name, pattern:, handler:)
  name = name.to_s.dasherize.to_sym

  string_formatters[name] = {
    pattern: pattern,
    handler: handler
  }
end

.with_context(context) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/schemacop.rb', line 99

def self.with_context(context)
  prev_context = Thread.current[CONTEXT_THREAD_KEY]
  Thread.current[CONTEXT_THREAD_KEY] = context
  return yield
ensure
  Thread.current[CONTEXT_THREAD_KEY] = prev_context
end