class Loom::Mods::ActionProxy

Public Class Methods

new(mod, shell_api) click to toggle source
# File lib/loom/mods/action_proxy.rb, line 6
def initialize(mod, shell_api)
  @mod = mod
  @shell_api = shell_api
  @nested_action_proxies = {}
end

Private Class Methods

install_action_map(action_map) click to toggle source
# File lib/loom/mods/action_proxy.rb, line 29
def install_action_map(action_map)
  install_root_actions action_map
  install_namespace_action_proxies action_map
end
install_namespace_action_proxies(action_map) click to toggle source

This gets a bit tricky

# File lib/loom/mods/action_proxy.rb, line 61
def install_namespace_action_proxies(action_map)
  action_map.ns_actionmaps.each do |ns, ns_action_map|
    @nested_action_proxy_klasses ||= {}
    @nested_action_proxy_klasses[self.hash] ||= {}
    @nested_action_proxy_klasses[self.hash][ns] ||=
      ActionProxy.subclass_for_action_map ns_action_map
    action_proxy_klass = @nested_action_proxy_klasses[self.hash][ns]

    define_method ns do
      @nested_action_proxies[ns] ||= action_proxy_klass.new @mod
    end
    Loom.log.debug2 self do
      "defined action proxy ns: #{ns}"
    end
  end
end
install_root_actions(action_map) click to toggle source
# File lib/loom/mods/action_proxy.rb, line 34
def install_root_actions(action_map)
  action_map.action_tuples.each do |tuple|
    public_action_name = tuple[0]
    # TODO: What I've done here w/ bound_action_name (remapping methods
    # from a given name to a flattened namespace on the Mod object) is
    # very very strange. Just storing/binding/calling a Proc would be more
    # idiomatic.
    bound_action_name = tuple[1]

    define_method public_action_name do |*args, &block|
      # TODO[P0]: Effectively this is the API for all mods, but it's
      # burried here in the middle of nowhere. Add documentation - or make
      # it easier to read.
      Loom.log.debug(self) do
        "proxy to mod action: #{public_action_name} => #{bound_action_name}, #{@mod}"
      end

      @mod.send bound_action_name, *args, &block
    end
    Loom.log.debug2 self do
      "defined action proxy action: #{public_action_name} => #{bound_action_name}"
    end
  end
end
new_action_map() click to toggle source
# File lib/loom/mods/action_proxy.rb, line 19
def new_action_map
  ActionMap.new
end
subclass_for_action_map(action_map) click to toggle source
# File lib/loom/mods/action_proxy.rb, line 23
def subclass_for_action_map(action_map)
  sub_class = Class.new ActionProxy
  sub_class.install_action_map action_map
  sub_class
end

Public Instance Methods

proxy_for_namespace(ns=nil) click to toggle source
# File lib/loom/mods/action_proxy.rb, line 12
def proxy_for_namespace(ns=nil)
  ns.nil? ? self : @nested_action_proxies[ns]
end