Class: Perkins::Build::Data::Var

Inherits:
Object
  • Object
show all
Defined in:
lib/perkins/build/data/var.rb

Constant Summary collapse

PATTERN =
/(?:SECURE )?([\w]+)=(("|')(.*?)(\3)|\$\(.*?\)|[^"' ]+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, secure = nil) ⇒ Var

Returns a new instance of Var.



24
25
26
27
28
# File 'lib/perkins/build/data/var.rb', line 24

def initialize(key, value, secure = nil)
  @key = key.to_s
  @value = value.to_s
  @secure = secure
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



22
23
24
# File 'lib/perkins/build/data/var.rb', line 22

def value
  @value
end

Class Method Details

.create(*args) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/perkins/build/data/var.rb', line 8

def create(*args)
  if args.size == 1
    parse(args.first).map { |key, value| Var.new(key, value) }
  else
    [Var.new(*args)]
  end
end

.parse(line) ⇒ Object



16
17
18
19
# File 'lib/perkins/build/data/var.rb', line 16

def parse(line)
  secure = line =~ /^SECURE /
  line.scan(PATTERN).map { |match| [(secure ? "SECURE #{match[0]}" : match[0]), match[1]] }
end

Instance Method Details

#keyObject



30
31
32
# File 'lib/perkins/build/data/var.rb', line 30

def key
  strip_secure(@key)
end

#secure?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/perkins/build/data/var.rb', line 48

def secure?
  @secure.nil? ? @key =~ /^SECURE / : @secure
end

#to_sObject



34
35
36
37
38
39
40
41
42
# File 'lib/perkins/build/data/var.rb', line 34

def to_s
  if travis?
    false
  elsif secure?
    "export #{[key, '[secure]'].join('=')}"
  else
    "export #{[key, value].join('=')}"
  end
end

#travis?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/perkins/build/data/var.rb', line 44

def travis?
  @key =~ /^TRAVIS_/
end