Class: Foobara::TypeDeclaration
- Inherits:
-
Object
- Object
- Foobara::TypeDeclaration
- Defined in:
- foobara-0.6.1/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_claimed_but_error ⇒ Object
(also: #claimed_but_error?)
Returns the value of attribute is_claimed_but_error.
-
#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
- #claimed_but_error! ⇒ 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{type: :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 {type: :ref} format.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 17 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_claimed_but_error ⇒ Object Also known as: claimed_but_error?
Returns the value of attribute is_claimed_but_error.
6 7 8 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 6 def is_claimed_but_error @is_claimed_but_error 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
134 135 136 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 134 def [](key) declaration_data[key] end |
#[]=(key, value) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 177 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
190 191 192 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 190 def all_symbolizable_keys? Util.all_symbolizable_keys?(declaration_data) end |
#array? ⇒ Boolean
138 139 140 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 138 def array? declaration_data.is_a?(::Array) end |
#assign(other) ⇒ Object
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 257 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 231 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 |
#claimed_but_error! ⇒ Object
293 294 295 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 293 def claimed_but_error! self.is_claimed_but_error = true end |
#class? ⇒ Boolean
173 174 175 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 173 def class? declaration_data.is_a?(::Class) end |
#clone ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 259 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
285 286 287 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 285 def clone_from_part(part) TypeDeclaration.new(part) end |
#delete(key) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 154 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
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 205 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
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 124 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 39 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
126 127 128 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 126 def hash? declaration_data.is_a?(::Hash) end |
#key?(key) ⇒ Boolean
130 131 132 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 130 def key?(key) declaration_data.key?(key) end |
#proc? ⇒ Boolean
142 143 144 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 142 def proc? declaration_data.is_a?(::Proc) end |
#reference? ⇒ Boolean
289 290 291 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 289 def reference? strict? && declaration_data.is_a?(::Symbol) end |
#size ⇒ Object
150 151 152 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 150 def size declaration_data.size end |
#slice ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 218 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
194 195 196 197 198 199 200 201 202 203 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 194 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
146 147 148 |
# File 'projects/typesystem/projects/type_declarations/src/type_declaration.rb', line 146 def to_proc declaration_data end |