class Schemas::Fields::NamedFieldFromHash

Public Class Methods

new(name, field) click to toggle source
# File lib/schemas/fields/named_field_from_hash.rb, line 4
def initialize(name, field)
  @name = name
  @field = field
end

Public Instance Methods

errors(input_hash) click to toggle source
# File lib/schemas/fields/named_field_from_hash.rb, line 9
def errors(input_hash)
  input = get_value_from_hash(input_hash)
  errors = @field.errors(input)
  errors.any? ? {@name => errors} : {}
end
parse(input_hash) click to toggle source
# File lib/schemas/fields/named_field_from_hash.rb, line 15
def parse(input_hash)
  input = get_value_from_hash(input_hash)
  {@name => @field.parse(input)}
end

Private Instance Methods

get_value_from_hash(input_hash) click to toggle source
# File lib/schemas/fields/named_field_from_hash.rb, line 22
def get_value_from_hash(input_hash)
  input_hash.fetch(@name, Missing.new)
end