-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathstash.rb
More file actions
24 lines (24 loc) · 929 Bytes
/
stash.rb
File metadata and controls
24 lines (24 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Stash API is useful for storing simple key/value pairs
# to preserve state between script runs
stash_set('key1', 'val1')
puts "key1: #{stash_get('key1')}"
stash_set('key2', 'val2')
puts "key2: #{stash_get('key2')}"
check_expression("'#{stash_get('key1')}' == 'val1'")
check_expression("'#{stash_get('key2')}' == 'val2'")
stash_set('key1', 1)
stash_set('key2', 2)
check_expression("'#{stash_get('key1')}' == '1'")
check_expression("'#{stash_get('key2')}' == '2'")
stash_delete('key2')
check_expression("#{stash_get('key2').nil?} == true")
stash_delete('key1')
data = [1,2,[3,4]]
stash_set('ary', data)
check_expression("'#{stash_get('ary')}' == '#{data.to_s}'")
stash_delete('ary')
# Note: hashes with symbol keys works but get converted to string keys on stash_get
hash = { 'one' => 1, 'two' => 2, 'string' => 'string' }
stash_set('hash', hash)
check_expression("'#{stash_get('hash')}' == '#{hash.to_s}'")
stash_delete('hash')