class ROM::Commands::Lazy

Lazy command wraps another command and evaluates its input when called

@api private

Attributes

command[R]

@attr_reader [Command] command The wrapped command

command_proc[R]
evaluator[R]

@attr_reader [Proc] evaluator The proc that will evaluate the input

unwrap[R]

@attr_reader [Command] command The wrapped command

Public Class Methods

[](command) click to toggle source

@api private

# 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
new(command, evaluator, command_proc = nil) click to toggle source

@api private

# 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

Public Instance Methods

>>(other) click to toggle source

Compose a lazy command with another one

@see Commands::Abstract#>>

@return [Composite]

@api public

# File lib/rom/commands/lazy.rb, line 58
def >>(other)
  Composite.new(self, other)
end
call(*_args) click to toggle source

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

@return [Array,Hash]

@api public

# File lib/rom/commands/lazy.rb, line 47
def call(*_args)
  raise NotImplementedError
end
combine(*others) click to toggle source

Combine with other lazy commands

@see Abstract#combine

@return [Graph]

@api public

# File lib/rom/commands/lazy.rb, line 69
def combine(*others)
  Graph.new(self, others)
end
lazy?() click to toggle source

@api private

# File lib/rom/commands/lazy.rb, line 74
def lazy?
  true
end
respond_to_missing?(name, include_private = false) click to toggle source

@api private

Calls superclass method
# File lib/rom/commands/lazy.rb, line 79
def respond_to_missing?(name, include_private = false)
  super || command.respond_to?(name)
end

Private Instance Methods

method_missing(name, *args, &block) click to toggle source

@api private

Calls superclass method
# 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