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
.configuration(id) ⇒ Object
Also known as:
config
26
27
28
29
|
# File 'lib/test_ids.rb', line 26
def configuration(id)
return @configuration[id] if @configuration && @configuration[id]
fail('You have to create the configuration first before you can access it')
end
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/test_ids.rb', line 32
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
|
52
53
54
|
# File 'lib/test_ids.rb', line 52
def configured?
!!@configuration_id
end
|
.current_configuration ⇒ Object
22
23
24
|
# File 'lib/test_ids.rb', line 22
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
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/test_ids.rb', line 68
def database_file(id)
if repo && on_completion == :save
if id == :not_specified
f = 'store.json'
else
f = "store_#{id.to_s.downcase}.json"
end
"#{git_database_dir}/#{f}"
end
end
|
.git ⇒ Object
87
88
89
|
# File 'lib/test_ids.rb', line 87
def git
@git
end
|
.git_database_dir ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/test_ids.rb', line 79
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
56
57
58
59
60
61
62
63
64
|
# File 'lib/test_ids.rb', line 56
def initialize_git
@git_initialized ||= begin
if repo
@git = Git.new(local: git_database_dir, remote: repo)
git.get_lock if on_completion == :save
end
true
end
end
|
.on_completion ⇒ Object
Returns what should be done with the database for the given configuration
at the end, :save (the default) or :discard.
If a repo has not been specified, then this attribute has no effect and the
data will always be discarded.
111
112
113
|
# File 'lib/test_ids.rb', line 111
def on_completion
@on_completion || :save
end
|
.on_completion=(val) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/test_ids.rb', line 115
def on_completion=(val)
return if @on_completion && @on_completion == val
if @on_completion && @on_completion != val
fail 'You can only use a single setting for on_completion per program generation run'
end
if @configuration
fail 'TestIds.on_completion must be set before creating the first configuration'
end
unless %w(save discard).include?(val.to_s)
fail 'on_completion must be set to either :save or :discard'
end
@on_completion = val.to_sym
end
|
.repo ⇒ Object
102
103
104
|
# File 'lib/test_ids.rb', line 102
def repo
@repo
end
|
.repo=(val) ⇒ Object
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/test_ids.rb', line 91
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
|