Class: Foobara::TypeDeclaration
- Inherits:
-
Object
- Object
- Foobara::TypeDeclaration
- Defined in:
- foobara-0.5.8/projects/typesystem/projects/type_declarations/src/type_declaration.rb
Overview
Inheriting from ::Hash for now but we should remove this once all of the handlers are updated
Instance Attribute Summary collapse
-
#base_type ⇒ Object
Returns the value of attribute base_type.
-
#declaration_data ⇒ Object
Returns the value of attribute declaration_data.
-
#is_absolutified ⇒ Object
(also: #absolutified?)
Returns the value of attribute is_absolutified.
-
#is_deep_duped ⇒ Object
(also: #deep_duped?)
Returns the value of attribute is_deep_duped.
-
#is_duped ⇒ Object
(also: #duped?)
Returns the value of attribute is_duped.
-
#is_strict ⇒ Object
(also: #strict?)
Returns the value of attribute is_strict.
-
#reference_checked ⇒ Object
(also: #reference_checked?)
Returns the value of attribute reference_checked.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #all_symbolizable_keys? ⇒ Boolean
- #array? ⇒ Boolean
- #assign(other) ⇒ Object
- #class? ⇒ Boolean
- #clone ⇒ Object
- #clone_from_part(part) ⇒ Object
- #delete(key) ⇒ Object
- #except ⇒ Object
- #handle_symbolic_declaration ⇒ Object
- #hash? ⇒ Boolean
-
#initialize(declaration_data, absolutified = false, skip_reference_check = false) ⇒ TypeDeclaration
constructor
TODO: we should be able to delete absolutified opt once strict declarations use
:refinstead of ‘:ref` format. - #key?(key) ⇒ Boolean
- #proc? ⇒ Boolean
- #reference? ⇒ Boolean
- #size ⇒ Object
- #slice ⇒ Object
- #symbolize_keys! ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(declaration_data, absolutified = false, skip_reference_check = false) ⇒ TypeDeclaration
TODO: we should be able to delete absolutified opt once strict declarations use :ref instead of ‘:ref` format.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 16 def initialize(declaration_data, absolutified = false, skip_reference_check = false) if TypeDeclarations.strict? self.is_strict = true elsif absolutified || TypeDeclarations.strict_stringified? self.is_absolutified = true end self.declaration_data = declaration_data unless strict? || skip_reference_check handle_symbolic_declaration end end |
Instance Attribute Details
#base_type ⇒ Object
Returns the value of attribute base_type.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def base_type @base_type end |
#declaration_data ⇒ Object
Returns the value of attribute declaration_data.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def declaration_data @declaration_data end |
#is_absolutified ⇒ Object Also known as: absolutified?
Returns the value of attribute is_absolutified.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def is_absolutified @is_absolutified end |
#is_deep_duped ⇒ Object Also known as: deep_duped?
Returns the value of attribute is_deep_duped.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def is_deep_duped @is_deep_duped end |
#is_duped ⇒ Object Also known as: duped?
Returns the value of attribute is_duped.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def is_duped @is_duped end |
#is_strict ⇒ Object Also known as: strict?
Returns the value of attribute is_strict.
4 5 6 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 4 def is_strict @is_strict end |
#reference_checked ⇒ Object Also known as: reference_checked?
Returns the value of attribute reference_checked.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def reference_checked @reference_checked end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def type @type end |
Instance Method Details
#[](key) ⇒ Object
133 134 135 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 133 def [](key) declaration_data[key] end |
#[]=(key, value) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 176 def []=(key, value) if strict? self.is_strict = false end unless duped? self.declaration_data = declaration_data.dup self.is_duped = true end declaration_data[key] = value end |
#all_symbolizable_keys? ⇒ Boolean
189 190 191 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 189 def all_symbolizable_keys? Util.all_symbolizable_keys?(declaration_data) end |
#array? ⇒ Boolean
137 138 139 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 137 def array? declaration_data.is_a?(::Array) end |
#assign(other) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 230 def assign(other) self.declaration_data = other.declaration_data if absolutified? != other.absolutified? self.is_absolutified = other.absolutified? end if strict? != other.strict? self.is_strict = other.strict? end if duped? != other.duped? self.is_duped = other.duped? end if deep_duped? != other.deep_duped? self.is_deep_duped = other.deep_duped? end if other.type self.type = other.type end if other.base_type self.base_type = other.base_type end end |
#class? ⇒ Boolean
172 173 174 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 172 def class? declaration_data.is_a?(::Class) end |
#clone ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 258 def clone declaration = TypeDeclaration.new(declaration_data, false, true) if strict? declaration.is_strict = true end if absolutified? declaration.is_absolutified = true end if type declaration.type = type end if base_type declaration.base_type = base_type end if reference_checked? declaration.reference_checked = true end declaration end |
#clone_from_part(part) ⇒ Object
284 285 286 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 284 def clone_from_part(part) TypeDeclaration.new(part) end |
#delete(key) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 153 def delete(key) return unless declaration_data.key?(key) if duped? declaration_data.delete(key) else self.declaration_data = declaration_data.except(key) self.is_duped = true end if strict? self.is_strict = false end if absolutified? && key == :type self.is_absolutified = false end end |
#except ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 204 def except(...) parts = declaration_data.except(...) declaration = clone_from_part(parts) declaration.is_duped = true if declaration.strict? declaration.is_strict = false end declaration end |
#handle_symbolic_declaration ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 38 def handle_symbolic_declaration self.reference_checked = true symbol = if declaration_data.is_a?(::Symbol) declaration_data elsif declaration_data.is_a?(::String) declaration_data.to_sym end if symbol mode = if absolutified? Namespace::LookupMode::ABSOLUTE else Namespace::LookupMode::RELAXED end type = Domain.current.(symbol, mode:) if type unless strict? self.declaration_data = type.full_type_symbol end self.type = type self.is_strict = true self.is_deep_duped = true self.is_duped = true else if declaration_data.is_a?(::Symbol) self.is_duped = true self.is_deep_duped = true end self.declaration_data = declaration_data end elsif TypeDeclarations.strict_stringified? symbolize_keys! type_symbol = self[:type].to_sym self[:type] = type_symbol type = Domain.current.(type_symbol, mode: Namespace::LookupMode::ABSOLUTE) if type if declaration_data.keys.size == 1 self.type = type self.is_strict = true self.is_deep_duped = true self.is_duped = true self.declaration_data = type.full_type_symbol else self.base_type = type end end elsif declaration_data.is_a?(::Hash) type_symbol = self[:type] || self["type"] if type_symbol if type_symbol.is_a?(::Symbol) || type_symbol.is_a?(::String) mode = if absolutified? Namespace::LookupMode::ABSOLUTE else Namespace::LookupMode::RELAXED end type = Domain.current.(type_symbol, mode:) if type symbolize_keys! self[:type] = type.full_type_symbol self.is_absolutified = true if declaration_data.keys.size == 1 self.declaration_data = type.full_type_symbol self.type = type self.is_strict = true self.is_deep_duped = true else self.base_type = type end end end end end end |
#hash? ⇒ Boolean
125 126 127 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 125 def hash? declaration_data.is_a?(::Hash) end |
#key?(key) ⇒ Boolean
129 130 131 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 129 def key?(key) declaration_data.key?(key) end |
#proc? ⇒ Boolean
141 142 143 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 141 def proc? declaration_data.is_a?(::Proc) end |
#reference? ⇒ Boolean
288 289 290 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 288 def reference? strict? && declaration_data.is_a?(::Symbol) end |
#size ⇒ Object
149 150 151 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 149 def size declaration_data.size end |
#slice ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 217 def slice(...) parts = declaration_data.slice(...) declaration = clone_from_part(parts) declaration.is_duped = true if declaration.strict? declaration.is_strict = false end declaration end |
#symbolize_keys! ⇒ Object
193 194 195 196 197 198 199 200 201 202 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 193 def symbolize_keys! if duped? declaration_data.transform_keys!(&:to_sym) else self.declaration_data = declaration_data.transform_keys(&:to_sym) self.is_duped = true end self end |
#to_proc ⇒ Object
145 146 147 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 145 def to_proc declaration_data end |