Module: ROM::AutoCurry Private

Included in:
Relation
Defined in:
lib/rom/auto_curry.rb

Overview

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.

Relation extension which provides auto-currying of relation view methods

Defined Under Namespace

Classes: Wrapper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ 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.



35
36
37
38
39
40
41
42
# File 'lib/rom/auto_curry.rb', line 35

def self.extended(klass)
  klass.define_singleton_method(:method_added) do |name|
    return if auto_curry_busy?

    auto_curry_guard { auto_curry(name) }
    super(name)
  end
end

Instance Method Details

#auto_curried_methodsObject

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.



58
59
60
# File 'lib/rom/auto_curry.rb', line 58

def auto_curried_methods
  @__auto_curried_methods__ ||= Set.new
end

#auto_curry(name) ⇒ 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.

Auto-curry a method

Parameters:

  • name (Symbol)

    The name of a method



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rom/auto_curry.rb', line 67

def auto_curry(name, &)
  arity = instance_method(name).arity

  if public_instance_methods.include?(name) && arity != 0
    mod = Wrapper.new(name, arity, &)

    auto_curried_methods << name

    prepend(mod)
  else
    self
  end
end

#auto_curry_busy?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)


53
54
55
# File 'lib/rom/auto_curry.rb', line 53

def auto_curry_busy?
  @__auto_curry_busy__ ||= false
end

#auto_curry_guardObject

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.



45
46
47
48
49
50
# File 'lib/rom/auto_curry.rb', line 45

def auto_curry_guard
  @__auto_curry_busy__ = true
  yield
ensure
  @__auto_curry_busy__ = false
end