Class: Swig

Inherits:
Object
  • Object
show all
Defined in:
lib/swig/swig.rb,
lib/swig/stream.rb,
lib/swig/worker.rb,
lib/swig/file_in_stream.rb

Defined Under Namespace

Classes: FileInStream, NoSuchTask, NoSwigFile, Stream, Worker

Class Method Summary collapse

Class Method Details

.cd_to_config_fileObject



30
31
32
33
34
35
36
# File 'lib/swig/swig.rb', line 30

def self.cd_to_config_file
  until File.exists?("swig_file.rb")
    Dir.chdir("../")

    raise NoSwigFile if Dir.pwd == "/"
  end
end

.dividerObject



42
43
44
# File 'lib/swig/swig.rb', line 42

def self.divider
  "=======================================".green
end

.invoke(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/swig/swig.rb', line 16

def self.invoke(name)
  @@tasks ||= {}

  block = @@tasks.fetch(name)

  time = (Benchmark.realtime do
    Swig::Stream.new.instance_eval(&block)
  end * 1000).round(2)

  show_message(name, time)
rescue KeyError
  raise NoSuchTask.new("task named \"#{name}\" doesn't exist")
end

.new_task(name, &block) ⇒ Object



10
11
12
13
14
# File 'lib/swig/swig.rb', line 10

def self.new_task(name, &block)
  @@tasks ||= {}

  @@tasks[name] = block
end

.tasksObject



38
39
40
# File 'lib/swig/swig.rb', line 38

def self.tasks
  @@tasks
end