Module: Dry::Effects::Initializer::DefineWithHook Private

Defined in:
lib/dry/effects/initializer.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#__define_with__Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dry/effects/initializer.rb', line 42

def __define_with__
  seq_names = dry_initializer
    .definitions
    .reject { _2.option }
    .keys
    .join(", ")

  seq_names << ", " unless seq_names.empty?

  undef_method(:with) if method_defined?(:with)

  class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
    def with(**new_options)                                    # def with(**new_options)
      if new_options.empty?                                    #   if new_options.empty?
        self                                                   #     self
      else                                                     #   else
        self.class.new(#{seq_names}**options, **new_options)   #     self.class.new(attr1, attr2, **options, **new_options)
      end                                                      #   end
    end                                                        # end
  RUBY
end

#optionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
# File 'lib/dry/effects/initializer.rb', line 18

def option(*)
  super.tap do
    __define_with__ unless method_defined?(:with)
    @has_options = true
  end
end

#options?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/dry/effects/initializer.rb', line 35

def options?
  return @has_options if defined? @has_options

  @has_options = false
end

#paramObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
12
13
14
# File 'lib/dry/effects/initializer.rb', line 9

def param(*)
  super.tap do
    @params_arity = nil
    __define_with__
  end
end

#params_arityObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
# File 'lib/dry/effects/initializer.rb', line 27

def params_arity
  @params_arity ||= dry_initializer
    .definitions
    .reject { _2.option }
    .size
end