Class: Augment

Inherits:
Object show all
Defined in:
lib/augment.rb

Constant Summary collapse

VERSION =
'1.0.1'
BACKENDS =
{}
FRONTENDS =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, file) ⇒ Augment

Returns a new instance of Augment.



17
18
19
20
# File 'lib/augment.rb', line 17

def initialize(action, file)
  raise "No backend or frontend with that name." if action.nil?
  action.run(file)
end

Class Method Details

.augment_path(original) ⇒ Object

Where should the JSON layer files be given a file?



40
41
42
# File 'lib/augment.rb', line 40

def augment_path(original)
  "#{File.dirname(File.expand_path(original))}/.augment/#{File.basename(original)}"
end

.interactive(backend_names = 'test') ⇒ Object

Interactive mode allows you to repeatedly give augment a filename and have it spit back layer JSON immediately. By default only uses the test backend.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/augment.rb', line 27

def interactive(backend_names = 'test')
  loop do
    begin
      filename = STDIN.gets.chomp
      backend_names.each { |backend| BACKENDS[backend].run(filename) }
      puts "{\"#{filename}\" : #{File.read(augment_path(filename))} }"
    rescue
      puts "Error augmenting #{filename}."
    end
  end
end