Module: TestIds
- Defined in:
- lib/test_ids.rb,
lib/test_ids/git.rb,
lib/test_ids/allocator.rb,
lib/test_ids/bin_array.rb,
lib/test_ids/configuration.rb,
lib/test_ids/shutdown_handler.rb
Defined Under Namespace
Classes: Allocator, BinArray, Configuration, Git, ShutdownHandler
Class Method Summary
collapse
Class Method Details
.allocate(instance, options = {}) ⇒ Object
Allocates a number to the given test and returns a new hash containing
:bin, :softbin and :number keys.
The given options hash is not modified by calling this method.
Use the same arguments as you would normally pass to flow.test, the numbers
returned will be the same as would be injected into flow.test.
25
26
27
28
29
30
31
|
# File 'lib/test_ids.rb', line 25
def allocate(instance, options = {})
opts = options.dup
current_configuration.allocator.allocate(instance, opts)
{ bin: opts[:bin], bin_size: opts[:bin_size], softbin: opts[:softbin], softbin_size: opts[:softbin_size],
number: opts[:number], number_size: opts[:number_size]
}
end
|
.configuration(id) ⇒ Object
Also known as:
config
50
51
52
53
|
# File 'lib/test_ids.rb', line 50
def configuration(id)
return @configuration[id] if @configuration && @configuration[id]
fail('You have to create the configuration first before you can access it')
end
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/test_ids.rb', line 56
def configure(id = nil, options = {})
id, options = nil, id if id.is_a?(Hash)
@configuration_id = id || options[:id] || :not_specified
@configuration ||= {}
return if @configuration[@configuration_id]
@configuration[@configuration_id] = Configuration.new(@configuration_id)
config = @configuration[@configuration_id]
yield config
config.validate!
initialize_git
end
|
97
98
99
|
# File 'lib/test_ids.rb', line 97
def configured?
!!@configuration_id
end
|
.current_configuration ⇒ Object
46
47
48
|
# File 'lib/test_ids.rb', line 46
def current_configuration
configuration(@configuration_id)
end
|
.database_file(id) ⇒ Object
Returns a full path to the database file for the given id, returns nil if
git storage has not been enabled
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/test_ids.rb', line 113
def database_file(id)
if repo
if id == :not_specified || !id || id == ''
f = 'store.json'
else
f = "store_#{id.to_s.downcase}.json"
end
"#{git_database_dir}/#{f}"
end
end
|
.git ⇒ Object
132
133
134
|
# File 'lib/test_ids.rb', line 132
def git
@git
end
|
.git_database_dir ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/test_ids.rb', line 124
def git_database_dir
@git_database_dir ||= begin
d = "#{Origen.app.imports_directory}/test_ids/#{Pathname.new(repo).basename}"
FileUtils.mkdir_p(d)
d
end
end
|
.initialize_git ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/test_ids.rb', line 101
def initialize_git
@git_initialized ||= begin
if repo
@git = Git.new(local: git_database_dir, remote: repo)
git.get_lock if publish?
end
true
end
end
|
.load_allocator(id = nil) ⇒ Object
Load an existing allocator, which will be loaded with a configuration based on what has
been serialized into the database if present, otherwise it will have an empty configuration.
Returns nil if the given database can not be found.
.next_in_range(range, options) ⇒ Object
169
170
171
|
# File 'lib/test_ids.rb', line 169
def next_in_range(range, options)
current_configuration.allocator.next_in_range(range, options)
end
|
.publish=(val) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/test_ids.rb', line 155
def publish=(val)
return if @publish && publish? == val
if @publish && publish? != val
fail 'You can only use a single setting for publish per program generation run'
end
if @configuration
fail 'TestIds.publish must be set before creating the first configuration'
end
unless [true, false].include?(val)
fail 'TestIds.publish must be set to either true or false'
end
@publish = val ? :save : :dont_save
end
|
.publish? ⇒ Boolean
151
152
153
|
# File 'lib/test_ids.rb', line 151
def publish?
@publish ? @publish == :save : true
end
|
.repo ⇒ Object
147
148
149
|
# File 'lib/test_ids.rb', line 147
def repo
@repo
end
|
.repo=(val) ⇒ Object
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/test_ids.rb', line 136
def repo=(val)
return if @repo && @repo == val
if @repo && @repo != val
fail 'You can only use a single test ids repository per program generation run, one per application is recommended'
end
if @configuration
fail 'TestIds.repo must be set before creating the first configuration'
end
@repo = val
end
|