gene_system 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gene_system/cli.rb +24 -0
- data/lib/gene_system/commands/helpers.rb +107 -0
- data/lib/gene_system/commands/install_manifest.rb +4 -39
- data/lib/gene_system/commands/remove_manifest.rb +4 -39
- data/lib/gene_system/manifest.rb +4 -18
- data/lib/gene_system/step_collection.rb +95 -0
- data/lib/gene_system/version.rb +1 -1
- data/lib/gene_system.rb +1 -0
- data/spec/gene_system/commands/helpers_spec.rb +97 -0
- data/spec/gene_system/commands/install_manifest_spec.rb +8 -2
- data/spec/gene_system/manifest_spec.rb +1 -17
- data/spec/gene_system/step_collection_spec.rb +199 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aa7960e15136bb83ad4d59cee4f04eb90329849e4afb122b71aa3c154221061
|
4
|
+
data.tar.gz: fd63a576848edc472d677278fbe0e59014fbefbc2341e8dc63accf6b8539fd8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8fa68614f9a03faa1e4e79bafe180e30016b913d0f5d92216295f252c83e0564941b4f16a6acc2ae3a9e52b28a028c8db58b777e2d3ba89154f9294785837ba
|
7
|
+
data.tar.gz: 43dce4572183820584a8c1a0a9c0d2f28cc6f33eb85d123b9f973c220ea1fef8f6bd1a05e24c9a04452399713f46444718d41626e13c829f0d993e28584d053b
|
data/Gemfile.lock
CHANGED
data/lib/gene_system/cli.rb
CHANGED
@@ -43,6 +43,18 @@ module GeneSystem
|
|
43
43
|
desc: 'Path to manifest (i.e. manifest.json)'
|
44
44
|
)
|
45
45
|
|
46
|
+
method_option(
|
47
|
+
:include_tags,
|
48
|
+
type: :array,
|
49
|
+
desc: 'List of tags to include'
|
50
|
+
)
|
51
|
+
|
52
|
+
method_option(
|
53
|
+
:exclude_tags,
|
54
|
+
type: :array,
|
55
|
+
desc: 'List of tags to exclude'
|
56
|
+
)
|
57
|
+
|
46
58
|
def install
|
47
59
|
cmd = GeneSystem::Commands::InstallManifest.new(options)
|
48
60
|
cmd.run
|
@@ -56,6 +68,18 @@ module GeneSystem
|
|
56
68
|
desc: 'Path to manifest (i.e. manifest.json)'
|
57
69
|
)
|
58
70
|
|
71
|
+
method_option(
|
72
|
+
:include_tags,
|
73
|
+
type: :array,
|
74
|
+
desc: 'List of tags to include'
|
75
|
+
)
|
76
|
+
|
77
|
+
method_option(
|
78
|
+
:exclude_tags,
|
79
|
+
type: :array,
|
80
|
+
desc: 'List of tags to exclude'
|
81
|
+
)
|
82
|
+
|
59
83
|
def remove
|
60
84
|
cmd = GeneSystem::Commands::RemoveManifest.new(options)
|
61
85
|
cmd.run
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module GeneSystem
|
2
|
+
module Commands
|
3
|
+
# Install/Remove shared helper functions
|
4
|
+
module Helpers
|
5
|
+
##
|
6
|
+
# Asks for user input when given prompts
|
7
|
+
#
|
8
|
+
# @param prompts [Array]
|
9
|
+
#
|
10
|
+
# @return Hashie::Mash
|
11
|
+
#
|
12
|
+
def ask(prompts = [])
|
13
|
+
answers = @manifest.variables
|
14
|
+
return answers if prompts.nil? || prompts.empty?
|
15
|
+
|
16
|
+
prompts.each do |prompt|
|
17
|
+
resp = @prompt.ask(prompt.prompt)
|
18
|
+
answers[prompt.var] = resp
|
19
|
+
end
|
20
|
+
|
21
|
+
answers
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Determines whether to skip a step
|
26
|
+
#
|
27
|
+
# @param [GeneSystem::Step] step
|
28
|
+
# @param [GeneSystem::Platform] platform
|
29
|
+
#
|
30
|
+
# @return [Boolean]
|
31
|
+
#
|
32
|
+
def skip?(direction, step, platform)
|
33
|
+
return false if step.send(direction).skip.nil?
|
34
|
+
|
35
|
+
platform.execute_command(
|
36
|
+
step.send(direction).skip
|
37
|
+
).zero?
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Returns manifest steps that match command
|
42
|
+
# options
|
43
|
+
#
|
44
|
+
# If there are no inclusions or exclusions then
|
45
|
+
# all of the steps are returned.
|
46
|
+
#
|
47
|
+
# If there is an include and/or an exclude filter
|
48
|
+
# then the steps are filtered
|
49
|
+
#
|
50
|
+
# @return [GeneSystem::StepCollection]
|
51
|
+
#
|
52
|
+
def steps
|
53
|
+
steps = @manifest.steps
|
54
|
+
return steps unless filters?
|
55
|
+
|
56
|
+
filters.each do |matcher, tags|
|
57
|
+
steps = steps.filter(
|
58
|
+
matcher, tags: tags
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
steps
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Constructs a filter function hash
|
67
|
+
#
|
68
|
+
# The key of the hash is the filter function
|
69
|
+
# and the value is the tags to filter by
|
70
|
+
#
|
71
|
+
# If no inclusions or exclusions are specified
|
72
|
+
# then an empty hash is returned
|
73
|
+
#
|
74
|
+
# @return [Hash]
|
75
|
+
#
|
76
|
+
def filters
|
77
|
+
filters = {}
|
78
|
+
|
79
|
+
if @options.include_tags
|
80
|
+
filters[StepCollection::STEP_INCLUDE_ANY_TAG] = @options.include_tags
|
81
|
+
end
|
82
|
+
|
83
|
+
if @options.exclude_tags
|
84
|
+
filters[StepCollection::STEP_EXCLUDE_ANY_TAG] = @options.exclude_tags
|
85
|
+
end
|
86
|
+
|
87
|
+
filters
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Returns true when an inclusion filter
|
92
|
+
# and/or an exclusion filter is specified
|
93
|
+
# in command options.
|
94
|
+
#
|
95
|
+
# Otherwise it returns false
|
96
|
+
#
|
97
|
+
# @return [Boolean]
|
98
|
+
#
|
99
|
+
def filters?
|
100
|
+
return true if @options.include_tags
|
101
|
+
return true if @options.exclude_tags
|
102
|
+
|
103
|
+
false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -2,6 +2,8 @@ module GeneSystem
|
|
2
2
|
module Commands
|
3
3
|
# Install manifest command
|
4
4
|
class InstallManifest
|
5
|
+
include GeneSystem::Commands::Helpers
|
6
|
+
|
5
7
|
##
|
6
8
|
# Default name of gene system manifest
|
7
9
|
#
|
@@ -29,8 +31,8 @@ module GeneSystem
|
|
29
31
|
|
30
32
|
puts("INSTALL #{@manifest.name_and_version}")
|
31
33
|
|
32
|
-
|
33
|
-
next if skip?(step, platform)
|
34
|
+
steps.each do |step|
|
35
|
+
next if skip?(:install, step, platform)
|
34
36
|
|
35
37
|
vars = ask(step.install.prompts)
|
36
38
|
|
@@ -44,43 +46,6 @@ module GeneSystem
|
|
44
46
|
"✔ Manifest #{@manifest.name_and_version} successfully installed"
|
45
47
|
)
|
46
48
|
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
##
|
51
|
-
# Asks for user input when given prompts
|
52
|
-
#
|
53
|
-
# @param prompts [Array]
|
54
|
-
#
|
55
|
-
# @return Hashie::Mash
|
56
|
-
#
|
57
|
-
def ask(prompts = [])
|
58
|
-
answers = @manifest.variables
|
59
|
-
return answers if prompts.nil? || prompts.empty?
|
60
|
-
|
61
|
-
prompts.each do |prompt|
|
62
|
-
resp = @prompt.ask(prompt.prompt)
|
63
|
-
answers[prompt.var] = resp
|
64
|
-
end
|
65
|
-
|
66
|
-
answers
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Determines whether to skip a step
|
71
|
-
#
|
72
|
-
# @param [GeneSystem::Step] step
|
73
|
-
# @param [GeneSystem::Platform] platform
|
74
|
-
#
|
75
|
-
# @return [Boolean]
|
76
|
-
#
|
77
|
-
def skip?(step, platform)
|
78
|
-
return false if step.install.skip.nil?
|
79
|
-
|
80
|
-
platform.execute_command(
|
81
|
-
step.install.skip
|
82
|
-
).zero?
|
83
|
-
end
|
84
49
|
end
|
85
50
|
end
|
86
51
|
end
|
@@ -2,6 +2,8 @@ module GeneSystem
|
|
2
2
|
module Commands
|
3
3
|
# Remove manifest command
|
4
4
|
class RemoveManifest
|
5
|
+
include GeneSystem::Commands::Helpers
|
6
|
+
|
5
7
|
##
|
6
8
|
# Default name of gene system manifest
|
7
9
|
#
|
@@ -29,8 +31,8 @@ module GeneSystem
|
|
29
31
|
|
30
32
|
puts("REMOVE #{@manifest.name_and_version}")
|
31
33
|
|
32
|
-
|
33
|
-
next if skip?(step, platform)
|
34
|
+
steps.each do |step|
|
35
|
+
next if skip?(:remove, step, platform)
|
34
36
|
|
35
37
|
vars = ask(step.remove.prompts)
|
36
38
|
|
@@ -44,43 +46,6 @@ module GeneSystem
|
|
44
46
|
"✔ Manifest #{@manifest.name_and_version} successfully removed"
|
45
47
|
)
|
46
48
|
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
##
|
51
|
-
# Asks for user input when given prompts
|
52
|
-
#
|
53
|
-
# @param prompts [Array]
|
54
|
-
#
|
55
|
-
# @return Hashie::Mash
|
56
|
-
#
|
57
|
-
def ask(prompts = [])
|
58
|
-
answers = @manifest.variables
|
59
|
-
return answers if prompts.nil?
|
60
|
-
|
61
|
-
prompts.each do |prompt|
|
62
|
-
resp = @prompt.ask(prompt.prompt)
|
63
|
-
answers[prompt.var] = resp
|
64
|
-
end
|
65
|
-
|
66
|
-
answers
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Determines whether to skip a step
|
71
|
-
#
|
72
|
-
# @param [GeneSystem::Step] step
|
73
|
-
# @param [GeneSystem::Platform] platform
|
74
|
-
#
|
75
|
-
# @return [Boolean]
|
76
|
-
#
|
77
|
-
def skip?(step, platform)
|
78
|
-
return false if step.remove.skip.nil?
|
79
|
-
|
80
|
-
platform.execute_command(
|
81
|
-
step.remove.skip
|
82
|
-
).zero?
|
83
|
-
end
|
84
49
|
end
|
85
50
|
end
|
86
51
|
end
|
data/lib/gene_system/manifest.rb
CHANGED
@@ -144,26 +144,12 @@ module GeneSystem
|
|
144
144
|
end
|
145
145
|
|
146
146
|
##
|
147
|
-
#
|
148
|
-
# return a list of steps relevant to an operation.
|
147
|
+
# Returns a steps as a step collection
|
149
148
|
#
|
150
|
-
#
|
151
|
-
# should be in the return set.
|
149
|
+
# @return [GeneSystem::StepCollection]
|
152
150
|
#
|
153
|
-
|
154
|
-
|
155
|
-
# Example:
|
156
|
-
# query = ->(step) { step.tags.include?("foo") }
|
157
|
-
# manifest.steps(query)
|
158
|
-
#
|
159
|
-
# @param [Lambda] query
|
160
|
-
#
|
161
|
-
# @return [Array]
|
162
|
-
#
|
163
|
-
def steps(query = DEFAULT_QUERY)
|
164
|
-
@steps.select do |step|
|
165
|
-
query.call(step)
|
166
|
-
end
|
151
|
+
def steps
|
152
|
+
GeneSystem::StepCollection.new(@steps)
|
167
153
|
end
|
168
154
|
|
169
155
|
##
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module GeneSystem
|
4
|
+
# Filterable and mergable collection of steps
|
5
|
+
class StepCollection
|
6
|
+
attr_reader :steps
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
##
|
10
|
+
# Default filter will match each step
|
11
|
+
#
|
12
|
+
DEFAULT_QUERY = lambda do |_step, _query = {}|
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Function that returns true if step has
|
18
|
+
# any of the provided tags
|
19
|
+
#
|
20
|
+
# @param [GeneSystem::Step] step
|
21
|
+
# @param [Hash] query
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
#
|
25
|
+
STEP_INCLUDE_ANY_TAG = lambda do |step, query = {}|
|
26
|
+
raise 'query must include tags' unless query[:tags]&.is_a?(Array)
|
27
|
+
|
28
|
+
results = query[:tags].map do |tag|
|
29
|
+
step.tags.include?(tag)
|
30
|
+
end
|
31
|
+
|
32
|
+
results.any?(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Function that returns true if step does
|
37
|
+
# not have any of the provided tags
|
38
|
+
#
|
39
|
+
# @param [GeneSystem::Step] step
|
40
|
+
# @param [Hash] query
|
41
|
+
#
|
42
|
+
# @return [Boolean]
|
43
|
+
#
|
44
|
+
STEP_EXCLUDE_ANY_TAG = lambda do |step, query = {}|
|
45
|
+
raise 'query must include tags' unless query[:tags]&.is_a?(Array)
|
46
|
+
|
47
|
+
results = query[:tags].map do |tag|
|
48
|
+
step.tags.include?(tag)
|
49
|
+
end
|
50
|
+
|
51
|
+
results.all?(false)
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize(steps = [])
|
55
|
+
@steps = steps
|
56
|
+
end
|
57
|
+
|
58
|
+
def_delegators(:@steps, :count, :map, :each)
|
59
|
+
|
60
|
+
##
|
61
|
+
# Filters steps by given matcher function
|
62
|
+
#
|
63
|
+
# The matcher function must take a step as an
|
64
|
+
# argument and return true or false as to whether
|
65
|
+
# it should be in the returned collection.
|
66
|
+
#
|
67
|
+
# @param [Proc] matcher
|
68
|
+
# @param [Hash] query
|
69
|
+
#
|
70
|
+
# @returns [GeneSystem::StepCollection]
|
71
|
+
#
|
72
|
+
def filter(matcher = DEFAULT_FILTER, query = {})
|
73
|
+
GeneSystem::StepCollection.new(
|
74
|
+
@steps.select do |step|
|
75
|
+
matcher.call(step, query)
|
76
|
+
end
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Creates a collection which is a union
|
82
|
+
# of the given collection and this
|
83
|
+
# collection.
|
84
|
+
#
|
85
|
+
# @param [GeneSystem::StepCollection] collection
|
86
|
+
#
|
87
|
+
# @return [GeneSystem::StepCollection]
|
88
|
+
#
|
89
|
+
def merge(collection)
|
90
|
+
GeneSystem::StepCollection.new(
|
91
|
+
@steps + collection.steps
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/gene_system/version.rb
CHANGED
data/lib/gene_system.rb
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe GeneSystem::Commands::Helpers do
|
4
|
+
let(:manifest) { double(GeneSystem::Manifest) }
|
5
|
+
let(:step) { double(GeneSystem::Step) }
|
6
|
+
let(:steps) { [step, step] }
|
7
|
+
let(:options) { Hashie::Mash.new }
|
8
|
+
|
9
|
+
subject { GeneSystem::Commands::RemoveManifest.new(options) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
subject.instance_variable_set(:@manifest, manifest)
|
13
|
+
allow(manifest).to receive(:steps).and_return(steps)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#steps' do
|
17
|
+
context 'when there are no filters' do
|
18
|
+
it 'returns all manifest steps' do
|
19
|
+
expect(subject.steps).to eq steps
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when there are filters' do
|
24
|
+
let(:options) do
|
25
|
+
Hashie::Mash.new(exclude_tags: %w[bags of tags])
|
26
|
+
end
|
27
|
+
|
28
|
+
before do
|
29
|
+
allow(steps).to receive(:filter)
|
30
|
+
subject.steps
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'filters steps' do
|
34
|
+
expect(steps)
|
35
|
+
.to have_received(:filter)
|
36
|
+
.with(
|
37
|
+
GeneSystem::StepCollection::STEP_EXCLUDE_ANY_TAG,
|
38
|
+
tags: %w[bags of tags]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#filters' do
|
45
|
+
context 'when include_tags is enabled' do
|
46
|
+
let(:options) do
|
47
|
+
Hashie::Mash.new(include_tags: %w[bags of tags])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'has STEP_INCLUDE_ANY_TAG function and tags' do
|
51
|
+
expect(subject.filters).to eq(
|
52
|
+
GeneSystem::StepCollection::STEP_INCLUDE_ANY_TAG => %w[bags of tags]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when exclude_tags is enabled' do
|
58
|
+
let(:options) do
|
59
|
+
Hashie::Mash.new(exclude_tags: %w[bags of tags])
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has STEP_EXCLUDE_ANY_TAG function and tags' do
|
63
|
+
expect(subject.filters).to eq(
|
64
|
+
GeneSystem::StepCollection::STEP_EXCLUDE_ANY_TAG => %w[bags of tags]
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#filters?' do
|
71
|
+
context 'when neither include_tags or exclude_tags' do
|
72
|
+
it 'returns false' do
|
73
|
+
expect(subject.filters?).to be false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when include_tags is enabled' do
|
78
|
+
let(:options) do
|
79
|
+
Hashie::Mash.new(include_tags: 'true')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns true' do
|
83
|
+
expect(subject.filters?).to be true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when exclude_tags is enabled' do
|
88
|
+
let(:options) do
|
89
|
+
Hashie::Mash.new(exclude_tags: 'true')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns true' do
|
93
|
+
expect(subject.filters?).to be true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -182,7 +182,10 @@ RSpec.describe GeneSystem::Commands::InstallManifest do
|
|
182
182
|
it 'prints success message' do
|
183
183
|
expect(subject)
|
184
184
|
.to have_received(:puts)
|
185
|
-
.with(
|
185
|
+
.with(
|
186
|
+
"✔ Manifest #{manifest_name} v#{version} "\
|
187
|
+
'successfully installed'
|
188
|
+
)
|
186
189
|
end
|
187
190
|
end
|
188
191
|
|
@@ -251,7 +254,10 @@ RSpec.describe GeneSystem::Commands::InstallManifest do
|
|
251
254
|
it 'prints success message' do
|
252
255
|
expect(subject)
|
253
256
|
.to have_received(:puts)
|
254
|
-
.with(
|
257
|
+
.with(
|
258
|
+
"✔ Manifest #{manifest_name} v#{version} "\
|
259
|
+
'successfully installed'
|
260
|
+
)
|
255
261
|
end
|
256
262
|
end
|
257
263
|
end
|
@@ -255,23 +255,7 @@ RSpec.describe GeneSystem::Manifest do
|
|
255
255
|
end
|
256
256
|
|
257
257
|
it 'returns all steps by defualt' do
|
258
|
-
expect(@manifest.steps).to eq steps
|
259
|
-
end
|
260
|
-
|
261
|
-
context 'when given a query' do
|
262
|
-
let(:target_step) { double(GeneSystem::Step) }
|
263
|
-
let(:steps) { [step, target_step, step] }
|
264
|
-
|
265
|
-
before do
|
266
|
-
query = ->(step) { step == target_step }
|
267
|
-
@manifest.instance_variable_set(:@steps, steps)
|
268
|
-
|
269
|
-
@result = @manifest.steps(query)
|
270
|
-
end
|
271
|
-
|
272
|
-
it 'returns steps responding to query' do
|
273
|
-
expect(@result).to eq [target_step]
|
274
|
-
end
|
258
|
+
expect(@manifest.steps.steps).to eq steps
|
275
259
|
end
|
276
260
|
end
|
277
261
|
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe GeneSystem::StepCollection do
|
4
|
+
let(:step_name) { 'step-name' }
|
5
|
+
let(:step) do
|
6
|
+
double(GeneSystem::Step, name: step_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:steps) { [step, step] }
|
10
|
+
subject { described_class.new(steps) }
|
11
|
+
|
12
|
+
describe 'DEFAULT_QUERY' do
|
13
|
+
it 'returns true' do
|
14
|
+
expect(
|
15
|
+
described_class::DEFAULT_QUERY.call(step)
|
16
|
+
).to be true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'STEP_INCLUDE_ANY_TAG' do
|
21
|
+
let(:tag) { 'foo' }
|
22
|
+
|
23
|
+
context 'when query does not include tags' do
|
24
|
+
it 'raises runtime error' do
|
25
|
+
expect do
|
26
|
+
described_class::STEP_INCLUDE_ANY_TAG.call(step)
|
27
|
+
end.to raise_error(
|
28
|
+
RuntimeError,
|
29
|
+
'query must include tags'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when step has tag' do
|
35
|
+
let(:step) do
|
36
|
+
double(GeneSystem::Step, tags: [tag, 'bar', 'biz'])
|
37
|
+
end
|
38
|
+
|
39
|
+
before do
|
40
|
+
@result = described_class::STEP_INCLUDE_ANY_TAG.call(
|
41
|
+
step,
|
42
|
+
tags: [tag]
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns true' do
|
47
|
+
expect(@result).to be true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when step does not have tag' do
|
52
|
+
let(:step) do
|
53
|
+
double(GeneSystem::Step, tags: %w[bar biz])
|
54
|
+
end
|
55
|
+
|
56
|
+
before do
|
57
|
+
@result = described_class::STEP_INCLUDE_ANY_TAG.call(
|
58
|
+
step,
|
59
|
+
tags: [tag]
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns false' do
|
64
|
+
expect(@result).to be false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'STEP_EXCLUDE_ANY_TAG' do
|
70
|
+
let(:tag) { 'foo' }
|
71
|
+
|
72
|
+
context 'when query does not include tags' do
|
73
|
+
it 'raises runtime error' do
|
74
|
+
expect do
|
75
|
+
described_class::STEP_EXCLUDE_ANY_TAG.call(step)
|
76
|
+
end.to raise_error(
|
77
|
+
RuntimeError,
|
78
|
+
'query must include tags'
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when step has tag' do
|
84
|
+
let(:step) do
|
85
|
+
double(GeneSystem::Step, tags: [tag, 'bar', 'biz'])
|
86
|
+
end
|
87
|
+
|
88
|
+
before do
|
89
|
+
@result = described_class::STEP_EXCLUDE_ANY_TAG.call(
|
90
|
+
step,
|
91
|
+
tags: [tag]
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns false' do
|
96
|
+
expect(@result).to be false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when step does not have tag' do
|
101
|
+
let(:step) do
|
102
|
+
double(GeneSystem::Step, tags: %w[bar biz])
|
103
|
+
end
|
104
|
+
|
105
|
+
before do
|
106
|
+
@result = described_class::STEP_EXCLUDE_ANY_TAG.call(
|
107
|
+
step,
|
108
|
+
tags: [tag]
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'returns true' do
|
113
|
+
expect(@result).to be true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#count' do
|
119
|
+
it 'returns step count' do
|
120
|
+
expect(subject.count).to eq steps.count
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#map' do
|
125
|
+
before do
|
126
|
+
@result = subject.map(&:name)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'maps step names' do
|
130
|
+
expect(@result).to eq [step_name, step_name]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#each' do
|
135
|
+
before do
|
136
|
+
@result = []
|
137
|
+
|
138
|
+
subject.each do |step|
|
139
|
+
@result << step.name
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'can iterate through steps' do
|
144
|
+
expect(@result).to eq [step_name, step_name]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#filter' do
|
149
|
+
let(:matching_step) do
|
150
|
+
double(GeneSystem::Step, tags: %w[target foo])
|
151
|
+
end
|
152
|
+
|
153
|
+
let(:steps) do
|
154
|
+
[step, step, matching_step]
|
155
|
+
end
|
156
|
+
|
157
|
+
before do
|
158
|
+
allow(matching_step)
|
159
|
+
.to receive(:tags)
|
160
|
+
.and_return(%w[target foo])
|
161
|
+
|
162
|
+
allow(step)
|
163
|
+
.to receive(:tags)
|
164
|
+
.and_return([])
|
165
|
+
|
166
|
+
@steps = subject
|
167
|
+
.filter(
|
168
|
+
described_class::STEP_INCLUDE_ANY_TAG,
|
169
|
+
tags: ['target']
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'returns a step collection' do
|
174
|
+
expect(@steps).to be_a(GeneSystem::StepCollection)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'only returns matching step' do
|
178
|
+
expect(@steps.steps.count).to be 1
|
179
|
+
expect(@steps.steps.first).to eq matching_step
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe '#merge' do
|
184
|
+
let(:another_collection) { described_class.new(steps) }
|
185
|
+
|
186
|
+
before do
|
187
|
+
@merged = subject.merge(another_collection)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'returns a new step collection' do
|
191
|
+
expect(@merged).not_to eq subject
|
192
|
+
expect(@merged).not_to eq another_collection
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'is a union of the 2 collections' do
|
196
|
+
expect(@merged.count).to eq 2 * subject.count
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gene_system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bigger
|
@@ -330,6 +330,7 @@ files:
|
|
330
330
|
- lib/gene_system/cli.rb
|
331
331
|
- lib/gene_system/commands.rb
|
332
332
|
- lib/gene_system/commands/create_manifest.rb
|
333
|
+
- lib/gene_system/commands/helpers.rb
|
333
334
|
- lib/gene_system/commands/install_manifest.rb
|
334
335
|
- lib/gene_system/commands/print_version.rb
|
335
336
|
- lib/gene_system/commands/remove_manifest.rb
|
@@ -337,16 +338,19 @@ files:
|
|
337
338
|
- lib/gene_system/manifest.rb
|
338
339
|
- lib/gene_system/platform.rb
|
339
340
|
- lib/gene_system/step.rb
|
341
|
+
- lib/gene_system/step_collection.rb
|
340
342
|
- lib/gene_system/version.rb
|
341
343
|
- manifest.json
|
342
344
|
- spec/gene_system/cli_spec.rb
|
343
345
|
- spec/gene_system/commands/create_manifest_spec.rb
|
346
|
+
- spec/gene_system/commands/helpers_spec.rb
|
344
347
|
- spec/gene_system/commands/install_manifest_spec.rb
|
345
348
|
- spec/gene_system/commands/print_version_spec.rb
|
346
349
|
- spec/gene_system/commands/remove_manifest_spec.rb
|
347
350
|
- spec/gene_system/generators_spec.rb
|
348
351
|
- spec/gene_system/manifest_spec.rb
|
349
352
|
- spec/gene_system/platform_spec.rb
|
353
|
+
- spec/gene_system/step_collection_spec.rb
|
350
354
|
- spec/gene_system/step_spec.rb
|
351
355
|
- spec/spec_helper.rb
|
352
356
|
homepage: https://github.com/andrewbigger/gene_system
|
@@ -375,11 +379,13 @@ summary: System configuration tool for applying settings
|
|
375
379
|
test_files:
|
376
380
|
- spec/gene_system/cli_spec.rb
|
377
381
|
- spec/gene_system/commands/create_manifest_spec.rb
|
382
|
+
- spec/gene_system/commands/helpers_spec.rb
|
378
383
|
- spec/gene_system/commands/install_manifest_spec.rb
|
379
384
|
- spec/gene_system/commands/print_version_spec.rb
|
380
385
|
- spec/gene_system/commands/remove_manifest_spec.rb
|
381
386
|
- spec/gene_system/generators_spec.rb
|
382
387
|
- spec/gene_system/manifest_spec.rb
|
383
388
|
- spec/gene_system/platform_spec.rb
|
389
|
+
- spec/gene_system/step_collection_spec.rb
|
384
390
|
- spec/gene_system/step_spec.rb
|
385
391
|
- spec/spec_helper.rb
|