Class: Parlour::RbiGenerator::StructProp

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/parlour/rbi_generator/struct_prop.rb

Overview

Represents a T::Struct property.

Constant Summary collapse

EXTRA_PROPERTIES =

The optional properties available on instances of this class.

i{
  optional enum dont_store foreign default factory immutable array override redaction
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, optional: nil, enum: nil, dont_store: nil, foreign: nil, default: nil, factory: nil, immutable: nil, array: nil, override: nil, redaction: nil) ⇒ void

Create a new struct property.

For documentation on all optional properties, please refer to the documentation for T::Struct within the sorbet-runtime gem: github.com/sorbet/sorbet/blob/master/gems/sorbet-runtime/lib/types/props/_props.rb#L31-L106

Parameters:

  • name (String)

    The name of this property.

  • type (String)

    A Sorbet string of this property’s type, such as “String”.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 34

def initialize(name, type, optional: nil, enum: nil, dont_store: nil,
  foreign: nil, default: nil, factory: nil, immutable: nil, array: nil,
  override: nil, redaction: nil)
  
  @name = name
  @type = type
  @optional = optional
  @enum = enum
  @dont_store = dont_store
  @foreign = foreign
  @default = default
  @factory = factory
  @immutable = immutable
  @array = array
  @override = override
  @redaction = redaction
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



108
109
110
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 108

def array
  @array
end

#defaultObject (readonly)

Returns the value of attribute default.



99
100
101
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 99

def default
  @default
end

#dont_storeObject (readonly)

Returns the value of attribute dont_store.



93
94
95
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 93

def dont_store
  @dont_store
end

#enumObject (readonly)

Returns the value of attribute enum.



90
91
92
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 90

def enum
  @enum
end

#factoryObject (readonly)

Returns the value of attribute factory.



102
103
104
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 102

def factory
  @factory
end

#foreignObject (readonly)

Returns the value of attribute foreign.



96
97
98
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 96

def foreign
  @foreign
end

#immutableObject (readonly)

Returns the value of attribute immutable.



105
106
107
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 105

def immutable
  @immutable
end

#nameString (readonly)

The name of this parameter, including any prefixes or suffixes such as *.

Returns:

  • (String)


78
79
80
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 78

def name
  @name
end

#optionalObject (readonly)

Returns the value of attribute optional.



87
88
89
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 87

def optional
  @optional
end

#overrideObject (readonly)

Returns the value of attribute override.



111
112
113
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 111

def override
  @override
end

#redactionObject (readonly)

Returns the value of attribute redaction.



114
115
116
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 114

def redaction
  @redaction
end

#typeString? (readonly)

A Sorbet string of this parameter’s type, such as “String” or “T.untyped”.

Returns:

  • (String, nil)


84
85
86
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 84

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if this instance is equal to another instance.

Parameters:

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 58

def ==(other)
  StructProp === other &&
    name       == other.name &&
    type       == other.type &&
    optional   == other.optional &&
    enum       == other.enum &&
    dont_store == other.dont_store &&
    foreign    == other.foreign &&
    default    == other.default &&
    factory    == other.factory &&
    immutable  == other.immutable &&
    array      == other.array &&
    override   == other.override &&
    redaction  == other.redaction
end

#to_prop_callString

Returns the prop call required to create this property.

Returns:

  • (String)


124
125
126
127
128
129
130
131
132
133
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 124

def to_prop_call
  call = "prop :#{name}, #{type}"

  EXTRA_PROPERTIES.each do |extra_property|
    value = send extra_property
    call += ", #{extra_property}: #{value}" unless value.nil?
  end

  call
end