Class: Mortymer::StructCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/mortymer/struct_compiler.rb

Constant Summary collapse

PRIMITIVE_TYPE_MAP =
{
  "string" => Mortymer::Model::String,
  "integer" => Mortymer::Model::Integer,
  "number" => Mortymer::Model::Float,
  "boolean" => Mortymer::Model::Bool,
  "null" => Mortymer::Model::Nil,
  string: Mortymer::Model::String,
  integer: Mortymer::Model::Integer,
  number: Mortymer::Model::Float,
  boolean: Mortymer::Model::Bool,
  null: Mortymer::Model::Nil
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(class_name = "GeneratedStruct#{SecureRandom.hex(4)}") ⇒ StructCompiler

Returns a new instance of StructCompiler.



21
22
23
24
# File 'lib/mortymer/struct_compiler.rb', line 21

def initialize(class_name = "GeneratedStruct#{SecureRandom.hex(4)}")
  @class_name = class_name
  @types = {}
end

Instance Method Details

#compile(schema) ⇒ Object



26
27
28
# File 'lib/mortymer/struct_compiler.rb', line 26

def compile(schema)
  build_type(schema, @class_name)
end