Class: Kobako::Extension::Backend

Inherits:
Data
  • Object
show all
Defined in:
lib/kobako/extension.rb,
sig/kobako/extension.rbs

Overview

Kobako::Extension::Backend — the host attachment of an Extension, pairing path (the constant path the backend binds at, single-segment "File" or nested "MyApp::Store", spelling the guest constant the idiom routes to) with the source of the bound object, declared by explicit keyword:

* +object:+ — a static object, fixed for the Sandbox's life.
* +provider:+ — a no-argument callable invoked once per invocation to
yield that invocation's object, so a fresh object backs the path
every invocation. A provider that raises propagates its exception to
the invocation caller and leaves the guest unrun; the next
invocation resolves it afresh.
* neither — a fillable, defaulting to +Kobako::Unresolved+ until the
host supplies the invocation's object.

The kind is chosen by keyword, never inferred from whether the value is callable, so a static object that is itself callable is expressed directly with object:. Giving both object: and provider: raises ArgumentError.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, object: nil, provider: nil) ⇒ Backend

Returns a new instance of Backend.

Parameters:

  • path: (String)
  • object: (Object) (defaults to: nil)
  • provider: (Object) (defaults to: nil)


47
48
49
50
51
52
53
54
# File 'lib/kobako/extension.rb', line 47

def initialize(path:, object: nil, provider: nil)
  if !object.nil? && !provider.nil?
    raise ArgumentError,
          "Extension::Backend accepts object: or provider:, not both"
  end

  super
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.

Returns:

  • (Object)


14
15
16
# File 'sig/kobako/extension.rbs', line 14

def object
  @object
end

#pathString (readonly)

Returns the value of attribute path.

Returns:

  • (String)


13
14
15
# File 'sig/kobako/extension.rbs', line 13

def path
  @path
end

#providerObject (readonly)

Returns the value of attribute provider.

Returns:

  • (Object)


15
16
17
# File 'sig/kobako/extension.rbs', line 15

def provider
  @provider
end

Class Method Details

.newKobako::Extension::Backend

Parameters:

  • path: (String)
  • object: (Object)
  • provider: (Object)

Returns:



17
# File 'sig/kobako/extension.rbs', line 17

def self.new: (path: String, ?object: untyped, ?provider: untyped) -> Kobako::Extension::Backend