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.



34
35
36
37
38
# File 'lib/rom/commands/lazy.rb', line 34

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.



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

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.



13
14
15
# File 'lib/rom/commands/lazy.rb', line 13

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.



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

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.



18
19
20
# File 'lib/rom/commands/lazy.rb', line 18

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.



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

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#>>


56
57
58
# File 'lib/rom/commands/lazy.rb', line 56

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)


45
46
47
# File 'lib/rom/commands/lazy.rb', line 45

def call(*args)
  raise NotImplementedError
end

#combine(*others) ⇒ Graph

Combine with other lazy commands

Returns:

See Also:

  • Abstract#combine


67
68
69
# File 'lib/rom/commands/lazy.rb', line 67

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)


72
73
74
# File 'lib/rom/commands/lazy.rb', line 72

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)


77
78
79
# File 'lib/rom/commands/lazy.rb', line 77

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