Class: GoonModelGen::Golang::NamedSlice

Inherits:
Type
  • Object
show all
Defined in:
lib/goon_model_gen/golang/named_slice.rb

Instance Attribute Summary collapse

Attributes inherited from Type

#name, #package

Instance Method Summary collapse

Methods inherited from Type

#memo, #qualified_name

Constructor Details

#initialize(name, base_type_name, base_type_package_path = nil) ⇒ NamedSlice

Returns a new instance of NamedSlice.

Parameters:

  • name (String)
  • base_type_name (String)
  • base_type_package_path (String) (defaults to: nil)


15
16
17
18
19
# File 'lib/goon_model_gen/golang/named_slice.rb', line 15

def initialize(name, base_type_name, base_type_package_path = nil)
  super(name)
  @base_type_name = base_type_name
  @base_type_package_path = base_type_package_path
end

Instance Attribute Details

#base_typeObject (readonly)

Returns the value of attribute base_type.



10
11
12
# File 'lib/goon_model_gen/golang/named_slice.rb', line 10

def base_type
  @base_type
end

#base_type_nameObject (readonly)

Returns the value of attribute base_type_name.



8
9
10
# File 'lib/goon_model_gen/golang/named_slice.rb', line 8

def base_type_name
  @base_type_name
end

#base_type_package_pathObject (readonly)

Returns the value of attribute base_type_package_path.



9
10
11
# File 'lib/goon_model_gen/golang/named_slice.rb', line 9

def base_type_package_path
  @base_type_package_path
end

Instance Method Details

#ptr_slice?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/goon_model_gen/golang/named_slice.rb', line 29

def ptr_slice?
  base_type.is_a?(GoonModelGen::Golang::Modifier) && (base_type.prefix == '*')
end

#resolve(pkgs) ⇒ Object

Parameters:



22
23
24
25
26
27
# File 'lib/goon_model_gen/golang/named_slice.rb', line 22

def resolve(pkgs)
  @base_type =
    base_type_package_path.present? ?
      pkgs.type_for(base_type_name, base_type_package_path) :
      pkgs.type_for(base_type_name) || raise("#{base_type_name.inspect} not found")
end