Module: OneSignal::CapnProto::SchemaLoader

Defined in:
lib/one_signal/capn_proto.rb

Defined Under Namespace

Modules: Struct

Instance Method Summary collapse

Instance Method Details

#load_schema(file_name, imports = []) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/one_signal/capn_proto.rb', line 72

def load_schema(file_name, imports=[])
  display_name = self.name

  @schema_parser ||= CapnProto::SchemaParser.new

  load_schema_rec = Proc.new do |schema, mod|
    node = schema.get_proto
    nested_nodes = node.nested_nodes

    if node.struct?
      struct_schema = schema.as_struct
      mod.instance_variable_set(:@schema, struct_schema)
      mod.extend(Struct)
    end

    nested_nodes.each do |nested_node|
      const_name = nested_node.name
      const_name[0] = const_name[0].upcase
      nested_mod = mod.const_set(const_name, Module.new)
      nested_schema = schema.get_nested(nested_node.name)
      load_schema_rec.call(nested_schema, nested_mod)
    end
  end

  schema = @schema_parser.parse_disk_file(
    display_name,
    file_name,
    imports);

  load_schema_rec.call(schema, self)
end

#schema_parserObject



68
69
70
# File 'lib/one_signal/capn_proto.rb', line 68

def schema_parser
  @schema_parser
end