Class: Freshener
- Inherits:
-
Object
- Object
- Freshener
- Includes:
- Freshen::Executable
- Defined in:
- lib/freshener.rb
Class Method Summary collapse
-
.all ⇒ Object
Returns a Hash of all installed fresheners.
-
.class_for(name) ⇒ Object
Get the class name for a freshener.
-
.ensure_installed!(*fresheners) ⇒ Object
Ensure that the specified fresheners are installed.
-
.installed?(*fresheners) ⇒ Boolean
Check that the specified fresheners are installed.
-
.instance_of(name) ⇒ Object
Returns an instance of the specified freshener.
-
.instances_of(*fresheners) ⇒ Object
Returns a Hash containing instances of the specified freshehers.
Instance Method Summary collapse
-
#freshen ⇒ Object
Example: >> rubygems = RubyGems.new >> rubygems.freshen => nil.
-
#needs_freshening? ⇒ Boolean
Whether or not we the freshener needs freshening up.
Methods included from Freshen::Executable
Class Method Details
.all ⇒ Object
Returns a Hash of all installed fresheners.
Example:
>> Freshener.all
=> { "rubygems" => #<RubyGems:0x00000000000000> }
17 18 19 20 21 |
# File 'lib/freshener.rb', line 17 def self.all fresheners = Dir.glob(File.join(Freshen::FRESHENERS_DIR, "*.rb")) fresheners.map! { |path| File.basename(path, ".rb") } instances_of(*fresheners) end |
.class_for(name) ⇒ Object
Get the class name for a freshener.
Arguments:
name: (String)
Example:
>> Freshener.class_for :ruby_gems
=> "RubyGems"
68 69 70 71 72 73 |
# File 'lib/freshener.rb', line 68 def self.class_for(name) klass = name.to_s.capitalize klass.gsub!(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase } klass.tr!("+", "x") klass end |
.ensure_installed!(*fresheners) ⇒ Object
Ensure that the specified fresheners are installed.
Arguments:
>> Freshener.ensure_installed! :ruby_gems
=> nil
121 122 123 124 125 126 127 128 129 |
# File 'lib/freshener.rb', line 121 def self.ensure_installed!(*fresheners) fresheners.each do |name| unless installed? name raise Freshen::FreshenerNotInstalled.new(name) end end nil end |
.installed?(*fresheners) ⇒ Boolean
Check that the specified fresheners are installed.
Arguments:
fresheners: (Splat)
Example:
>> Freshener.installed? :ruby_gems
=> true
107 108 109 110 111 112 113 |
# File 'lib/freshener.rb', line 107 def self.installed?(*fresheners) fresheners.each do |name| return false unless File.file? File.join(Freshen::FRESHENERS_DIR, "#{name}.rb") end true end |
.instance_of(name) ⇒ Object
Returns an instance of the specified freshener.
Arguments:
name: (String)
Example:
>> Freshener.instance_of :ruby_gems
=> #<RubyGems:0x00000000000000>
51 52 53 54 55 56 57 |
# File 'lib/freshener.rb', line 51 def self.instance_of(name) load_by_name(name) klass = class_for(name) klass = Object.const_get(klass) klass.new end |
.instances_of(*fresheners) ⇒ Object
Returns a Hash containing instances of the specified freshehers.
Example:
>> Freshener.instances_of :ruby_gems
=> { "rubygems" => #<RubyGems:0x00000000000000> }
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/freshener.rb', line 30 def self.instances_of(*fresheners) fresheners.sort_by! do |name| name end fresheners.map! do |name| [name.to_s, instance_of(name.to_s)] end Hash[*fresheners.flatten] end |
Instance Method Details
#freshen ⇒ Object
Example:
>> rubygems = RubyGems.new
>> rubygems.freshen
=> nil
153 154 155 |
# File 'lib/freshener.rb', line 153 def freshen raise Freshen::UpdateMethodNotImplementedError.new(self) end |
#needs_freshening? ⇒ Boolean
Whether or not we the freshener needs freshening up.
Example:
>> rubygems = RubyGems.new
>> rubygems.needs_freshening?
=> true
142 143 144 |
# File 'lib/freshener.rb', line 142 def needs_freshening? true end |