Class: Foobara::TypeDeclaration
- Inherits:
-
Object
- Object
- Foobara::TypeDeclaration
- Defined in:
- foobara-0.1.7/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
Direct Known Subclasses
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 ‘:ref` instead 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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/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 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 6 def type @type end |
Instance Method Details
#[](key) ⇒ Object
130 131 132 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 130 def [](key) declaration_data[key] end |
#[]=(key, value) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 173 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
186 187 188 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 186 def all_symbolizable_keys? Util.all_symbolizable_keys?(declaration_data) end |
#array? ⇒ Boolean
134 135 136 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 134 def array? declaration_data.is_a?(::Array) end |
#assign(other) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 227 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
169 170 171 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 169 def class? declaration_data.is_a?(::Class) end |
#clone ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 255 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
281 282 283 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 281 def clone_from_part(part) TypeDeclaration.new(part) end |
#delete(key) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 150 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
201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 201 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 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 38 def handle_symbolic_declaration self.reference_checked = true if declaration_data.is_a?(::Symbol) symbol = declaration_data elsif declaration_data.is_a?(::String) && TypeDeclarations.stringified? symbol = declaration_data.to_sym end if symbol type = if absolutified? Domain.current.(symbol, mode: Namespace::LookupMode::ABSOLUTE) else Domain.current.(symbol) end 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) type = if absolutified? Domain.current.(type_symbol, mode: Namespace::LookupMode::ABSOLUTE) else Domain.current.(type_symbol) end 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
122 123 124 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 122 def hash? declaration_data.is_a?(::Hash) end |
#key?(key) ⇒ Boolean
126 127 128 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 126 def key?(key) declaration_data.key?(key) end |
#proc? ⇒ Boolean
138 139 140 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 138 def proc? declaration_data.is_a?(::Proc) end |
#reference? ⇒ Boolean
285 286 287 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 285 def reference? strict? && declaration_data.is_a?(::Symbol) end |
#size ⇒ Object
146 147 148 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 146 def size declaration_data.size end |
#slice ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 214 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
190 191 192 193 194 195 196 197 198 199 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 190 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
142 143 144 |
# File 'foobara-0.1.7/projects/type_declarations/src/type_declaration.rb', line 142 def to_proc declaration_data end |