Class: Interactor::Initializer::Helper
- Inherits:
-
Object
- Object
- Interactor::Initializer::Helper
- Defined in:
- lib/interactor/initializer/helper.rb
Class Method Summary collapse
- .attr_assignments(attributes) ⇒ Object
- .attr_readers(target_class, attributes) ⇒ Object
- .methods_with_keywords ⇒ Object
- .methods_with_params ⇒ Object
- .modify_class(target_class, signature, attributes, class_methods) ⇒ Object
Class Method Details
.attr_assignments(attributes) ⇒ Object
59 60 61 |
# File 'lib/interactor/initializer/helper.rb', line 59 def self.attr_assignments(attributes) attributes.map { |attr| "@#{attr} = #{attr}" }.join(';') end |
.attr_readers(target_class, attributes) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/interactor/initializer/helper.rb', line 18 def self.attr_readers(target_class, attributes) target_class.class_eval do attributes.each do |attr| attr_reader(attr) protected(attr) end end end |
.methods_with_keywords ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/interactor/initializer/helper.rb', line 43 def self.methods_with_keywords <<-RUBY def self.for(args) new(**args).run end def self.run(args) new(**args).run end def self.with(args) new(**args).run end RUBY end |
.methods_with_params ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/interactor/initializer/helper.rb', line 27 def self.methods_with_params <<-RUBY def self.for(*args) new(*args).run end def self.run(*args) new(*args).run end def self.with(*args) new(*args).run end RUBY end |
.modify_class(target_class, signature, attributes, class_methods) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/interactor/initializer/helper.rb', line 4 def self.modify_class(target_class, signature, attributes, class_methods) assignments = attr_assignments(attributes) target_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def initialize(#{signature}) #{assignments} end #{class_methods} RUBY attr_readers(target_class, attributes) end |