Module: Vigilem::Assembly

Defined in:
lib/vigilem/assembly.rb,
lib/vigilem/assembly/version.rb,
lib/vigilem/assembly/dom_keyboard.rb

Defined Under Namespace

Classes: DOMKeyboard, NoAvailableHandler

Constant Summary collapse

VERSION =
"0.0.13"

Class Method Summary collapse

Class Method Details

.find_stat(opts = {}, &block) ⇒ Stat || NilClass

find’s an available handler

Parameters:

  • opts (Hash) (defaults to: {})
  • block (Proc)

Options Hash (opts):

  • :platform_defaults (Array<Regexp || String, Array<String> || String>)

    [os_pattern, gem_name], the default gem for os_pattern, if os_pattern matches this os and there are mulitple handlers available, install this gem_name and raises ArgumentError when the default matches more than one Stat

Returns:

  • (Stat || NilClass)

Raises:

  • ArgumentError, when the platform default matches more than one Stat



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vigilem/assembly.rb', line 49

def find_stat(opts={}, &block)
  stats = Core::Stat.all_available
  # @fixme just grabs first
  stat = if stats.size > 1
    [*opts[:platform_defaults]].map do |os_pattern, gem_name| 
      if System.check[:os][os_pattern]
        stats.select {|stat| stat.gem_name == gem_name }
        if stats.size > 1
          raise ArgumentError, "multiple handlers match :platform_defaults"\
                            "#{os_pattern} => #{gem_name} matches #{stats}"
        else
          stats.first
        end
      end
    end.flatten.compact.first
  else
    stats.first
  end
end

.install_handler(opts = {}, &block) ⇒ Object

find’s an available handler and installs it

Parameters:

  • opts (Hash) (defaults to: {})
  • block (Proc)

Options Hash (opts):

  • :platform_defaults (Array<Regexp || String, String>)

    [os_pattern, gem_name], the default gem for os_pattern, if os_pattern matches this os and there are mulitple handlers available, install this gem_name and raises ArgumentError when the default matches more than one Stat

Returns:

  • the return value of stat.install

Raises:

  • NoAvailableHandler, when the platform default matches more than one Stat



26
27
28
29
# File 'lib/vigilem/assembly.rb', line 26

def install_handler(opts={}, &block)
  stat = find_stat(opts, &block)
  stat.install
end

.install_handler!(opts = {}, &block) ⇒ Object

like ::install_handler but throws an NoHandlerAvailable

Raises:

See Also:

  • install_hadler


34
35
36
37
38
# File 'lib/vigilem/assembly.rb', line 34

def install_handler!(opts={}, &block)
  stat = find_stat(opts, &block)
  raise NoAvailableHandler unless stat
  stat.install
end