Class: Gamefic::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/proxy.rb,
lib/gamefic/proxy/base.rb,
lib/gamefic/proxy/pick.rb,
lib/gamefic/proxy/config.rb,
lib/gamefic/proxy/plot_pick.rb

Overview

TODO:

Turn this into a module after the old proxies are completely deprecated

Defined Under Namespace

Classes: Base, Config, Pick, PlotPick

Constant Summary collapse

TYPES =
%i[attr ivar pick pick! plot_pick plot_pick! config].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:



22
23
24
25
26
27
# File 'lib/gamefic/proxy.rb', line 22

def initialize type, key
  Gamefic.logger.debug "Using deprecated #{type} proxy"
  @type = type
  validate_type
  @key = type == :config ? [key].compact : key
end

Instance Attribute Details

#keySymbol, ... (readonly)

Returns:



18
19
20
# File 'lib/gamefic/proxy.rb', line 18

def key
  @key
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


15
16
17
# File 'lib/gamefic/proxy.rb', line 15

def type
  @type
end

Instance Method Details

#[](key) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
39
# File 'lib/gamefic/proxy.rb', line 34

def [](key)
  raise ArgumentError, 'Invalid []' unless type == :config

  @key.push key
  self
end

#fetch(narrative) ⇒ Object



29
30
31
32
# File 'lib/gamefic/proxy.rb', line 29

def fetch narrative
  send(type, narrative) ||
    raise(ArgumentError, "Unable to fetch entity from proxy agent symbol `#{key}`")
end