Module: JsonSchematize::Introspect

Included in:
Generator
Defined in:
lib/json_schematize/introspect.rb

Instance Method Summary collapse

Instance Method Details

#deep_inspect(with_raw_params: false, with_field: false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/json_schematize/introspect.rb', line 11

def deep_inspect(with_raw_params: false, with_field: false)
  self.class.fields.map do |field|
    value = {
      required: field.required,
      acceptable_types: field.acceptable_types,
      value: instance_variable_get(:"@#{field.name}"),
    }
    value[:field] = field if with_field
    value[:raw_params] = @__raw_params if with_raw_params
    [field.name, value]
  end.to_h
end

#inspectObject



24
25
26
27
# File 'lib/json_schematize/introspect.rb', line 24

def inspect
  stringify = to_h.map { |k, v| "#{k}:#{v}" }.join(", ")
  "#<#{self.class} - required fields: #{self.class.required_fields.map(&:name)}; #{stringify}>"
end

#to_hObject Also known as: to_hash



4
5
6
7
8
# File 'lib/json_schematize/introspect.rb', line 4

def to_h
  self.class.fields.map do |field|
    [field.name, instance_variable_get(:"@#{field.name}")]
  end.to_h
end