Class: Literal::Attributable::Generators::Writer

Inherits:
Base
  • Object
show all
Defined in:
lib/literal/attributable/generators/writer.rb

Direct Known Subclasses

IVarWriter, StructWriter

Instance Attribute Summary

Attributes included from Nodes

#nodes

Instance Method Summary collapse

Methods inherited from Base

#call

Methods included from Nodes

node

Constructor Details

#initialize(attribute) ⇒ Writer

Returns a new instance of Writer.



5
6
7
# File 'lib/literal/attributable/generators/writer.rb', line 5

def initialize(attribute)
	@attribute = attribute
end

Instance Method Details

#bodyObject (private)



29
30
31
# File 'lib/literal/attributable/generators/writer.rb', line 29

def body
	[type_check, assignment]
end

#paramsObject (private)



20
21
22
23
24
25
26
27
# File 'lib/literal/attributable/generators/writer.rb', line 20

def params
	[
		PositionalParam.new(
			name: "value",
			default: nil
		)
	]
end

#templateObject



9
10
11
12
13
14
15
16
# File 'lib/literal/attributable/generators/writer.rb', line 9

def template
	Def.new(
		visibility: @attribute.writer,
		name: "#{@attribute.name}=",
		params:,
		body:
	)
end

#type_checkObject (private)



33
34
35
36
37
38
# File 'lib/literal/attributable/generators/writer.rb', line 33

def type_check
	TypeCheck.new(
		attribute_name: @attribute.name,
		variable_name: "value"
	)
end