Class: GoaModelGen::GoStructFieldType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(d) ⇒ GoStructFieldType

Returns a new instance of GoStructFieldType.



35
36
37
38
39
40
# File 'lib/goa_model_gen/go_struct.rb', line 35

def initialize(d)
  @name = d['Name']
  @kinds = d['Kinds']
  @pkg_path = d['PkgPath']
  @representation = d['Representation']
end

Instance Attribute Details

#kindsObject (readonly)

Returns the value of attribute kinds.



34
35
36
# File 'lib/goa_model_gen/go_struct.rb', line 34

def kinds
  @kinds
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/goa_model_gen/go_struct.rb', line 34

def name
  @name
end

#pkg_pathObject (readonly)

Returns the value of attribute pkg_path.



34
35
36
# File 'lib/goa_model_gen/go_struct.rb', line 34

def pkg_path
  @pkg_path
end

#representationObject (readonly)

Returns the value of attribute representation.



34
35
36
# File 'lib/goa_model_gen/go_struct.rb', line 34

def representation
  @representation
end

Instance Method Details

#==(other) ⇒ Object Also known as: assignable_with?



42
43
44
45
46
47
# File 'lib/goa_model_gen/go_struct.rb', line 42

def ==(other)
  (pkg_path == other.pkg_path) &&
    (name == other.name) &&
    (kinds == other.kinds) &&
    (representation == other.representation)
end

#defined_in_model?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/goa_model_gen/go_struct.rb', line 77

def defined_in_model?
  pkg_path =~ /\/model\z/
end

#method_part_nameObject



68
69
70
71
72
73
74
75
# File 'lib/goa_model_gen/go_struct.rb', line 68

def method_part_name
  parts = kinds.dup
  parts.pop if parts.last == 'ptr'
  parts =
    (parts.first == 'struct' || pkg_path.present?) ?
      [name] + parts[1..-1] : parts
  parts.map(&:camelize).join
end

#needs_error_to_convert_to?(other) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/goa_model_gen/go_struct.rb', line 62

def needs_error_to_convert_to?(other)
  return false if other.name == 'string'
  return true if name == 'string'
  return false
end

#pointee_of?(other) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/goa_model_gen/go_struct.rb', line 58

def pointee_of?(other)
  other.pointer_of?(self)
end

#pointer?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/goa_model_gen/go_struct.rb', line 50

def pointer?
  kinds.last == 'ptr'
end

#pointer_of?(other) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/goa_model_gen/go_struct.rb', line 53

def pointer_of?(other)
  (pkg_path == other.pkg_path) &&
    (name == other.name) &&
    (kinds == (other.kinds + ['ptr']))
end