class Gamefic::Proxy
@todo Turn this into a module after the old proxies are completely deprecated
Constants
- TYPES
Attributes
type[R]
@return [Symbol]
Public Class Methods
new(type, key)
click to toggle source
@param type [Symbol] @param key [Symbol, String
, Array]
# 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
Public Instance Methods
[](key)
click to toggle source
# File lib/gamefic/proxy.rb, line 34 def [](key) raise ArgumentError, 'Invalid []' unless type == :config @key.push key self end
fetch(narrative)
click to toggle source
# 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
Private Instance Methods
attr(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 43 def attr narrative Stage.run(narrative, [key].flatten) { |keys| keys.inject(self) { |obj, key| obj.send key } } rescue NoMethodError nil end
config(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 69 def config narrative key.inject(narrative.config) { |hash, key| hash[key] } end
ivar(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 49 def ivar narrative narrative.instance_variable_get key end
pick(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 53 def pick narrative narrative.pick *key end
pick!(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 57 def pick! narrative narrative.pick! *key end
plot_pick(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 61 def plot_pick narrative narrative.plot.pick *key end
plot_pick!(narrative)
click to toggle source
# File lib/gamefic/proxy.rb, line 65 def plot_pick! narrative narrative.plot.pick! *key end
validate_type()
click to toggle source
# File lib/gamefic/proxy.rb, line 73 def validate_type return if TYPES.include?(type) raise ArgumentError, "Invalid proxy type `#{type}` (must be #{TYPES.join_or})" end