Class: Uinit::Structure::Compilers::AsJson

Inherits:
Base
  • Object
show all
Defined in:
lib/uinit/structure/compilers/as_json.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#mod

Instance Method Summary collapse

Methods inherited from Base

compile, #compile_method

Constructor Details

#initialize(mod, schema) ⇒ AsJson

Returns a new instance of AsJson.



7
8
9
10
11
12
# File 'lib/uinit/structure/compilers/as_json.rb', line 7

def initialize(mod, schema)
  super(mod)

  @schema = schema
  @attributes = schema.class.instance_methods(false).map { schema.send(_1) }
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



14
15
16
# File 'lib/uinit/structure/compilers/as_json.rb', line 14

def attributes
  @attributes
end

#schemaObject (readonly)

Returns the value of attribute schema.



14
15
16
# File 'lib/uinit/structure/compilers/as_json.rb', line 14

def schema
  @schema
end

Instance Method Details

#compileObject



16
17
18
19
20
21
22
23
24
# File 'lib/uinit/structure/compilers/as_json.rb', line 16

def compile
  compile_method(<<~RUBY, __FILE__, __LINE__ + 1)
    def as_json
      #{compile_super}
      #{compile_json_attributes * "\n"}
      json
    end
  RUBY
end