Class: Parlour::RbiGenerator::StructProp
- Inherits:
-
Object
- Object
- Parlour::RbiGenerator::StructProp
- 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
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#dont_store ⇒ Object
readonly
Returns the value of attribute dont_store.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
-
#foreign ⇒ Object
readonly
Returns the value of attribute foreign.
-
#immutable ⇒ Object
readonly
Returns the value of attribute immutable.
-
#name ⇒ String
readonly
The name of this parameter, including any prefixes or suffixes such as *.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#override ⇒ Object
readonly
Returns the value of attribute override.
-
#redaction ⇒ Object
readonly
Returns the value of attribute redaction.
-
#type ⇒ String?
readonly
A Sorbet string of this parameter’s type, such as “String” or “T.untyped”.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if this instance is equal to another instance.
-
#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
constructor
Create a new struct property.
-
#to_prop_call ⇒ String
Returns the
propcall required to create this property.
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
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
#array ⇒ Object (readonly)
Returns the value of attribute array.
108 109 110 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 108 def array @array end |
#default ⇒ Object (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_store ⇒ Object (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 |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
90 91 92 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 90 def enum @enum end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
102 103 104 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 102 def factory @factory end |
#foreign ⇒ Object (readonly)
Returns the value of attribute foreign.
96 97 98 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 96 def foreign @foreign end |
#immutable ⇒ Object (readonly)
Returns the value of attribute immutable.
105 106 107 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 105 def immutable @immutable end |
#name ⇒ String (readonly)
The name of this parameter, including any prefixes or suffixes such as *.
78 79 80 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 78 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
87 88 89 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 87 def optional @optional end |
#override ⇒ Object (readonly)
Returns the value of attribute override.
111 112 113 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 111 def override @override end |
#redaction ⇒ Object (readonly)
Returns the value of attribute redaction.
114 115 116 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 114 def redaction @redaction end |
#type ⇒ String? (readonly)
A Sorbet string of this parameter’s type, such as “String” or “T.untyped”.
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.
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_call ⇒ String
Returns the prop call required to create this property.
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 |