Class: PairKit::JsonSchema::Dsl::HashScaffold

Inherits:
Scaffold
  • Object
show all
Defined in:
lib/pair_kit/json_schema/dsl/scaffolds/hash_scaffold.rb

Instance Method Summary collapse

Methods inherited from Scaffold

wrap

Constructor Details

#initialize(val) ⇒ HashScaffold

Returns a new instance of HashScaffold.



5
6
7
# File 'lib/pair_kit/json_schema/dsl/scaffolds/hash_scaffold.rb', line 5

def initialize(val)
  @hash = val
end

Instance Method Details

#[](name, default = nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/pair_kit/json_schema/dsl/scaffolds/hash_scaffold.rb', line 9

def [](name, default = nil)
  name = Miniflector.camel_case(name)
  return @hash[name] if @hash.key?(name)

  @hash[name] = Scaffold.wrap(default)
end

#[]=(name, val) ⇒ Object



16
17
18
19
# File 'lib/pair_kit/json_schema/dsl/scaffolds/hash_scaffold.rb', line 16

def []=(name, val)
  name = Miniflector.camel_case(name)
  @hash[name] = Scaffold.wrap(val)
end

#to_schemaObject



21
22
23
# File 'lib/pair_kit/json_schema/dsl/scaffolds/hash_scaffold.rb', line 21

def to_schema
  @hash.transform_values(&:to_schema)
end