Class: SexyJSONSchemas::Properties::Object

Inherits:
Base
  • Object
show all
Defined in:
lib/sexy_json_schemas/properties/object.rb

Direct Known Subclasses

AnonymousObject

Instance Attribute Summary

Attributes inherited from Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Object

Returns a new instance of Object.



23
24
25
26
27
# File 'lib/sexy_json_schemas/properties/object.rb', line 23

def initialize(name, options = {}, &block)
  super(name, options)
  @properties = []
  instance_eval(&block) if block_given?
end

Class Method Details

.property_methodsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sexy_json_schemas/properties/object.rb', line 8

def self.property_methods
  [
    :integer_property,
    :string_property,
    :object_property,
    :number_property,
    :boolean_property,
    :null_property,
    :any_property,
    :union_property,
    :array_property,
    :ref_property
  ]
end

Instance Method Details

#any_property(*args, &block) ⇒ Object



62
63
64
# File 'lib/sexy_json_schemas/properties/object.rb', line 62

def any_property(*args, &block)
  @properties << Properties::Any.new(*args, &block)
end

#array_property(*args, &block) ⇒ Object



70
71
72
# File 'lib/sexy_json_schemas/properties/object.rb', line 70

def array_property(*args, &block)
  @properties << Properties::Array.new(*args, &block)
end

#as_jsonObject



29
30
31
32
33
# File 'lib/sexy_json_schemas/properties/object.rb', line 29

def as_json
  super.tap do |json|
    json["properties"] = properties
  end
end

#boolean_property(*args, &block) ⇒ Object



50
51
52
# File 'lib/sexy_json_schemas/properties/object.rb', line 50

def boolean_property(*args, &block)
  @properties << Properties::Boolean.new(*args, &block)
end

#integer_property(*args, &block) ⇒ Object



42
43
44
# File 'lib/sexy_json_schemas/properties/object.rb', line 42

def integer_property(*args, &block)
  @properties << Properties::Integer.new(*args, &block)
end

#null_property(*args, &block) ⇒ Object



54
55
56
# File 'lib/sexy_json_schemas/properties/object.rb', line 54

def null_property(*args, &block)
  @properties << Properties::Null.new(*args, &block)
end

#number_property(*args, &block) ⇒ Object



46
47
48
# File 'lib/sexy_json_schemas/properties/object.rb', line 46

def number_property(*args, &block)
  @properties << Properties::Number.new(*args, &block)
end

#object_property(*args, &block) ⇒ Object



78
79
80
# File 'lib/sexy_json_schemas/properties/object.rb', line 78

def object_property(*args, &block)
  @properties << Properties::Object.new(*args, &block)
end

#propertiesObject



35
36
37
38
39
40
# File 'lib/sexy_json_schemas/properties/object.rb', line 35

def properties
  @properties.inject({}) do |acc, property|
    acc[property.name] = property.as_json
    acc
  end
end

#ref_property(*args, &block) ⇒ Object



74
75
76
# File 'lib/sexy_json_schemas/properties/object.rb', line 74

def ref_property(*args, &block)
  @properties << Properties::Ref.new(*args, &block)
end

#string_property(*args, &block) ⇒ Object



58
59
60
# File 'lib/sexy_json_schemas/properties/object.rb', line 58

def string_property(*args, &block)
  @properties << Properties::String.new(*args, &block)
end

#typeObject



4
5
6
# File 'lib/sexy_json_schemas/properties/object.rb', line 4

def type
  "object"
end

#union_property(*args, &block) ⇒ Object



66
67
68
# File 'lib/sexy_json_schemas/properties/object.rb', line 66

def union_property(*args, &block)
  @properties << Properties::Union.new(*args, &block)
end