Class: TacoRc

Inherits:
Object show all
Defined in:
lib/taco/tacorc.rb

Overview

.taco/.tacorc describes properties of the taco repository contrast with ~/.taco_profile

Defined Under Namespace

Classes: ParseError

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ TacoRc

Returns a new instance of TacoRc.

Raises:

  • (ArgumentError)


7
8
9
10
# File 'lib/taco/tacorc.rb', line 7

def initialize(path)
  raise ArgumentError.new("no such file: #{path}") unless File.exists? path
  @path = path
end

Instance Method Details

#update_schema!(schema) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/taco/tacorc.rb', line 12

def update_schema!(schema)
  open(@path) do |f|
    f.readlines.each_with_index do |line, index|
      next if line =~ /^#/ || line =~ /^\s*$/
      raise ParseError.new("Parse error on line #{index+1} of #{@path}: line does not begin with schema_attr_update") unless line =~ /^\s*schema_attr_update /

      begin
        eval "#{schema}.#{line.strip}"
      rescue KeyError, TypeError, NameError => e
        raise ParseError.new("Parse error on line #{index+1} of #{@path}: #{e.to_s}")
      end
    end
  end
end