Class: Lacerda::Conversion::DataStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/lacerda/conversion/data_structure.rb,
lib/lacerda/conversion/data_structure/member.rb,
lib/lacerda/conversion/data_structure/member/type.rb

Defined Under Namespace

Classes: Member

Constant Summary collapse

PRIMITIVES =
%w{boolean string number array enum object}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data, scope = nil) ⇒ DataStructure

Returns a new instance of DataStructure.



32
33
34
35
36
37
38
39
40
# File 'lib/lacerda/conversion/data_structure.rb', line 32

def initialize(id, data, scope = nil)
  @scope = scope
  @data = data
  @id = self.class.scope(@scope, id)
  @schema = json_schema_blueprint
  @schema['title'] = @id
  add_description_to_json_schema
  add_properties_to_json_schema
end

Class Method Details

.scope(scope, string) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lacerda/conversion/data_structure.rb', line 6

def self.scope(scope, string)
  # This allows users to enter either
  #
  #     # Message
  #     - id (number, required)
  #     - ...
  #
  # or
  #
  #     # MessageService::Message
  #     - id (number, required)
  #     - ...
  #
  # in their publish.mson specification files. Including the service name in
  # a publish specification is redundant and not necessary, but let's let our
  # friendly users do this if they wish.
  #
  scope = nil if Lacerda.underscore(string.to_s).start_with?(Lacerda.underscore(scope.to_s))

  # Now that this is out of the way, let's put a
  # scope in front and return the string.
  Lacerda.underscore(
    [scope, string.to_s].compact.join(Lacerda::SCOPE_SEPARATOR)
  )
end

Instance Method Details

#to_jsonObject



42
43
44
# File 'lib/lacerda/conversion/data_structure.rb', line 42

def to_json
  @schema
end