Class: Literal::Struct

Inherits:
Structish show all
Defined in:
lib/literal/struct.rb

Constant Summary

Constants included from Attributable

Attributable::Visibility

Constants included from Monads

Monads::Either, Monads::Left, Monads::Maybe, Monads::Nothing, Monads::Result, Monads::Right, Monads::Some

Instance Attribute Summary

Attributes inherited from Structish

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structish

#==, #[], #[]=, #deconstruct, #deconstruct_keys, #to_h

Methods included from Attributable

#attribute, #define_literal_methods, #literal_attributes, #literal_extension

Methods included from Types

#_Any, #_Array, #_Boolean, #_Callable, #_Class, #_Constraint, #_Descendant, #_Enumerable, #_Falsy, #_Float, #_Frozen, #_Hash, #_Integer, #_Interface, #_Intersection, #_Is, #_JSONData, #_Lambda, #_Map, #_Never, #_Nilable, #_Not, #_Procable, #_Range, #_Set, #_Shape, #_String, #_Symbol, #_Truthy, #_Tuple, #_Union, #_Void

Methods included from Monads

#Either, #Left, #Maybe, #Result, #Right, #Some, #Success

Class Method Details

.attribute(name, type, special = nil, reader: :public, writer: :public, positional: false, default: nil) ⇒ Object



5
6
7
# File 'lib/literal/struct.rb', line 5

def attribute(name, type, special = nil, reader: :public, writer: :public, positional: false, default: nil)
	super(name, type, special, reader:, writer:, positional:, default:)
end

.generate_literal_initializerObject (private)



11
12
13
# File 'lib/literal/struct.rb', line 11

def generate_literal_initializer
	Generators::StructInitializer.new(literal_attributes).call
end

.generate_literal_reader(attribute) ⇒ Object (private)



19
20
21
# File 'lib/literal/struct.rb', line 19

def generate_literal_reader(attribute)
	Generators::StructReader.new(attribute).call
end

.generate_literal_writer(attribute) ⇒ Object (private)



15
16
17
# File 'lib/literal/struct.rb', line 15

def generate_literal_writer(attribute)
	Generators::StructWriter.new(attribute).call
end

Instance Method Details

#marshal_dumpObject



37
38
39
# File 'lib/literal/struct.rb', line 37

def marshal_dump
	[2, @attributes, frozen?]
end

#marshal_load(data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/literal/struct.rb', line 24

def marshal_load(data)
	case data
	when Hash # TODO: Remove this branch.
		@attributes = data[:attributes]
		freeze if data[:frozen?]
	when Array
		@attributes = data[1]
		freeze if data[2]
	end

	@literal_attributes = self.class.literal_attributes
end