Class: PairKit::JsonSchema::Dsl::ArrayScaffold

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

Instance Method Summary collapse

Methods inherited from Scaffold

wrap

Constructor Details

#initialize(val) ⇒ ArrayScaffold

Returns a new instance of ArrayScaffold.



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

def initialize(val)
  @array = val.is_a?(ArrayScaffold) ? val.array : val.map { |x| Scaffold.wrap(x) }
end

Instance Method Details

#+(arr) ⇒ Object



26
27
28
29
30
# File 'lib/pair_kit/json_schema/dsl/scaffolds/array_scaffold.rb', line 26

def +(arr)
  ArrayScaffold.new([]).tap do |scf|
    scf.array = array +  ArrayScaffold.new(arr).array
  end
end

#<<(item) ⇒ Object



10
11
12
# File 'lib/pair_kit/json_schema/dsl/scaffolds/array_scaffold.rb', line 10

def <<(item)
  @array << Scaffold.wrap(item)
end

#firstObject



18
19
20
# File 'lib/pair_kit/json_schema/dsl/scaffolds/array_scaffold.rb', line 18

def first
  @array.first
end

#lastObject



22
23
24
# File 'lib/pair_kit/json_schema/dsl/scaffolds/array_scaffold.rb', line 22

def last
  @array.last
end

#to_schemaObject



14
15
16
# File 'lib/pair_kit/json_schema/dsl/scaffolds/array_scaffold.rb', line 14

def to_schema
  @array.map(&:to_schema)
end