Class: Vigilem::Core::Stat
- Inherits:
-
Object
- Object
- Vigilem::Core::Stat
- 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
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#input_system_name ⇒ Object
readonly
Returns the value of attribute input_system_name.
-
#platform_masks ⇒ Object
readonly
Returns the value of attribute platform_masks.
Class Method Summary collapse
Instance Method Summary collapse
- #api_check?(*args, &block) ⇒ TrueClass || FalseClass
-
#available? ⇒ TrueClass || FalseClass
whether or not this input_system is avaialble on this system.
-
#available_on?(os) ⇒ TrueClass || FalseClass
(also: #is_available_on?)
whether or not this input_system is availble on given os.
- #gem_requirement ⇒ Object
- #initialize(input_system, gemname, opts = {}, &api_check) ⇒ Object constructor
- #install(version_requirement = nil) ⇒ Object
- #installed? ⇒ TrueClass || FalseCLass
Constructor Details
#initialize(input_system, gemname, opts = {}, &api_check) ⇒ Object
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_name ⇒ Object (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_name ⇒ Object (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_masks ⇒ Object (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_available ⇒ Array<Stat>
107 108 109 |
# File 'lib/vigilem/core/stat.rb', line 107 def all_available all.select(&:available?) end |
.new(*args, &block) ⇒ Object
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
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
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
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_requirement ⇒ Object
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
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
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 |