Class: Memorium::Memo::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/memorium/memo/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params) ⇒ Template

Returns a new instance of Template.



4
5
6
7
8
9
# File 'lib/memorium/memo/template.rb', line 4

def initialize(name, params)
  @name = name
  @params = params

  @result = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/memorium/memo/template.rb', line 2

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



2
3
4
# File 'lib/memorium/memo/template.rb', line 2

def params
  @params
end

Instance Method Details

#reader_memoize_nilObject



22
23
24
25
26
27
28
29
30
# File 'lib/memorium/memo/template.rb', line 22

def reader_memoize_nil
  @result << <<~RUBY
    def #{name.original}(#{params.signature})
      return #{name.pure_memoized} if defined?(#{name.pure_memoized})
      #{name.pure_memoized} = #{name.memoized}(#{params.parametrize})
    end
  RUBY

end

#reader_plainObject



13
14
15
16
17
18
19
20
# File 'lib/memorium/memo/template.rb', line 13

def reader_plain
  @result << <<~RUBY
    def #{name.original}(#{params.signature})
      #{name.pure_memoized} ||= #{name.memoized}(#{params.parametrize})
    end
  RUBY

end

#resultObject



11
# File 'lib/memorium/memo/template.rb', line 11

def result = @result.join("\n")

#writerObject



32
33
34
35
36
37
38
39
# File 'lib/memorium/memo/template.rb', line 32

def writer
  @result << <<~RUBY
    def #{name.setter}(value)
      #{name.pure_memoized} = value
    end
  RUBY

end