Class: Loom::Shell::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/shell/api.rb

Overview

A facade for the shell API exposed to Loom files. This is the loom object passed to patterns.

Direct Known Subclasses

FakeApi

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ Api

Returns a new instance of Api.



8
9
10
11
12
# File 'lib/loom/shell/api.rb', line 8

def initialize(shell)
  @shell = shell
  @mod_loader = shell.mod_loader
  @dry_run = shell.dry_run
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

This is the entry point for ‘loom.foo` calls from .loom files.



23
24
25
26
27
28
29
30
31
# File 'lib/loom/shell/api.rb', line 23

def method_missing(name, *args, &block)
  Loom.log.debug3(self) { "shell api => #{name} #{args} #{block}" }
  # TODO: The relationship between shell and mod_loader seems leaky here, a
  # Shell::Api should have a shell and not care about the mod_loader,
  # currently it seems to violate Demeter. The shell should dispatch to the
  # mod_loader only as an implementation detail. Otherwise this is harder to
  # test.
  @mod_loader.send name, @shell, *args, &block
end

Instance Method Details

#dry_run?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/loom/shell/api.rb', line 14

def dry_run?
  @dry_run
end

#localObject



18
19
20
# File 'lib/loom/shell/api.rb', line 18

def local
  @shell.local.shell_api
end