Class: Divine::StructHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/divine/code_generators/code_generator.rb

Overview

Support methods that help to get fields and fields type from structs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(structs) ⇒ StructHandler

Returns a new instance of StructHandler.



17
18
19
20
21
22
# File 'lib/divine/code_generators/code_generator.rb', line 17

def initialize(structs)
  @structs = structs
  @name = structs.first.name
  @latest_version = structs.last.version
  @field_hash = structs.map(&:fields).flatten.group_by(&:name)
end

Instance Attribute Details

#latest_versionObject (readonly)

name = name of struct latest_version = struct version structs = defined struct



15
16
17
# File 'lib/divine/code_generators/code_generator.rb', line 15

def latest_version
  @latest_version
end

#nameObject (readonly)

name = name of struct latest_version = struct version structs = defined struct



15
16
17
# File 'lib/divine/code_generators/code_generator.rb', line 15

def name
  @name
end

#structsObject (readonly)

name = name of struct latest_version = struct version structs = defined struct



15
16
17
# File 'lib/divine/code_generators/code_generator.rb', line 15

def structs
  @structs
end

Instance Method Details

#field(name) ⇒ Object

Get field of given name

  • Args :

  • name -> field’s name



28
29
30
# File 'lib/divine/code_generators/code_generator.rb', line 28

def field(name)
  @field_hash[name]
end

#field_namesObject

Get all fields names



35
36
37
# File 'lib/divine/code_generators/code_generator.rb', line 35

def field_names
  @field_hash.keys.sort
end