Module: ActsAsArchive::Gems

Defined in:
lib/acts_as_archive/gems.rb

Defined Under Namespace

Classes: SimpleStruct

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



9
10
11
# File 'lib/acts_as_archive/gems.rb', line 9

def config
  @config
end

.gemsetObject

Returns the value of attribute gemset.



10
11
12
# File 'lib/acts_as_archive/gems.rb', line 10

def gemset
  @gemset
end

.gemsetsObject (readonly)

Returns the value of attribute gemsets.



10
11
12
# File 'lib/acts_as_archive/gems.rb', line 10

def gemsets
  @gemsets
end

.versionsObject (readonly)

Returns the value of attribute versions.



10
11
12
# File 'lib/acts_as_archive/gems.rb', line 10

def versions
  @versions
end

Class Method Details

.activate(*gems) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/acts_as_archive/gems.rb', line 30

def activate(*gems)
  begin
    require 'rubygems' unless defined?(::Gem)
  rescue LoadError
    puts "rubygems library could not be required" if @config.warn
  end

  self.gemset ||= gemset_from_loaded_specs

  gems.flatten.collect(&:to_sym).each do |name|
    version = @versions[name]
    vendor = File.expand_path("../../../vendor/#{name}/lib", __FILE__)
    if File.exists?(vendor)
      $:.unshift vendor
    elsif defined?(gem)
      gem name.to_s, version
    else
      puts "#{name} #{"(#{version})" if version} failed to activate" if @config.warn
    end
  end
end

.dependenciesObject



52
53
54
# File 'lib/acts_as_archive/gems.rb', line 52

def dependencies
  dependency_filter(@gemspec.dependencies, @gemset)
end

.development_dependenciesObject



56
57
58
# File 'lib/acts_as_archive/gems.rb', line 56

def development_dependencies
  dependency_filter(@gemspec.development_dependencies, @gemset)
end

.gemset_namesObject



89
90
91
92
93
94
95
96
97
# File 'lib/acts_as_archive/gems.rb', line 89

def gemset_names
  (
    [ :default ] +
    @gemsets[gemspec.name.to_sym].inject([]) { |array, (key, value)|
      array.push(key) if value.is_a?(::Hash) || value.nil?
      array
    }
  ).uniq
end

.gemspec(reload = false) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/acts_as_archive/gems.rb', line 99

def gemspec(reload=false)
  if @gemspec && !reload
    @gemspec
  else
    data = YAML::load(File.read(@config.gemspec)) rescue {}
    @gemspec = SimpleStruct.new(data)
  end
end