Skip to content

Commit

Permalink
feat(gems): allow to specify gems' versions
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbertoli committed Oct 26, 2021
1 parent 233e225 commit 084c5af
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/gems.sls
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ gem_req_pkgs:
### GEMS to install
# (requires the ruby/rubygem deb/rpm installed, either by the system or listed in
# the required packages
# Standarize gems to format { gem: version }
{% set gem = namespace(name = '', version = '') %}
{%- for gm in wanted_gems %}
{{ gm }}:
{%- if gm is mapping %}
{%- for k,v in gm.items() %}
{%- set gem.name = k %}
{%- set gem.version = v %}
{%- endfor %}
{%- else %}
{%- set gem.name = gm %}
{%- set gem.version = 'version_undefined' %}
{%- endif %}
{{ gem.name }}-{{ gem.version }}:
gem.installed:
- name: {{ gem.name }}
{%- if gem.version != 'version_undefined' %}
- version: {{ gem.version }}
{%- endif %}
- require:
- pkg: gem_req_pkgs
{%- if req_states %}
Expand Down
3 changes: 3 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ packages:
wanted:
- progressbar
- minitest
# You can also specify a desired gem version
- some_gem: 1.2.3
- other: 2.3.4
unwanted:
- diff-lcs
- kitchen-vagrant
Expand Down
16 changes: 16 additions & 0 deletions test/integration/default/controls/gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@
end
end

### SPECIFIC GEMS VERSIONS
control "Specific gems' versions" do
title 'should be installed'

specific_gems = {
'regexp_parser' => '1.7.0',
'strings' => '0.1.8'
}
specific_gems.each do |p, _v|
describe gem(p) do
it { should be_installed }
its('versions') { should include(/v/) }
end
end
end

### UNWANTED
control 'Unwanted gems' do
title 'should be uninstalled'
Expand Down
3 changes: 2 additions & 1 deletion test/salt/pillar/debian.sls
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ packages:
# should also add the python pip package you want. Otherwise, the formula
# will take care of getting it if needed.
- libpython2.7-dev
- python-pip
wanted:
- dxpy
- attrs
Expand All @@ -59,6 +58,8 @@ packages:
wanted:
- progressbar
- minitest
- strings: 0.1.8
- regexp_parser: 1.7.0
unwanted:
- diff-lcs
- kitchen-vagrant
Expand Down

0 comments on commit 084c5af

Please sign in to comment.