Class: Interactor::Initializer::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/interactor/initializer/helper.rb

Class Method Summary collapse

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_keywordsObject



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
  "    def self.for(args)\n      new(**args).run\n    end\n\n    def self.run(args)\n      new(**args).run\n    end\n\n    def self.with(args)\n      new(**args).run\n    end\n  RUBY\nend\n"

.methods_with_paramsObject



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
  "    def self.for(*args)\n      new(*args).run\n    end\n\n    def self.run(*args)\n      new(*args).run\n    end\n\n    def self.with(*args)\n      new(*args).run\n    end\n  RUBY\nend\n"

.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 "    def initialize(\#{signature})\n      \#{assignments}\n    end\n\n    \#{class_methods}\n  RUBY\n\n  attr_readers(target_class, attributes)\nend\n", __FILE__, __LINE__ + 1