Class: MultiRails::Loader
- Inherits:
-
Object
- Object
- MultiRails::Loader
- Defined in:
- lib/multi_rails/loader.rb
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.all_rails_versions ⇒ Object
Returns a list of all Rails versions available, oldest first.
-
.gem_and_require_rails(rails_version = nil) ⇒ Object
Require and gem rails Will use a default version if none is supplied.
-
.latest_stable_version ⇒ Object
Try to detech the latest stable by finding the most recent version with less then 4 version parts – not sure if there is a better way?.
-
.latest_version ⇒ Object
Find the most recent version.
- .logger ⇒ Object
Instance Method Summary collapse
-
#display_rails_gem_used ⇒ Object
Display the rails gem from the laod path, as a sanity check to make sure we are getting the rails version we expect.
-
#gem_and_require_rails ⇒ Object
Gem a version of Rails, and require appropriate files.
- #gem_rails ⇒ Object
-
#initialize(version) ⇒ Loader
constructor
A version of the loader is created to gem and require one version of Rails.
- #require_rails ⇒ Object
Constructor Details
#initialize(version) ⇒ Loader
A version of the loader is created to gem and require one version of Rails
35 36 37 |
# File 'lib/multi_rails/loader.rb', line 35 def initialize(version) @version = version end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/multi_rails/loader.rb', line 4 def version @version end |
Class Method Details
.all_rails_versions ⇒ Object
Returns a list of all Rails versions available, oldest first
18 19 20 21 |
# File 'lib/multi_rails/loader.rb', line 18 def self.all_rails_versions specs = Gem::cache.find_name("rails") specs.map {|spec| spec.version.to_s }.sort end |
.gem_and_require_rails(rails_version = nil) ⇒ Object
Require and gem rails Will use a default version if none is supplied
12 13 14 15 |
# File 'lib/multi_rails/loader.rb', line 12 def self.gem_and_require_rails(rails_version = nil) rails_version = MultiRails::Config.version_lookup(rails_version) Loader.new(rails_version).gem_and_require_rails end |
.latest_stable_version ⇒ Object
Try to detech the latest stable by finding the most recent version with less then 4 version parts
-- not sure if there is a better way?
25 26 27 |
# File 'lib/multi_rails/loader.rb', line 25 def self.latest_stable_version all_rails_versions.sort.reverse.detect {|version| version.count(".") < 3 } end |
.latest_version ⇒ Object
Find the most recent version
30 31 32 |
# File 'lib/multi_rails/loader.rb', line 30 def self.latest_version all_rails_versions.sort.last end |
.logger ⇒ Object
6 7 8 |
# File 'lib/multi_rails/loader.rb', line 6 def self.logger @logger ||= Logger.new(STDOUT) end |
Instance Method Details
#display_rails_gem_used ⇒ Object
Display the rails gem from the laod path, as a sanity check to make sure we are getting the rails version we expect
47 48 49 |
# File 'lib/multi_rails/loader.rb', line 47 def display_rails_gem_used puts %[#{MultiRails::BAR}\nUsing rails gem: #{Config.rails_load_path}\n] end |
#gem_and_require_rails ⇒ Object
Gem a version of Rails, and require appropriate files
40 41 42 43 44 |
# File 'lib/multi_rails/loader.rb', line 40 def gem_and_require_rails gem_rails require_rails display_rails_gem_used end |
#gem_rails ⇒ Object
51 52 53 54 55 56 |
# File 'lib/multi_rails/loader.rb', line 51 def gem_rails gem 'rails', version rescue LoadError => e msg = %Q[Cannot find gem for Rails version: '#{version}'!\nInstall the missing gem with:\nsudo gem install -v=#{version} rails] raise MultiRailsError, msg end |
#require_rails ⇒ Object
58 59 60 |
# File 'lib/multi_rails/loader.rb', line 58 def require_rails Config.rails_requires.each {|lib| require lib } end |