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.
T.let(%i{ optional enum dont_store foreign default factory immutable array override redaction }, T::Array[Symbol])
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 ⇒ Types::TypeLike?
readonly
This parameter’s type.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if this instance is equal to another instance.
- #generalize_from_rbi! ⇒ Object
-
#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
prop
call 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 33 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.
106 107 108 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 106 def array @array end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
97 98 99 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 97 def default @default end |
#dont_store ⇒ Object (readonly)
Returns the value of attribute dont_store.
91 92 93 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 91 def dont_store @dont_store end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
88 89 90 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 88 def enum @enum end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
100 101 102 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 100 def factory @factory end |
#foreign ⇒ Object (readonly)
Returns the value of attribute foreign.
94 95 96 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 94 def foreign @foreign end |
#immutable ⇒ Object (readonly)
Returns the value of attribute immutable.
103 104 105 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 103 def immutable @immutable end |
#name ⇒ String (readonly)
The name of this parameter, including any prefixes or suffixes such as *.
77 78 79 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 77 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
85 86 87 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 85 def optional @optional end |
#override ⇒ Object (readonly)
Returns the value of attribute override.
109 110 111 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 109 def override @override end |
#redaction ⇒ Object (readonly)
Returns the value of attribute redaction.
112 113 114 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 112 def redaction @redaction end |
#type ⇒ Types::TypeLike? (readonly)
This parameter’s type.
82 83 84 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 82 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if this instance is equal to another instance.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 57 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 |
#generalize_from_rbi! ⇒ Object
134 135 136 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 134 def generalize_from_rbi! @type = TypeParser.parse_single_type(@type) if String === @type end |
#to_prop_call ⇒ String
Returns the prop
call required to create this property.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/parlour/rbi_generator/struct_prop.rb', line 122 def to_prop_call call = "prop :#{name}, #{String === @type ? @type : @type.generate_rbi}" EXTRA_PROPERTIES.each do |extra_property| value = send extra_property call += ", #{extra_property}: #{value}" unless value.nil? end call end |