Class: Milkshake::Environment
- Inherits:
-
Object
- Object
- Milkshake::Environment
- Defined in:
- lib/milkshake/environment.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #gem_dependencies ⇒ Object
- #gemspecs ⇒ Object
- #gemspecs_by_name ⇒ Object
-
#initialize(cache, options = {}) ⇒ Environment
constructor
A new instance of Environment.
- #locale_paths ⇒ Object
- #reload! ⇒ Object
Constructor Details
#initialize(cache, options = {}) ⇒ Environment
Returns a new instance of Environment.
15 16 17 18 19 20 21 22 23 |
# File 'lib/milkshake/environment.rb', line 15 def initialize(cache, ={}) @cache = cache @options = {'gems' => {}}.merge() @options['gems']['rack-gem-assets'] = { 'lib' => 'rack/gem_assets' } Milkshake.extender.extend_rubygems! reload! end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5 6 7 |
# File 'lib/milkshake/environment.rb', line 5 def cache @cache end |
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
5 6 7 |
# File 'lib/milkshake/environment.rb', line 5 def gems @gems end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/milkshake/environment.rb', line 5 def @options end |
Class Method Details
.load(cache, path) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/milkshake/environment.rb', line 7 def self.load(cache, path) if File.exist?(path) new cache, YAML.load_file(path) else new cache end end |
Instance Method Details
#gem_dependencies ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/milkshake/environment.rb', line 69 def gem_dependencies @order.inject([]) do |deps, name| = @gems[name].inject({}) do |memo, (key, value)| memo[key.to_sym] = value memo end deps << Rails::GemDependency.new(name, ) end end |
#gemspecs ⇒ Object
63 64 65 66 67 |
# File 'lib/milkshake/environment.rb', line 63 def gemspecs @ordered_gemspecs ||= @order.collect do |name| gemspecs_by_name[name] end.compact end |
#gemspecs_by_name ⇒ Object
59 60 61 |
# File 'lib/milkshake/environment.rb', line 59 def gemspecs_by_name @gemspecs ||= {} end |
#locale_paths ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/milkshake/environment.rb', line 79 def locale_paths @cache.key('environment.locale_paths') do if Gem::Version.new(Rails.version) < Gem::Version.new("2.3.4") locale_paths = self.gemspecs.inject([]) do |paths, gemspec| locale_path = File.join(gemspec.full_gem_path, 'config', 'locales') if File.directory?(locale_path) paths.push(Dir[File.join(locale_path, '*.{rb,yml}')]) else paths end end locale_paths.flatten! else [] end end end |
#reload! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/milkshake/environment.rb', line 25 def reload! resolver = nil index = Gem::SourceIndex.from_installed_gems @gems = @cache.key('environment.gems') do resolver ||= DependencyResolver.load_for(@options['gems']) resolver.gems end @gemspecs = nil @gemspec_versions = @cache.key('environment.gemspec-versions') do resolver ||= DependencyResolver.load_for(@options['gems']) specs = resolver.specs @gemspecs = specs specs.inject({}) { |memo, (name, spec)| memo[name] = spec.version.to_s ; memo } end @gemspecs ||= @gemspec_versions.inject({}) do |memo, (name, version)| specs = index.search(Gem::Dependency.new(name, version)) specs.sort! do |left,right| right.version <=> left.version end memo[name] = specs.first memo end @order = @cache.key('environment.gems.order') do resolver ||= DependencyResolver.load_for(@options['gems']) resolver.names end @ordered_gemspecs = nil end |