lapis_lazuli 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lapis_lazuli/runtime.rb +28 -6
- data/lib/lapis_lazuli/storage.rb +49 -7
- data/lib/lapis_lazuli/version.rb +1 -1
- data/lib/lapis_lazuli/world/browser.rb +22 -2
- data/lib/lapis_lazuli/world/config.rb +17 -5
- data/lib/lapis_lazuli/world/error.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed6ca8f1aa232bdc2014087496286902cae4f061
|
4
|
+
data.tar.gz: 8a9b24b75b4e148bd4b84531174c199ff76004e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d35e57fbe11bb803d15019b5e564aa96bdd5b9b6c27ab98364419475747b818777120cf3551aec7dbbccf0413fa09fd32ead27d915cea89f662f22828871b05
|
7
|
+
data.tar.gz: e1f684eb9fec6bc62e9a04e6e301d6c1f4949d931adf1e7cc799d77ae841aec8ae34779fd5278f0894a1cebef91e7b86a04d49d8a445edb15bbcb1be7199454a
|
data/lib/lapis_lazuli/runtime.rb
CHANGED
@@ -19,6 +19,12 @@ module LapisLazuli
|
|
19
19
|
@objects = {}
|
20
20
|
end
|
21
21
|
|
22
|
+
##
|
23
|
+
# Number of objects stored in the Runtime
|
24
|
+
def length
|
25
|
+
return @objects.keys.length
|
26
|
+
end
|
27
|
+
|
22
28
|
def has?(name)
|
23
29
|
return @objects.has_key? name
|
24
30
|
end
|
@@ -49,6 +55,12 @@ module LapisLazuli
|
|
49
55
|
return obj
|
50
56
|
end
|
51
57
|
|
58
|
+
##
|
59
|
+
# Remove an object from the Runtime
|
60
|
+
def unset(name)
|
61
|
+
@objects.delete(name)
|
62
|
+
end
|
63
|
+
|
52
64
|
def get(name)
|
53
65
|
return @objects[name]
|
54
66
|
end
|
@@ -57,6 +69,22 @@ module LapisLazuli
|
|
57
69
|
private
|
58
70
|
def self.destroy(world, name, destructor)
|
59
71
|
Proc.new do
|
72
|
+
# Try to run destroy on the object itself
|
73
|
+
obj = Runtime.instance.get(name)
|
74
|
+
|
75
|
+
#world.log.debug("Destroying #{name}")
|
76
|
+
|
77
|
+
# Do not destroy the logger until everything else has been stopped
|
78
|
+
if name == :logger and Runtime.instance.length > 1
|
79
|
+
#world.log.debug("This is the logger, wait until everything is closed")
|
80
|
+
break
|
81
|
+
end
|
82
|
+
Runtime.instance.unset(name)
|
83
|
+
|
84
|
+
if obj.respond_to?(:destroy)
|
85
|
+
obj.send(:destroy, world)
|
86
|
+
break
|
87
|
+
end
|
60
88
|
# If a destructor is given, call that.
|
61
89
|
if not destructor.nil?
|
62
90
|
return destructor.call(world)
|
@@ -76,12 +104,6 @@ module LapisLazuli
|
|
76
104
|
return world.send(name).destroy(world)
|
77
105
|
end
|
78
106
|
|
79
|
-
# Try to run destroy on the object itself
|
80
|
-
obj = Runtime.get(name)
|
81
|
-
if obj.respond_to? :destroy
|
82
|
-
return obj.send(:destroy)
|
83
|
-
end
|
84
|
-
|
85
107
|
# If the object has stream/socket functions close ends the connection
|
86
108
|
if obj.respond_to? :close
|
87
109
|
return obj.send(:close)
|
data/lib/lapis_lazuli/storage.rb
CHANGED
@@ -9,8 +9,14 @@ module LapisLazuli
|
|
9
9
|
##
|
10
10
|
# Simple storage class
|
11
11
|
class Storage
|
12
|
+
# The name of this storage container
|
13
|
+
@name
|
12
14
|
@data
|
13
|
-
|
15
|
+
|
16
|
+
##
|
17
|
+
# Initialize the storage with an optional name
|
18
|
+
def initialize(name=nil)
|
19
|
+
@name = name
|
14
20
|
@data = {}
|
15
21
|
end
|
16
22
|
|
@@ -28,7 +34,13 @@ module LapisLazuli
|
|
28
34
|
|
29
35
|
##
|
30
36
|
# Write all stored data to file
|
31
|
-
def writeToFile(filename)
|
37
|
+
def writeToFile(filename=nil)
|
38
|
+
if filename.nil? && @name.nil?
|
39
|
+
raise "Need a filename"
|
40
|
+
elsif filename.nil?
|
41
|
+
filename = "#{@name}.json"
|
42
|
+
end
|
43
|
+
|
32
44
|
# Make storage directory
|
33
45
|
dir = File.dirname(filename)
|
34
46
|
begin
|
@@ -41,17 +53,47 @@ module LapisLazuli
|
|
41
53
|
|
42
54
|
File.open(filename, 'w') { |file|
|
43
55
|
# Write the JSON to the file
|
44
|
-
file.
|
56
|
+
file.puts(@data.to_json)
|
45
57
|
}
|
46
58
|
end
|
47
59
|
|
48
60
|
##
|
49
61
|
# This will be called during the destruction of the world
|
50
62
|
def destroy(world)
|
51
|
-
|
52
|
-
|
53
|
-
world.
|
54
|
-
|
63
|
+
# No data to write
|
64
|
+
if @data.keys.length == 0
|
65
|
+
world.log.debug("Storage '#{@name}' is empty")
|
66
|
+
return
|
67
|
+
end
|
68
|
+
|
69
|
+
filename = nil
|
70
|
+
|
71
|
+
# If we have a name
|
72
|
+
if !@name.nil?
|
73
|
+
# Check the environment for a filename
|
74
|
+
env_value = world.env("#{@name}_file", nil)
|
75
|
+
if !env_value.nil?
|
76
|
+
filename = env_value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
# Otherwise, generate a name
|
80
|
+
if filename.nil?
|
81
|
+
# Folder to store in
|
82
|
+
filename += world.config("storage_dir", ".#{File::SEPARATOR}storage") + File::SEPARATOR
|
83
|
+
|
84
|
+
# Filename
|
85
|
+
if @name.nil?
|
86
|
+
# Use current timestamp and the object_id of the data
|
87
|
+
filename += world.time[:timestamp] + "_" + @data.object_id
|
88
|
+
else
|
89
|
+
# Use the given name
|
90
|
+
filename += @name
|
91
|
+
end
|
92
|
+
|
93
|
+
# JSON file extension
|
94
|
+
filename += ".json"
|
95
|
+
end
|
96
|
+
|
55
97
|
world.log.debug("Writing storage to: #{filename}")
|
56
98
|
self.writeToFile(filename)
|
57
99
|
end
|
data/lib/lapis_lazuli/version.rb
CHANGED
@@ -51,9 +51,29 @@ module WorldModule
|
|
51
51
|
b = Runtime.instance.set_if(self, :browser) do
|
52
52
|
# Add LL to the arguments for the browser
|
53
53
|
LapisLazuli::Browser.set_world(self)
|
54
|
-
|
54
|
+
|
55
55
|
# Create & return a new browser object
|
56
|
-
LapisLazuli::Browser.new(*args)
|
56
|
+
brow = LapisLazuli::Browser.new(*args)
|
57
|
+
|
58
|
+
metadata = Runtime.instance.get(:metadata)
|
59
|
+
if metadata
|
60
|
+
metadata.set(
|
61
|
+
"browser",
|
62
|
+
{
|
63
|
+
"name" => brow.driver.capabilities[:browser_name],
|
64
|
+
"version" => brow.driver.capabilities[:version],
|
65
|
+
"platform" => brow.driver.capabilities[:platform],
|
66
|
+
}
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
sessionid = brow.driver.capabilities["webdriver.remote.sessionid"]
|
71
|
+
|
72
|
+
if !sessionid.nil?
|
73
|
+
metadata.set("sessionid", sessionid)
|
74
|
+
end
|
75
|
+
|
76
|
+
brow
|
57
77
|
end
|
58
78
|
|
59
79
|
if not b.is_open?
|
@@ -7,6 +7,8 @@
|
|
7
7
|
#
|
8
8
|
|
9
9
|
require "lapis_lazuli/options"
|
10
|
+
require "lapis_lazuli/storage"
|
11
|
+
require "lapis_lazuli/runtime"
|
10
12
|
|
11
13
|
module LapisLazuli
|
12
14
|
module WorldModule
|
@@ -52,6 +54,18 @@ module WorldModule
|
|
52
54
|
warn "Could not load configuration from: #{Config.config_file}"
|
53
55
|
@config = {}
|
54
56
|
end
|
57
|
+
|
58
|
+
@metadata = Runtime.instance.set_if(self, :metadata) do
|
59
|
+
log.debug "Creating metadata storage"
|
60
|
+
Storage.new("metadata")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def metadata
|
65
|
+
if @metadata.nil?
|
66
|
+
raise "No metadata available"
|
67
|
+
end
|
68
|
+
return @metadata
|
55
69
|
end
|
56
70
|
|
57
71
|
|
@@ -179,7 +193,7 @@ module WorldModule
|
|
179
193
|
# ll.config("test.google.url") => "www.google.com"
|
180
194
|
#
|
181
195
|
# Raises error if traversing the object is impossible
|
182
|
-
def config(variable=false, default=nil)
|
196
|
+
def config(variable=false, default=(no_default_set=true;nil))
|
183
197
|
# Make sure the configured configuration is loaded, if possible
|
184
198
|
init
|
185
199
|
|
@@ -199,7 +213,7 @@ module WorldModule
|
|
199
213
|
|
200
214
|
# Otherwise try to find it in the configuration object
|
201
215
|
variable.split(".").each do |part|
|
202
|
-
if
|
216
|
+
if no_default_set == true && result.nil?
|
203
217
|
raise "Unknown configuration variable '#{variable}' and no default given!"
|
204
218
|
end
|
205
219
|
break if result.nil?
|
@@ -214,7 +228,7 @@ module WorldModule
|
|
214
228
|
if default.nil? and result.nil?
|
215
229
|
if CONFIG_OPTIONS.has_key? variable
|
216
230
|
return CONFIG_OPTIONS[variable][0]
|
217
|
-
|
231
|
+
elsif no_default_set == true
|
218
232
|
raise "Unknown configuration variable '#{variable}' and no default given!"
|
219
233
|
end
|
220
234
|
else
|
@@ -306,7 +320,6 @@ module WorldModule
|
|
306
320
|
# Variables like:
|
307
321
|
# var_from_env("remote.url","http://test.test")
|
308
322
|
if var.is_a? String and
|
309
|
-
var.include? "." and
|
310
323
|
not default.is_a? Hash
|
311
324
|
|
312
325
|
# Env variables cannot contain a . replace them by _
|
@@ -377,7 +390,6 @@ module WorldModule
|
|
377
390
|
|
378
391
|
return value
|
379
392
|
end
|
380
|
-
|
381
393
|
end # module Config
|
382
394
|
end # module WorldModule
|
383
395
|
end # module LapisLazuli
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lapis_lazuli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Onno Steenbergen
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-05-
|
14
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|