Class: ROM::Commands::Lazy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/commands/lazy.rb,
lib/rom/commands/lazy/create.rb,
lib/rom/commands/lazy/delete.rb,
lib/rom/commands/lazy/update.rb

Overview

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

Lazy command wraps another command and evaluates its input when called

Direct Known Subclasses

Create, Delete, Update

Defined Under Namespace

Classes: Create, Delete, Update

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, evaluator, command_proc = nil) ⇒ Lazy

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 a new instance of Lazy.


36
37
38
39
40
# File 'lib/rom/commands/lazy.rb', line 36

def initialize(command, evaluator, command_proc = nil)
  @command = command
  @evaluator = evaluator
  @command_proc = command_proc || proc { |*| command }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

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.


86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rom/commands/lazy.rb', line 86

def method_missing(name, *args, &block)
  if command.respond_to?(name)
    response = command.public_send(name, *args, &block)

    if response.instance_of?(command.class)
      self.class.new(response, evaluator, command_proc)
    else
      response
    end
  else
    super
  end
end

Instance Attribute Details

#commandObject (readonly) Also known as: unwrap

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.


15
16
17
# File 'lib/rom/commands/lazy.rb', line 15

def command
  @command
end

#command_procObject (readonly)

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.


22
23
24
# File 'lib/rom/commands/lazy.rb', line 22

def command_proc
  @command_proc
end

#evaluatorObject (readonly)

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.


20
21
22
# File 'lib/rom/commands/lazy.rb', line 20

def evaluator
  @evaluator
end

Class Method Details

.[](command) ⇒ 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.


25
26
27
28
29
30
31
32
33
# File 'lib/rom/commands/lazy.rb', line 25

def self.[](command)
  case command
  when Commands::Create then Lazy::Create
  when Commands::Update then Lazy::Update
  when Commands::Delete then Lazy::Delete
  else
    self
  end
end

Instance Method Details

#>>(other) ⇒ Composite

Compose a lazy command with another one

Returns:

See Also:

  • Commands::Abstract#>>

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

def >>(other)
  Composite.new(self, other)
end

#call(*_args) ⇒ Array, Hash

Evaluate command's input using the input proc and pass to command

Returns:

  • (Array, Hash)

Raises:

  • (NotImplementedError)

47
48
49
# File 'lib/rom/commands/lazy.rb', line 47

def call(*_args)
  raise NotImplementedError
end

#combine(*others) ⇒ Graph

Combine with other lazy commands

Returns:

See Also:

  • Abstract#combine

69
70
71
# File 'lib/rom/commands/lazy.rb', line 69

def combine(*others)
  Graph.new(self, others)
end

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

74
75
76
# File 'lib/rom/commands/lazy.rb', line 74

def lazy?
  true
end

#respond_to_missing?(name, include_private = false) ⇒ 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)

79
80
81
# File 'lib/rom/commands/lazy.rb', line 79

def respond_to_missing?(name, include_private = false)
  super || command.respond_to?(name)
end