Skip to content

Commit 084c5af

Browse files
committed
feat(gems): allow to specify gems' versions
1 parent 233e225 commit 084c5af

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

packages/gems.sls

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ gem_req_pkgs:
2727
### GEMS to install
2828
# (requires the ruby/rubygem deb/rpm installed, either by the system or listed in
2929
# the required packages
30+
# Standarize gems to format { gem: version }
31+
{% set gem = namespace(name = '', version = '') %}
32+
3033
{%- for gm in wanted_gems %}
31-
{{ gm }}:
34+
{%- if gm is mapping %}
35+
{%- for k,v in gm.items() %}
36+
{%- set gem.name = k %}
37+
{%- set gem.version = v %}
38+
{%- endfor %}
39+
{%- else %}
40+
{%- set gem.name = gm %}
41+
{%- set gem.version = 'version_undefined' %}
42+
{%- endif %}
43+
{{ gem.name }}-{{ gem.version }}:
3244
gem.installed:
45+
- name: {{ gem.name }}
46+
{%- if gem.version != 'version_undefined' %}
47+
- version: {{ gem.version }}
48+
{%- endif %}
3349
- require:
3450
- pkg: gem_req_pkgs
3551
{%- if req_states %}

pillar.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ packages:
5757
wanted:
5858
- progressbar
5959
- minitest
60+
# You can also specify a desired gem version
61+
- some_gem: 1.2.3
62+
- other: 2.3.4
6063
unwanted:
6164
- diff-lcs
6265
- kitchen-vagrant

test/integration/default/controls/gems_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
end
2121
end
2222

23+
### SPECIFIC GEMS VERSIONS
24+
control "Specific gems' versions" do
25+
title 'should be installed'
26+
27+
specific_gems = {
28+
'regexp_parser' => '1.7.0',
29+
'strings' => '0.1.8'
30+
}
31+
specific_gems.each do |p, _v|
32+
describe gem(p) do
33+
it { should be_installed }
34+
its('versions') { should include(/v/) }
35+
end
36+
end
37+
end
38+
2339
### UNWANTED
2440
control 'Unwanted gems' do
2541
title 'should be uninstalled'

test/salt/pillar/debian.sls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ packages:
4141
# should also add the python pip package you want. Otherwise, the formula
4242
# will take care of getting it if needed.
4343
- libpython2.7-dev
44-
- python-pip
4544
wanted:
4645
- dxpy
4746
- attrs
@@ -59,6 +58,8 @@ packages:
5958
wanted:
6059
- progressbar
6160
- minitest
61+
- strings: 0.1.8
62+
- regexp_parser: 1.7.0
6263
unwanted:
6364
- diff-lcs
6465
- kitchen-vagrant

0 commit comments

Comments
 (0)