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
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 publish?
end
true
end
end
|
.publish=(val) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/test_ids.rb', line 110
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
106
107
108
|
# File 'lib/test_ids.rb', line 106
def publish?
@publish ? @publish == :save : true
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
|