facterdb 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b446e391aa35c93ef8b2344d8311594c1f31ca608b515026f8ccb3772a23f0e8
4
- data.tar.gz: 848bce097609f4da2f5f39baddcabc820e11aff6e0a3c329f0db22df86aefb39
3
+ metadata.gz: d3c5507c6727a268578ec7d76730523df6fea54b3eb52c0bb5d3d4fd5dfd5eee
4
+ data.tar.gz: 99ee4c368b24f08a646a9d936507b07fcd1c71c38c202b704676055b4018b6d1
5
5
  SHA512:
6
- metadata.gz: d11839665d133a84b6b78f3b3ce338c2d127787acbea80c861ad88c3ec69d55f20517d0e31aae323a5ec0f7ecb63efbde08b0aa66cb499001e6042911362583b
7
- data.tar.gz: 13070c867414980285265492c7f0f56551c7adc901f7442a52b816ecd4e7674c8b58d800f710c13d4a1a0b6e1d2ddcf770470776a3efa4a9ce29e57992b9cd39
6
+ metadata.gz: b13f056772f354c139d0674121b3e7d249931b24ee67f7c71336e988276aa537a0e2e09859fecee7ccfe4d5a47c0b6ac7914cef20635a6afbbf4f53b4af8979f
7
+ data.tar.gz: 6c9b28b139fef0ecdc7e5003994882fb1996a32cfd641249960c60c4c65b909ee03e9e5083ed1286f1fb96b3666a96c7e773c18767bc70954a36df7efa748caa
@@ -3,19 +3,27 @@ sudo: false
3
3
  cache: bundler
4
4
  script:
5
5
  - bundle exec rake spec
6
- rvm:
7
- - 2.3
8
- env:
9
- - FACTER_GEM_VERSION="~> 1.6.0"
10
- - FACTER_GEM_VERSION="~> 1.7.0"
11
- - FACTER_GEM_VERSION="~> 2.0.0"
12
- - FACTER_GEM_VERSION="~> 2.1.0"
13
- - FACTER_GEM_VERSION="~> 2.2.0"
14
- - FACTER_GEM_VERSION="~> 2.3.0"
15
- - FACTER_GEM_VERSION="~> 2.4.0"
16
- - FACTER_GEM_VERSION="~> 2.0" COVERAGE=yes
17
6
  matrix:
18
7
  fast_finish: true
8
+ include:
9
+ - rvm: 2.3
10
+ env: FACTER_GEM_VERSION="~> 1.6.0"
11
+ - rvm: 2.3
12
+ env: FACTER_GEM_VERSION="~> 1.7.0"
13
+ - rvm: 2.3
14
+ env: FACTER_GEM_VERSION="~> 2.0.0"
15
+ - rvm: 2.3
16
+ env: FACTER_GEM_VERSION="~> 2.1.0"
17
+ - rvm: 2.3
18
+ env: FACTER_GEM_VERSION="~> 2.2.0"
19
+ - rvm: 2.3
20
+ env: FACTER_GEM_VERSION="~> 2.3.0"
21
+ - rvm: 2.3
22
+ env: FACTER_GEM_VERSION="~> 2.4.0"
23
+ - rvm: 2.5
24
+ env: FACTER_GEM_VERSION="~> 2.0" COVERAGE=yes
25
+ - rvm: 2.7
26
+ env: FACTER_GEM_VERSION="~> 2.0"
19
27
  notifications:
20
28
  email: false
