Class: NestedRecord::Methods
- Inherits:
-
Module
- Object
- Module
- NestedRecord::Methods
- Defined in:
- lib/nested_record/methods.rb,
lib/nested_record/methods/one.rb,
lib/nested_record/methods/many.rb
Defined Under Namespace
Instance Method Summary collapse
- #attributes_writer_method_name ⇒ Object
- #define(name) ⇒ Object
- #define_attributes_writer_method ⇒ Object
-
#initialize(setup) ⇒ Methods
constructor
A new instance of Methods.
- #reader_method_name ⇒ Object
- #rewrite_attributes_method_name ⇒ Object
- #upsert_attributes_method_name ⇒ Object
- #writer_method_name ⇒ Object
Constructor Details
#initialize(setup) ⇒ Methods
Returns a new instance of Methods.
2 3 4 |
# File 'lib/nested_record/methods.rb', line 2 def initialize(setup) @setup = setup end |
Instance Method Details
#attributes_writer_method_name ⇒ Object
41 42 43 |
# File 'lib/nested_record/methods.rb', line 41 def attributes_writer_method_name :"#{@setup.name}_attributes=" end |
#define(name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nested_record/methods.rb', line 6 def define(name) method_name = public_send("#{name}_method_name") method_body = (bodym = public_method("#{name}_method_body")).call case method_body when Proc define_method(method_name, &method_body) when String location = bodym.source_location location[1] += 1 module_eval <<~RUBY, *location def #{method_name} #{method_body} end RUBY else fail end end |
#define_attributes_writer_method ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/nested_record/methods.rb', line 45 def define_attributes_writer_method case @setup.attributes_writer_strategy when :rewrite alias_method attributes_writer_method_name, rewrite_attributes_method_name when :upsert alias_method attributes_writer_method_name, upsert_attributes_method_name end end |
#reader_method_name ⇒ Object
25 26 27 |
# File 'lib/nested_record/methods.rb', line 25 def reader_method_name @setup.name end |
#rewrite_attributes_method_name ⇒ Object
37 38 39 |
# File 'lib/nested_record/methods.rb', line 37 def rewrite_attributes_method_name :"rewrite_#{@setup.name}_attributes" end |
#upsert_attributes_method_name ⇒ Object
33 34 35 |
# File 'lib/nested_record/methods.rb', line 33 def upsert_attributes_method_name :"upsert_#{@setup.name}_attributes" end |
#writer_method_name ⇒ Object
29 30 31 |
# File 'lib/nested_record/methods.rb', line 29 def writer_method_name :"#{@setup.name}=" end |