Class: Vigilem::Core::Stat

Inherits:
Object
  • Object
show all
Extended by:
Support::ObjSpace
Defined in:
lib/vigilem/core/stat.rb

Overview

Stat(us) of the input_system and the handler gem associated with it

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_system, gemname, opts = {}, &api_check) ⇒ Object

Parameters:

  • input_system, (String)

    the descriptive name of the input_system

  • gemname, (String)

    the gem name of the handler to install

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

Options Hash (opts):

  • :platforms (Array<Regexp || Symbol>)
  • :requirement, (Object)

    defaults to Gem::Requirement.default



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vigilem/core/stat.rb', line 46

def initialize(input_system, gemname, opts={}, &api_check)
  @input_system_name = input_system
  @gem_name = gemname
  @gem_requirement = opts[:requirement] ||= Gem::Requirement.default
  
  @platform_masks = [*opts[:platforms] || /.+/].map do |plats| 
    if plats.is_a?(Symbol)
      System::SYSTEM_NAME_MASKS[plats]
    elsif plats.is_a?(Regexp)
      plats
    else
      raise NotImplementedError, "UnSupported type #{plats.class}:#{plats}"
    end
  end
  @api_check = api_check
end

Instance Attribute Details

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



15
16
17
# File 'lib/vigilem/core/stat.rb', line 15

def gem_name
  @gem_name
end

#input_system_nameObject (readonly)

Returns the value of attribute input_system_name.



15
16
17
# File 'lib/vigilem/core/stat.rb', line 15

def input_system_name
  @input_system_name
end

#platform_masksObject (readonly)

Returns the value of attribute platform_masks.



15
16
17
# File 'lib/vigilem/core/stat.rb', line 15

def platform_masks
  @platform_masks
end

Class Method Details

.all_availableArray<Stat>

Returns:



107
108
109
# File 'lib/vigilem/core/stat.rb', line 107

def all_available
  all.select(&:available?)
end

.new(*args, &block) ⇒ Object

Parameters:

  • gem_name (String)
  • opts (Hash)
  • api_check (Proc)

Returns:



26
27
28
# File 'lib/vigilem/core/stat.rb', line 26

def self.new(*args, &block)
  obj_register(super(*args, &block))
end

Instance Method Details

#api_check?(*args, &block) ⇒ TrueClass || FalseClass

Parameters:

  • args (Array)
  • block (Proc)

Returns:

  • (TrueClass || FalseClass)


34
35
36
# File 'lib/vigilem/core/stat.rb', line 34

def api_check?(*args, &block)
  !!api_check.call(*args, &block)
end

#available?TrueClass || FalseClass

whether or not this input_system is avaialble on this system

Returns:

  • (TrueClass || FalseClass)


98
99
100
# File 'lib/vigilem/core/stat.rb', line 98

def available?
  available_on?(System.os) and api_check?
end

#available_on?(os) ⇒ TrueClass || FalseClass Also known as: is_available_on?

whether or not this input_system is availble on given os

Parameters:

  • os (String || Regexp)

Returns:

  • (TrueClass || FalseClass)


72
73
74
# File 'lib/vigilem/core/stat.rb', line 72

def available_on?(os)
  System.check[:os][Regexp.union(platform_masks), os]
end

#gem_requirementObject



65
66
67
# File 'lib/vigilem/core/stat.rb', line 65

def gem_requirement
  @gem_requirement ||= Gem::Requirement.default
end

#install(version_requirement = nil) ⇒ Object

Parameters:

  • version_requirement,

    optional

Returns:



81
82
83
# File 'lib/vigilem/core/stat.rb', line 81

def install(version_requirement=nil)
  @installed = installer.install(gem_name, *version_requirement)
end

#installed?TrueClass || FalseCLass

Returns:

  • (TrueClass || FalseCLass)


87
88
89
90
91
92
93
# File 'lib/vigilem/core/stat.rb', line 87

def installed?
  if @installed.nil?
    @installed = Gem::Specification.find_all_by_name(gem_name, *gem_requirement).any?
  else
    @installed
  end
end