Class: Memorium::InitializeAttr::Template
- Inherits:
-
Object
- Object
- Memorium::InitializeAttr::Template
- Defined in:
- lib/memorium/initialize_attr/template.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Template
constructor
A new instance of Template.
- #initializer ⇒ Object
- #reader ⇒ Object
- #reader_with_require(check_type) ⇒ Object
- #result ⇒ Object
- #writer ⇒ Object
Constructor Details
#initialize(name) ⇒ Template
Returns a new instance of Template.
4 5 6 7 8 |
# File 'lib/memorium/initialize_attr/template.rb', line 4 def initialize(name) @name = name @result = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/memorium/initialize_attr/template.rb', line 2 def name @name end |
Instance Method Details
#initializer ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/memorium/initialize_attr/template.rb', line 12 def initializer @result << <<~RUBY def initialize(attributes = nil, **kw_attributes) #{Memorium::InitializeAttr::ACCESSOR} = attributes || kw_attributes end RUBY end |
#reader ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/memorium/initialize_attr/template.rb', line 21 def reader @result << <<~RUBY def #{name.original} return #{name.attribute} if defined?(#{name.attribute}) #{name.attribute} = #{Memorium::InitializeAttr::ACCESSOR}[#{name.original.inspect}] end RUBY end |
#reader_with_require(check_type) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/memorium/initialize_attr/template.rb', line 31 def reader_with_require(check_type) @result << <<~RUBY def #{name.original} return #{name.attribute} if defined?(#{name.attribute}) #{name.attribute} = #{Memorium::InitializeAttr::ACCESSOR}[#{name.original.inspect}] require_attr(#{name.original.inspect}, by: #{check_type.inspect}) end RUBY end |
#result ⇒ Object
10 |
# File 'lib/memorium/initialize_attr/template.rb', line 10 def result = @result.join("\n") |
#writer ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/memorium/initialize_attr/template.rb', line 42 def writer @result << <<~RUBY def #{name.setter}(value) #{name.attribute} = value end RUBY end |