Class: GoonModelGen::Source::File

Inherits:
Object
  • Object
show all
Includes:
Contextual
Defined in:
lib/goon_model_gen/source/file.rb

Instance Attribute Summary collapse

Attributes included from Contextual

#context

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ File

Returns a new instance of File.

Parameters:

  • path (string)


17
18
19
20
# File 'lib/goon_model_gen/source/file.rb', line 17

def initialize(path)
  @path = path
  @types = []
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/goon_model_gen/source/file.rb', line 13

def path
  @path
end

#typesObject (readonly)

Returns the value of attribute types.



14
15
16
# File 'lib/goon_model_gen/source/file.rb', line 14

def types
  @types
end

Instance Method Details

#basenameObject



22
23
24
# File 'lib/goon_model_gen/source/file.rb', line 22

def basename
  ::File.basename(path, '.*')
end

#new_enum(name, base_type, elements) ⇒ Enum

Parameters:

  • name (string)
  • base_type (String)
  • elements (Hash<Object,Hash>)

    elements of enum from YAML

Returns:



40
41
42
43
44
45
# File 'lib/goon_model_gen/source/file.rb', line 40

def new_enum(name, base_type, elements)
  Enum.new(name, base_type, elements).tap do |t|
    t.context = self.context
    types.push(t)
  end
end

#new_named_slice(name, base_type_name) ⇒ Slice

Parameters:

  • name (string)
  • base_type_name (string)

Returns:

  • (Slice)


50
51
52
53
54
55
# File 'lib/goon_model_gen/source/file.rb', line 50

def new_named_slice(name, base_type_name)
  NamedSlice.new(name, base_type_name).tap do |s|
    s.context = self.context
    types.push(s)
  end
end

#new_struct(name) ⇒ Struct

Parameters:

  • name (string)

Returns:



28
29
30
31
32
33
34
# File 'lib/goon_model_gen/source/file.rb', line 28

def new_struct(name)
  Struct.new(name).tap do |s|
    s.context = self.context
    s.file = self
    types.push(s)
  end
end