21
29
  deploy:
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.0](https://rubygems.org/gems/facterdb/versions/1.5.0) (2020-11-19)
4
+
5
+ [Full Changelog](https://github.com/camptocamp/facterdb/compare/1.4.0...1.5.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - add filter validation [\#19](https://github.com/camptocamp/facterdb/issues/19)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Fixes a bug with generate\_filter\_str [\#160](https://github.com/camptocamp/facterdb/pull/160) ([logicminds](https://github.com/logicminds))
14
+ - Fixes \#19 - add filter validation [\#159](https://github.com/camptocamp/facterdb/pull/159) ([logicminds](https://github.com/logicminds))
15
+ - Remove pin on facter \< 4 [\#156](https://github.com/camptocamp/facterdb/pull/156) ([sanfrancrisko](https://github.com/sanfrancrisko))
16
+ - Add ruby 2.5 and 2.7 testing [\#155](https://github.com/camptocamp/facterdb/pull/155) ([DavidS](https://github.com/DavidS))
17
+
3
18
  ## [1.4.0](https://rubygems.org/gems/facterdb/versions/1.4.0) (2020-05-09)
4
19
 
5
20
  [Full Changelog](https://github.com/camptocamp/facterdb/compare/1.3.0...1.4.0)
@@ -20,6 +35,7 @@
20
35
 
21
36
  - Add Debian 10 facter 3.13/3.14 sets [\#152](https://github.com/camptocamp/facterdb/pull/152) ([bastelfreak](https://github.com/bastelfreak))
22
37
  - Pin to facter \< 4 to avoid automatic upgrade [\#151](https://github.com/camptocamp/facterdb/pull/151) ([raphink](https://github.com/raphink))
38
+ - Adding facts from Solaris 11 x86 & SPARC [\#149](https://github.com/camptocamp/facterdb/pull/149) ([genebean](https://github.com/genebean))
23
39
  - AmazonLinux facts added [\#147](https://github.com/camptocamp/facterdb/pull/147) ([bFekete](https://github.com/bFekete))
24
40
  - Add facts for Raspbian 9 and 10; alter Rakefile to support Raspbian [\#136](https://github.com/camptocamp/facterdb/pull/136) ([threepistons](https://github.com/threepistons))
25
41
 
data/README.md CHANGED
@@ -2,7 +2,6 @@ facterdb
2
2
  ========
3
3
 
4
4
  [![Build Status](https://img.shields.io/travis/camptocamp/facterdb/master.svg)](https://travis-ci.org/camptocamp/facterdb)
5
- [![Code Climate](https://img.shields.io/codeclimate/github/camptocamp/facterdb.svg)](https://codeclimate.com/github/camptocamp/facterdb)
6
5
  [![Gem Version](https://img.shields.io/gem/v/facterdb.svg)](https://rubygems.org/gems/facterdb)
7
6
  [![Gem Downloads](https://img.shields.io/gem/dt/facterdb.svg)](https://rubygems.org/gems/facterdb)
8
7
  [![Coverage Status](https://img.shields.io/coveralls/camptocamp/facterdb.svg)](https://coveralls.io/r/camptocamp/facterdb?branch=master)
@@ -21,6 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'pry'
22
22
  s.add_development_dependency 'rspec'
23
23
  s.add_development_dependency 'github_changelog_generator', '~> 1.10', '< 1.10.4'
24
- s.add_runtime_dependency 'facter', '< 4.0.0'
24
+ s.add_runtime_dependency 'facter', '< 5.0.0'
25
25
  s.add_runtime_dependency 'jgrep'
26
26
  end
@@ -2,6 +2,9 @@ require 'facter'
2
2
  require 'jgrep'
3
3
 
4
4
  module FacterDB
5
+ module Errors
6
+ class InvalidFilter < RuntimeError; end
7
+ end
5
8
 
6
9
  # @return [String] - returns a giant incomprehensible string of concatenated json data
7
10
  def self.database
@@ -92,18 +95,36 @@ module FacterDB
92
95
  get_facts(filter_str)
93
96
  end
94
97
 
95
- def self.get_facts(filter=nil)
96
- if filter.is_a?(Array)
97
- filter_str = '(' + filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(') or (') + ')'
98
- elsif filter.is_a?(Hash)
99
- filter_str = filter.map { |k,v | "#{k}=#{v}" }.join(' and ')
100
- elsif filter.is_a?(String)
101
- filter_str = filter
102
- elsif filter == nil
103
- filter_str = ''
98
+ # @return [String] - the string filter
99
+ # @param filter [Object] - The filter to convert to jgrep string
100
+ def self.generate_filter_str(filter=nil)
101
+ case filter
102
+ when ::Array
103
+ '(' + filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(') or (') + ')'
104
+ when ::Hash
105
+ filter.map { |k,v | "#{k}=#{v}" }.join(' and ')
106
+ when ::String
107
+ filter
108
+ when ::NilClass
109
+ ''
104
110
  else
105
- raise 'filter must be either an Array a Hash or a String'
111
+ raise Errors::InvalidFilter, "filter must be either an Array a Hash, String, or nil, received #{filter.class}"
106
112
  end
113
+ end
114
+
115
+ # @return [Boolean] - true if the filter is valid against the jgrep filter validator
116
+ # @param filter [Object] - The filter to convert to jgrep string
117
+ def self.valid_filters?(filters)
118
+ filter_str = generate_filter_str(filters)
119
+ JGrep.validate_filters(filter_str).nil?
120
+ rescue RuntimeError
121
+ false
122
+ end
123
+
124
+ # @return [Array] - array of hashes of facts
125
+ # @param filter [Object] - The filter to convert to jgrep string
126
+ def self.get_facts(filter=nil)
127
+ filter_str = generate_filter_str(filter)
107
128
  JGrep.jgrep(database, filter_str).map { |hash| Hash[hash.map{ |k, v| [k.to_sym, v] }] }
108
129
  end
109
130
  end
@@ -1,5 +1,5 @@
1
1
  module FacterDB
2
2
  module Version
3
- STRING = '1.4.0'
3
+ STRING = '1.5.0'
4
4
  end
5
5
  end
@@ -282,6 +282,42 @@ describe FacterDB do
282
282
  end
283
283
  end
284
284
 
285
+ describe '.valid_filters?' do
286
+ it 'invalid and false' do
287
+ expect( FacterDB.valid_filters?('and')).to be_falsey
288
+ end
289
+
290
+ it 'valid and true' do
291
+ expect( FacterDB.valid_filters?('foo')).to be_truthy
292
+ end
293
+ end
294
+
295
+ describe '.generate_filter_str' do
296
+ it 'invalid type' do
297
+ expect{FacterDB.generate_filter_str(3)}.to raise_error(FacterDB::Errors::InvalidFilter)
298
+ end
299
+
300
+ it 'with string' do
301
+ expect(FacterDB.generate_filter_str('foo')).to eq("foo")
302
+ end
303
+
304
+ it 'with hash' do
305
+ expect(FacterDB.generate_filter_str({:osfamily => 'Debian'})).to eq("osfamily=Debian")
306
+ end
307
+
308
+ it 'with Array' do
309
+ expect(FacterDB.generate_filter_str([:osfamily => 'Debian'])).to eq("(osfamily=Debian)")
310
+ end
311
+
312
+ it 'empty' do
313
+ expect(FacterDB.generate_filter_str('')).to eq('')
314
+ end
315
+
316
+ it 'nil filter' do
317
+ expect(FacterDB.generate_filter_str(nil)).to eq('')
318
+ end
319
+ end
320
+
285
321
  describe '.get_facts' do
286
322
  subject(:result) { FacterDB.get_facts(filter) }
287
323
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facterdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickaël Canévet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-09 00:00:00.000000000 Z
11
+ date: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "<"
94
94
  - !ruby/object:Gem::Version
95
- version: 4.0.0
95
+ version: 5.0.0
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "<"
101
101
  - !ruby/object:Gem::Version
102
- version: 4.0.0
102
+ version: 5.0.0
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: jgrep
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -1757,8 +1757,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1757
1757
  - !ruby/object:Gem::Version
1758
1758
  version: '0'
1759
1759
  requirements: []
1760
- rubyforge_project:
1761
- rubygems_version: 2.7.7
1760
+ rubygems_version: 3.0.8
1762
1761
  signing_key:
1763
1762
  specification_version: 4
1764
1763
  summary: A Database of OS facts provided by Facter