Class: Rucola::Dependencies

Inherits:
Object show all
Defined in:
lib/rucola/dependencies.rb,
lib/rucola/dependencies.rb,
lib/rucola/dependencies/exclusions.rb,
lib/rucola/dependencies/override_require_and_gem.rb

Defined Under Namespace

Classes: Dependency, RequiredFile

Constant Summary collapse

@@verbose =
true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependencies

Returns a new instance of Dependencies.



180
181
182
183
# File 'lib/rucola/dependencies.rb', line 180

def initialize
  @dependencies = []
  @exceptions = {}
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



177
178
179
# File 'lib/rucola/dependencies.rb', line 177

def dependencies
  @dependencies
end

#exceptionsObject (readonly)

Returns the value of attribute exceptions.



178
179
180
# File 'lib/rucola/dependencies.rb', line 178

def exceptions
  @exceptions
end

Class Method Details

.exclude(regexp) ⇒ Object



8
9
10
# File 'lib/rucola/dependencies/exclusions.rb', line 8

def exclude(regexp)
  exclusions << regexp
end

.exclude?(name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rucola/dependencies/exclusions.rb', line 12

def exclude?(name)
  exclusions.any? { |regexp| name =~ regexp }
end

.exclusionsObject



4
5
6
# File 'lib/rucola/dependencies/exclusions.rb', line 4

def exclusions
  @exclusions ||= []
end

.instanceObject



172
173
174
# File 'lib/rucola/dependencies.rb', line 172

def instance
  @instance ||= new
end

.load(dependencies_file) ⇒ Object

Loads dependencies from a file which uses ‘Rucola::Dependencies.run do … end’ to define dependencies.



163
164
165
166
# File 'lib/rucola/dependencies.rb', line 163

def load(dependencies_file)
  require dependencies_file
  instance
end

.override_require_and_gem!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rucola/dependencies/override_require_and_gem.rb', line 13

def self.override_require_and_gem!
  Kernel.module_eval do
    alias_method :__require_before_rucola_standalone_app, :require
    def require(name)
      return if name == 'rubygems' # atm we don't want to allow rubygems
      # check if there's an exception for this requirement and load it, otherwise load the original
      exception = Rucola::Dependencies.instance.exceptions[name] if Rucola::Dependencies.respond_to?(:instance) # check if everything is done loading
      __require_before_rucola_standalone_app(exception || name)
    end

    def gem(name, version)
      #puts "Gem required: #{name}"
      require(name)
    end
  end
end

.run(&block) ⇒ Object



168
169
170
# File 'lib/rucola/dependencies.rb', line 168

def run(&block)
  instance.instance_eval(&block)
end

.verboseObject



150
151
152
# File 'lib/rucola/dependencies.rb', line 150

def verbose
  @@verbose
end

.verbose=(value) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/rucola/dependencies.rb', line 153

def verbose=(value)
  if value
    $VERBOSE = true
  else
    $VERBOSE = nil
  end
  @@verbose = value
end

Instance Method Details

#copy_to(path, options = {}) ⇒ Object



237
238
239
# File 'lib/rucola/dependencies.rb', line 237

def copy_to(path, options = {})
  @dependencies.each {|dep| dep.copy_to(path, options) }
end

#dependency(name, version = '>=0') {|_self| ... } ⇒ Object

Specify dependencies of your application. Eg:

dependency 'net/http'

Or if it’s a gem you can also specify a specific version. (See the gem documentation about the possibilities). Eg:

dependency 'daemons', '1.0.7'

Yields:

  • (_self)

Yield Parameters:



195
196
197
198
# File 'lib/rucola/dependencies.rb', line 195

def dependency(name, version = '>=0')
  @dependencies << Dependency.new(name, version)
  yield self if block_given?
end

#exception(required_name, file_name) ⇒ Object

Sometimes there will be some libraries that just can’t be resolved. For these you can add exceptions: Eg:

# when "require 'xml-simple'" is called it will be replaced with "require 'xmlsimple'"
exception 'xml-simple', 'xmlsimple'

Or you can pass these in a block for grouping, but note that it’s exaclty the same as defining the exception outside of the block. Eg:

dependency 'activesupport' do
  # there's a problem with the gem being named 'xml-simple',
  # but the file is actually called 'xmlsimple'.
  exception 'xml-simple', 'xmlsimple'
end


215
216
217
# File 'lib/rucola/dependencies.rb', line 215

def exception(required_name, file_name)
  @exceptions[required_name] = file_name
end

#require!Object



219
220
221
# File 'lib/rucola/dependencies.rb', line 219

def require!
  @dependencies.each {|dep| dep.require! }
end

#required_files(*types) ⇒ Object

Requires an array of all the required files with any duplicates removed. TODO: Check if using this will save a lot of time while copying, because atm files might be copied multiple times.



230
231
232
233
234
235
# File 'lib/rucola/dependencies.rb', line 230

def required_files(*types)
  files = @dependencies.collect {|dep| dep.required_files_of_types(types) }.flatten
  unique_files = []
  files.each { |file| unique_files << file unless unique_files.include?(file) }
  unique_files
end

#resolve!Object



223
224
225
# File 'lib/rucola/dependencies.rb', line 223

def resolve!
  @dependencies.each {|dep| dep.resolve! }
end