Class: GoaModelGen::BaseLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/goa_model_gen/loader.rb

Direct Known Subclasses

ModelLoader, SwaggerLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, kind, types_key, fields_key) ⇒ BaseLoader

Returns a new instance of BaseLoader.



14
15
16
17
18
19
# File 'lib/goa_model_gen/loader.rb', line 14

def initialize(path, kind, types_key, fields_key)
  @path = path
  @kind = kind
  @types_key, @fields_key = types_key, fields_key
  @raw = YAML.load_file(path)
end

Instance Attribute Details

#fields_keyObject (readonly)

Returns the value of attribute fields_key.



13
14
15
# File 'lib/goa_model_gen/loader.rb', line 13

def fields_key
  @fields_key
end

#kindObject (readonly)

Returns the value of attribute kind.



13
14
15
# File 'lib/goa_model_gen/loader.rb', line 13

def kind
  @kind
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/goa_model_gen/loader.rb', line 12

def path
  @path
end

#rawObject (readonly)

Returns the value of attribute raw.



12
13
14
# File 'lib/goa_model_gen/loader.rb', line 12

def raw
  @raw
end

#types_keyObject (readonly)

Returns the value of attribute types_key.



13
14
15
# File 'lib/goa_model_gen/loader.rb', line 13

def types_key
  @types_key
end

Instance Method Details

#build_field(name, f) ⇒ Object



31
32
33
# File 'lib/goa_model_gen/loader.rb', line 31

def build_field(name, f)
  Field.new(name, f)
end

#build_type(name, d) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/goa_model_gen/loader.rb', line 21

def build_type(name, d)
  kind.new(name, d).tap do |t|
    if d[fields_key]
      d[fields_key].each do |fname, f|
        t.fields << build_field(fname, f)
      end
    end
  end
end