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.



29
30
31
32
33
# File 'lib/test_ids.rb', line 29

def allocate(instance, options = {})
  opts = options.dup
  current_configuration.allocator.allocate(instance, opts)
  { bin: opts[:bin], softbin: opts[:softbin], number: opts[:number] }
end

.configuration(id) ⇒ Object Also known as: config



39
40
41
42
# File 'lib/test_ids.rb', line 39

def configuration(id)
  return @configuration[id] if @configuration && @configuration[id]
  fail('You have to create the configuration first before you can access it')
end

.configure(id = nil, options = {}) {|config| ... } ⇒ Object

Yields:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/test_ids.rb', line 45

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

.configured?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/test_ids.rb', line 65

def configured?
  !!@configuration_id
end

.current_configurationObject



35
36
37
# File 'lib/test_ids.rb', line 35

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



81
82
83
84
85
86
87
88
89
90
# File 'lib/test_ids.rb', line 81

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

.gitObject



100
101
102
# File 'lib/test_ids.rb', line 100

def git
  @git
end

.git_database_dirObject



92
93
94
95
96
97
98
# File 'lib/test_ids.rb', line 92

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_gitObject



69
70
71
72
73
74
75
76
77
# File 'lib/test_ids.rb', line 69

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



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/test_ids.rb', line 123

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

Returns:

  • (Boolean)


119
120
121
# File 'lib/test_ids.rb', line 119

def publish?
  @publish ? @publish == :save : true
end

.repoObject



115
116
117
# File 'lib/test_ids.rb', line 115

def repo
  @repo
end

.repo=(val) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/test_ids.rb', line 104

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