natives 0.5.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDYxNjNkMGYyMGVhNDA2ZDI4Mjk0N2QzMTA3NjIxZWI5MDg2ODdiMA==
4
+ YzQxZTNmYjcyMGI5MGIxNjUzYWZiYjExYmE1MWUxMDQ3YjU2NWExNw==
5
5
  data.tar.gz: !binary |-
6
- NTk0YTNhMTIyZjEzNzlmZjU1ZTU1NzZkNDcwMzYzOTgwNmNkYzAwNQ==
6
+ ZjI4MTc0NzY1OTdjMGUyM2Q5MzJiOGU4NmRiNjEzMzc0YWZiZDViNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGFhNzdhMDg4OWU2MDJjMTJlMGUyNTQyNTU1YWVjZDFjOTAwNTM0MzZiMDNj
10
- ZWM4MDNlOTkwODljNTAxYmY3MDBmMTY5ZDY4YmRlZTFlZTQ0ZWM3NTBhNmU1
11
- YTEyMTcyOGY5ZDg2NDU2NGM0NjE5MDJlM2EyN2M3ZDI1NjVlZDQ=
9
+ NmM1NGVmZGM0YWUzZThmMDc4NGQ3Njc2YTFiZjAyOTJmOGEzYzIwYzExNDY2
10
+ ZmM2Nzg2MjY0ODQzYjY4NjE1YzA2OGVjNDEyN2JmYTgzYWQ4ZDYxMjdkYjdh
11
+ NzcwOWVkMTM4MTI1MWZkYTMwMzkyY2Q2OGJhZmNlYjdhMmU1ZDE=
12
12
  data.tar.gz: !binary |-
13
- MDBhMmE4MDNlYmJiMzkxODZlY2RhNjlmZDg5ZTA2YTY3NTgzMzFmY2JiZDZh
14
- YTIyMzhkNGE4M2JmYTdjNGQ3ODNiMGZiYTA4ZTY0MzMzYzhiYWVjNTk2YTZi
15
- NTQ2YTU3YmJhZTJhMjFmMDU4YzcxOTk4YzQ5MTE2N2JjZjk2ZDM=
13
+ ZjkzOThmY2M0OGU5NzI1NWMwMzQ2ZTMxNjllMDQwNjUwZGE4MWY4NTIwYWYx
14
+ OGFiYzVlMGIyOWRiNGU1YWY1NTVlZDY3NDM3MjI2ODM1NzY0MDkxNmI3ZmZj
15
+ MDcxODVlNmI2MWQ2M2YxNWFlMjhmNWI1M2M3ZGY4NDhhMzAxZTE=
data/Gemfile CHANGED
@@ -10,7 +10,6 @@ group :development do
10
10
  gem "rspec"
11
11
  gem "yard"
12
12
  gem "rdoc"
13
- gem "bundler"
14
13
  gem "jeweler"
15
14
  gem "debugger"
16
15
  gem "simplecov"
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/natives.png)](http://badge.fury.io/rb/natives)
4
4
  [![Code Climate](https://codeclimate.com/github/teohm/natives.png)](https://codeclimate.com/github/teohm/natives)
5
5
  [![Build Status](https://travis-ci.org/teohm/natives.png)](https://travis-ci.org/teohm/natives)
6
+ [![Dependency Status](https://gemnasium.com/teohm/natives.png)](https://gemnasium.com/teohm/natives)
6
7
 
7
8
  List native packages required by ruby gems on your machine.
8
9
 
@@ -59,10 +60,12 @@ $ cd rails_app1
59
60
  $ cat natives-catalogs/catalog1.yaml
60
61
  rubygems:
61
62
  my_gem:
62
- mac_os_x/homebrew:
63
- - package1
64
- ubuntu/apt:
65
- - package2
63
+ homebrew:
64
+ mac_os_x:
65
+ - package1
66
+ apt:
67
+ default:
68
+ - package2
66
69
 
67
70
  $ natives list my_gem # runs on mac os x
68
71
  package1
@@ -84,16 +87,17 @@ It loads YAML files (.yaml, .yml) from the following paths in this order:
84
87
 
85
88
  When there are multiple YAML files in a path, they are **sorted by filename** and loaded in that order.
86
89
 
87
- ### Catalog file format
90
+ ### Catalog YAML format
88
91
 
89
92
  A catalog file is written in YAML, based on this format:
90
93
 
91
94
  ```
92
95
  catalog_name:
93
96
  entry_name:
94
- platform/package_provider:
95
- version:
96
- - package_name
97
+ package_provider:
98
+ platform:
99
+ platform_version:
100
+ - package_name
97
101
  ```
98
102
 
99
103
  For example,
@@ -101,9 +105,10 @@ For example,
101
105
  ```
102
106
  rubygems:
103
107
  capybara-webkit:
104
- mac_os_x/homebrew:
105
- 10.7.5:
106
- - libqtwebkit-dev
108
+ homebrew:
109
+ mac_os_x:
110
+ 10.7.5:
111
+ - libqtwebkit-dev
107
112
  ```
108
113
 
109
114
  #### Use `default` when apply to all platforms
@@ -111,79 +116,87 @@ rubygems:
111
116
  ```
112
117
  rubygems:
113
118
  curb:
114
- default:
115
- - curl
116
- ```
117
-
118
- #### Use `default` when apply to all versions
119
-
120
- ```
121
- rubygems:
122
- capybara-webkit:
123
- mac_os_x/homebrew:
119
+ apt:
124
120
  default:
125
- - libqtwebkit-dev
121
+ - libcurl4-openssl-dev
122
+
126
123
  ```
127
124
 
128
- #### Use array to group platforms
125
+ #### Use `default` when apply to all platform versions
129
126
 
130
127
  ```
131
128
  rubygems:
132
129
  capybara-webkit:
133
- [ubuntu/apt, debian/apt]:
134
- default:
135
- - libqtwebkit-dev
130
+ homebrew:
131
+ mac_os_x:
132
+ default:
133
+ - libqtwebkit-dev
136
134
  ```
137
135
 
138
- #### Use array to group versions
139
-
140
-
136
+ #### Use array to group platform versions
141
137
 
142
138
  ```
143
139
  rubygems:
144
140
  capybara-webkit:
145
- ubuntu/apt:
146
- [10.04, 10.04.1, 10.04.2, 10.04.3, 10.04.4]:
147
- - libqt4-dev
148
- default:
149
- - libqtwebkit-dev
141
+ apt:
142
+ ubuntu:
143
+ [10.04, 10.04.1, 10.04.2, 10.04.3, 10.04.4]:
144
+ - libqt4-dev
145
+ default:
146
+ - libqtwebkit-dev
150
147
  ```
151
148
 
152
149
 
153
- #### Supported values for platform/package_provider
150
+ #### Supported values for platforms and package providers
154
151
 
155
152
  Not in the list? No worry, submit a PR to patch [`host_detection/package_provider.rb`](https://github.com/teohm/natives/blob/master/lib/natives/host_detection/package_provider.rb).
156
153
 
157
- ```
158
- aix/aix
159
- amazon/yum
160
- arch/pacman
161
- centos/yum
162
- debian/apt
163
- fedora/yum
164
- freebsd/freebsd
165
- gcel/apt
166
- gentoo/portage
167
- linaro/apt
168
- linuxmint/apt
169
- mac_os_x/homebrew
170
- mac_os_x/macports
171
- mac_os_x_server/macports
172
- nexentacore/solaris
173
- omnios/ips
174
- openindiana/ips
175
- opensolaris/ips
176
- opensuse/zypper
177
- oracle/yum
178
- raspbian/apt
179
- redhat/yum
180
- scientific/yum
181
- smartos/smartos
182
- solaris2/ips
183
- suse/zypper
184
- ubuntu/apt
185
- xcp/yum
186
- xenserver/yum
154
+ ##### Package providers
155
+ ```
156
+ aix
157
+ yum
158
+ packman
159
+ apt
160
+ feebsd
161
+ portage
162
+ homebrew
163
+ macports
164
+ solaris
165
+ ips
166
+ zypper
167
+ smartos
168
+ ```
169
+
170
+ ##### Platforms
171
+ ```
172
+ aix
173
+ amazon
174
+ arch
175
+ centos
176
+ debian
177
+ fedora
178
+ freebsd
179
+ gcel
180
+ gentoo
181
+ linaro
182
+ linuxmint
183
+ mac_os_x
184
+ mac_os_x_server
185
+ nexentacore
186
+ omnios
187
+ openindiana
188
+ opensolaris
189
+ opensuse
190
+ oracle
191
+ raspbian
192
+ redhat
193
+ scientific
194
+ smartos
195
+ solaris2
196
+ suse
197
+ ubuntu
198
+ xcp
199
+ xenserver
187
200
  ```
188
201
 
189
202
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.6.0
@@ -18,10 +18,10 @@ Vagrant::Config.run do |config|
18
18
  # Provision docker and new kernel if deployment was not done.
19
19
  # It is assumed Vagrant can successfully launch the provider instance.
20
20
  if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
21
- # Add lxc-docker package
21
+ # Add lxc-docker and parallel package
22
22
  pkg_cmd = "wget -q -O - https://get.docker.io/gpg | apt-key add -;" \
23
23
  "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list;" \
24
- "apt-get update -qq; apt-get install -q -y --force-yes lxc-docker; "
24
+ "apt-get update -qq; apt-get install -q -y --force-yes lxc-docker parallel; "
25
25
  # Add Ubuntu raring backported kernel
26
26
  pkg_cmd << "apt-get update -qq; apt-get install -q -y linux-image-generic-lts-raring; "
27
27
  # Add guest additions if local vbox VM. As virtualbox is the default provider,
@@ -1,74 +1,55 @@
1
1
  rubygems:
2
2
  capybara-webkit:
3
- mac_os_x/macports:
4
- default:
5
- - qt4-mac-devel
6
- mac_os_x/homebrew:
7
- default:
8
- - qt
9
- debian/apt:
10
- default:
11
- - libqtwebkit-dev
12
- ubuntu/apt:
3
+ macports:
4
+ mac_os_x:
5
+ default:
6
+ - qt4-mac-devel
7
+ homebrew:
8
+ mac_os_x:
9
+ default:
10
+ - qt
11
+ apt:
13
12
  default:
14
13
  - libqtwebkit-dev
15
14
  curb:
16
- debian/apt:
17
- default:
18
- - libcurl4-openssl-dev
19
- ubuntu/apt:
15
+ apt:
20
16
  default:
21
17
  - libcurl4-openssl-dev
22
18
  nokogiri:
23
- debian/apt:
24
- default:
25
- - libxslt-dev
26
- - libxml2-dev
27
- ubuntu/apt:
19
+ apt:
28
20
  default:
29
21
  - libxslt-dev
30
22
  - libxml2-dev
31
23
  pg:
32
- mac_os_x/homebrew:
33
- default:
34
- - postgres
35
- debian/apt:
36
- default:
37
- - libpq-dev
38
- ubuntu/apt:
24
+ homebrew:
25
+ mac_os_x:
26
+ default:
27
+ - postgres
28
+ apt:
39
29
  default:
40
30
  - libpq-dev
41
31
  rmagick:
42
- mac_os_x/homebrew:
43
- default:
44
- - imagemagick
45
- debian/apt:
46
- default:
47
- - imagemagick
48
- - libmagickwand-dev
49
- ubuntu/apt:
32
+ homebrew:
33
+ mac_os_x:
34
+ default:
35
+ - imagemagick
36
+ apt:
50
37
  default:
51
38
  - imagemagick
52
39
  - libmagickwand-dev
53
40
  tesseract-ocr:
54
- mac_os_x/homebrew:
55
- default:
56
- - tesseract
57
- debian/apt:
58
- default:
59
- - libtesseract-dev
60
- - libleptonica-dev
61
- ubuntu/apt:
41
+ homebrew:
42
+ mac_os_x:
43
+ default:
44
+ - tesseract
45
+ apt:
62
46
  default:
63
47
  - libtesseract-dev
64
48
  - libleptonica-dev
65
49
  sqlite3:
66
- debian/apt:
67
- default:
68
- - libsqlite3-dev
69
- ubuntu/apt:
50
+ apt:
70
51
  default:
71
52
  - libsqlite3-dev
72
- fedora/yum:
53
+ yum:
73
54
  default:
74
55
  - sqlite-devel
@@ -16,9 +16,11 @@ done
16
16
 
17
17
  gems="$( $BIN_HOME/list_all )"
18
18
 
19
- for image_name in $image_names; do
20
- for gem in $gems; do
21
- $BIN_HOME/test_entry $image_name $gem
22
- done
23
- done
19
+ #for image_name in $image_names; do
20
+ #for gem in $gems; do
21
+ #$BIN_HOME/test_entry $image_name $gem
22
+ #done
23
+ #done
24
24
 
25
+ # Experimental: run test in parallel
26
+ parallel --gnu -j+0 $BIN_HOME/test_entry ::: $image_names ::: $gems
@@ -38,7 +38,7 @@ module Natives
38
38
  def native_packages_for(*entry_names)
39
39
  packages = Array(entry_names).flatten.map do |entry_name|
40
40
  Selector.new(self.to_hash.fetch(entry_name, {})).
41
- value_for(@platform, @platform_version, @package_provider)
41
+ values_for(@package_provider, @platform, @platform_version)
42
42
  end
43
43
  packages.flatten.compact
44
44
  end
@@ -0,0 +1,77 @@
1
+ require 'natives/errors'
2
+
3
+ module Natives
4
+ class Catalog
5
+ class Normalizer
6
+
7
+ def normalize(hash)
8
+ normalize_package_provider_hash(hash)
9
+ end
10
+
11
+ protected
12
+
13
+ def default?(str)
14
+ 'default' == str
15
+ end
16
+
17
+ def convert_to_hash(hash)
18
+ return hash.to_h if hash.respond_to?(:to_h)
19
+ return hash.to_hash if hash.respond_to?(:to_hash)
20
+ if block_given?
21
+ yield
22
+ else
23
+ raise InvalidCatalogFormat
24
+ end
25
+ end
26
+
27
+ def normalize_package_provider_hash(hash)
28
+ hash = convert_to_hash(hash) do
29
+ raise InvalidCatalogFormat,
30
+ "expected a hash of package providers, but got: #{hash.inspect}"
31
+ end
32
+
33
+ hash.inject({}) do |normalized_hash, (k, v)|
34
+ normalized_hash[k.to_s] = normalize_platform_hash(v)
35
+ normalized_hash
36
+ end
37
+ end
38
+
39
+ def normalize_platform_hash(hash)
40
+ hash = convert_to_hash(hash) do
41
+ raise InvalidCatalogFormat,
42
+ "expected a hash of platforms, but got: #{hash.inspect}"
43
+ end
44
+
45
+ hash.inject({}) do |normalized_hash, (k, v)|
46
+ platform = k.to_s
47
+ value = if default?(platform)
48
+ normalize_native_package_list(v)
49
+ else
50
+ normalize_version_hash(v)
51
+ end
52
+ normalized_hash[platform] = value
53
+ normalized_hash
54
+ end
55
+ end
56
+
57
+ def normalize_version_hash(hash)
58
+ hash = convert_to_hash(hash) do
59
+ raise InvalidCatalogFormat,
60
+ "expected a hash of versions, but got: #{hash.inspect}"
61
+ end
62
+
63
+ hash.inject({}) do |normalized_hash, (k, v)|
64
+ versions = Array(k)
65
+ versions.each do |version|
66
+ normalized_hash[version.to_s] = normalize_native_package_list(v)
67
+ end
68
+ normalized_hash
69
+ end
70
+ end
71
+
72
+ def normalize_native_package_list(list)
73
+ Array(list)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,77 +1,36 @@
1
+ require 'natives/catalog/normalizer'
2
+
1
3
  module Natives
2
4
  class Catalog
3
5
  class Selector
4
- def initialize(platform_hash)
5
- assert_valid_platform_hash(platform_hash)
6
- @values = normalize_platform_hash(platform_hash)
6
+ def initialize(hash)
7
+ @values = normalize(hash)
7
8
  end
8
9
 
9
- def value_for(platform, platform_version, package_provider)
10
- key = "#{platform.to_s}/#{package_provider.to_s}"
11
- if @values.key?(key) && @values[key].key?(platform_version)
12
- @values[key][platform_version]
13
- elsif @values.key?(key) && @values[key].key?('default')
14
- @values[key]['default']
15
- elsif @values.key?('default')
16
- @values['default']
17
- else
18
- nil
19
- end
20
- end
21
-
22
- protected
23
-
24
- def normalize_platform_hash(platform_hash)
25
- normalized_hash = {}
26
- platform_hash.each do |keys, value|
27
- if keys.to_s == 'default'
28
- normalized_hash['default'] = value
10
+ def values_for(package_provider, platform, platform_version)
11
+ package_provider = package_provider.to_s
12
+ platform = platform.to_s
13
+ platform_version = platform_version.to_s
14
+
15
+ values = nil
16
+ platforms = @values.fetch(package_provider, nil)
17
+ if platforms
18
+ versions = platforms.fetch(platform, nil)
19
+ if versions
20
+ values = versions.fetch(platform_version, nil) ||
21
+ versions.fetch('default', nil)
29
22
  else
30
- Array(keys).each do |key|
31
- normalized_hash[key.to_s] = normalize_keys(value)
32
- end
23
+ values = platforms.fetch('default', nil)
33
24
  end
34
25
  end
35
- normalized_hash
36
- end
37
26
 
38
- def normalize_keys(hash)
39
- normalized_hash = {}
40
- hash.each do |keys, value|
41
- Array(keys).each do |key|
42
- normalized_hash[key.to_s] = value
43
- end
44
- end
45
- normalized_hash
27
+ Array(values)
46
28
  end
47
29
 
48
- def assert_valid_platform_hash(platform_hash)
49
- unless platform_hash.kind_of? Hash
50
- raise ArgumentError, 'catalog entry should be a hash'
51
- end
30
+ private
52
31
 
53
- platform_hash.each do |platforms, value|
54
- assert_valid_key_and_value(platforms, value)
55
- end
56
- end
57
-
58
- def assert_valid_key_and_value(platforms, value)
59
- return if platforms.to_s == 'default'
60
-
61
- keys = platforms.kind_of?(Array) ? platforms : [platforms]
62
- keys.each do |key|
63
- if (%r{\A.+/.+\Z} =~ key.to_s) == nil && key.to_s != 'default'
64
- msg = "Found an invalid key: #{key.inspect}. "
65
- msg << "A valid key should be in this format: 'platform/package_provider'."
66
- raise ArgumentError, msg
67
- end
68
- end
69
-
70
- unless value.kind_of? Hash
71
- msg = "Found an invalid value: #{value.inspect} "
72
- msg << "for key: #{platforms.inspect}. The value should be a Hash."
73
- raise ArgumentError, msg
74
- end
32
+ def normalize(hash)
33
+ Normalizer.new.normalize(hash)
75
34
  end
76
35
 
77
36
  end
@@ -0,0 +1,5 @@
1
+ module Natives
2
+ class NativesError < StandardError; end
3
+
4
+ class InvalidCatalogFormat < NativesError; end
5
+ end
@@ -3,8 +3,8 @@ require 'bundler'
3
3
  module Natives
4
4
  class GemfileViewer
5
5
  def initialize(gemfile_path)
6
- @gemfile_path = gemfile_path
7
- @lockfile_path = "#{gemfile_path}.lock"
6
+ @gemfile_path = File.expand_path(gemfile_path)
7
+ @lockfile_path = "#{@gemfile_path}.lock"
8
8
  end
9
9
 
10
10
  def gem_names
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: natives 0.5.5 ruby lib
5
+ # stub: natives 0.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "natives"
9
- s.version = "0.5.5"
9
+ s.version = "0.6.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Huiming Teo"]
13
- s.date = "2013-11-13"
13
+ s.date = "2013-11-18"
14
14
  s.description = "Lookup native package dependencies required by gems on your machine."
15
15
  s.email = "teohuiming@gmail.com"
16
16
  s.executables = ["natives"]
@@ -52,9 +52,11 @@ Gem::Specification.new do |s|
52
52
  "lib/natives/catalog.rb",
53
53
  "lib/natives/catalog/loader.rb",
54
54
  "lib/natives/catalog/merger.rb",
55
+ "lib/natives/catalog/normalizer.rb",
55
56
  "lib/natives/catalog/selector.rb",
56
57
  "lib/natives/catalog/validator.rb",
57
58
  "lib/natives/cli.rb",
59
+ "lib/natives/errors.rb",
58
60
  "lib/natives/gemfile_viewer.rb",
59
61
  "lib/natives/host_detection.rb",
60
62
  "lib/natives/host_detection/package_provider.rb",
@@ -74,6 +76,7 @@ Gem::Specification.new do |s|
74
76
  "spec/natives/apps/list_spec.rb",
75
77
  "spec/natives/catalog/loader_spec.rb",
76
78
  "spec/natives/catalog/merger_spec.rb",
79
+ "spec/natives/catalog/normalizer_spec.rb",
77
80
  "spec/natives/catalog/selector_spec.rb",
78
81
  "spec/natives/catalog/validator_spec.rb",
79
82
  "spec/natives/catalog_spec.rb",
@@ -86,7 +89,7 @@ Gem::Specification.new do |s|
86
89
  s.homepage = "http://github.com/teohm/natives"
87
90
  s.licenses = ["MIT"]
88
91
  s.require_paths = ["lib"]
89
- s.rubygems_version = "2.1.10"
92
+ s.rubygems_version = "2.1.11"
90
93
  s.summary = "Lookup native packages required by gems."
91
94
 
92
95
  if s.respond_to? :specification_version then
@@ -99,7 +102,6 @@ Gem::Specification.new do |s|
99
102
  s.add_development_dependency(%q<rspec>, [">= 0"])
100
103
  s.add_development_dependency(%q<yard>, [">= 0"])
101
104
  s.add_development_dependency(%q<rdoc>, [">= 0"])
102
- s.add_development_dependency(%q<bundler>, [">= 0"])
103
105
  s.add_development_dependency(%q<jeweler>, [">= 0"])
104
106
  s.add_development_dependency(%q<debugger>, [">= 0"])
105
107
  s.add_development_dependency(%q<simplecov>, [">= 0"])
@@ -110,7 +112,6 @@ Gem::Specification.new do |s|
110
112
  s.add_dependency(%q<rspec>, [">= 0"])
111
113
  s.add_dependency(%q<yard>, [">= 0"])
112
114
  s.add_dependency(%q<rdoc>, [">= 0"])
113
- s.add_dependency(%q<bundler>, [">= 0"])
114
115
  s.add_dependency(%q<jeweler>, [">= 0"])
115
116
  s.add_dependency(%q<debugger>, [">= 0"])
116
117
  s.add_dependency(%q<simplecov>, [">= 0"])
@@ -122,7 +123,6 @@ Gem::Specification.new do |s|
122
123
  s.add_dependency(%q<rspec>, [">= 0"])
123
124
  s.add_dependency(%q<yard>, [">= 0"])
124
125
  s.add_dependency(%q<rdoc>, [">= 0"])
125
- s.add_dependency(%q<bundler>, [">= 0"])
126
126
  s.add_dependency(%q<jeweler>, [">= 0"])
127
127
  s.add_dependency(%q<debugger>, [">= 0"])
128
128
  s.add_dependency(%q<simplecov>, [">= 0"])
@@ -1,9 +1,10 @@
1
1
  rubygems:
2
2
  invalid_line
3
- ubuntu/apt:
4
- default:
5
- - imagemagick
6
- - libmagick9-dev
3
+ apt:
4
+ ubuntu:
5
+ default:
6
+ - imagemagick
7
+ - libmagick9-dev
7
8
  curb:
8
9
  default:
9
10
  - curl
@@ -1,21 +1,26 @@
1
1
  rubygems:
2
2
  capybara-webkit:
3
- mac_os_x/macports:
4
- default:
5
- - qt4-mac-devel
6
- mac_os_x/homebrew:
7
- default:
8
- - qt
9
- ubuntu/apt:
10
- default:
11
- - libqtwebkit-dev
12
- [10.04,10.04.1,10.04.2,10.04.3,10.04.4]:
13
- - libqt4-dev
3
+ macports:
4
+ mac_os_x:
5
+ default:
6
+ - qt4-mac-devel
7
+ homebrew:
8
+ mac_os_x:
9
+ default:
10
+ - qt
11
+ apt:
12
+ ubuntu:
13
+ default:
14
+ - libqtwebkit-dev
15
+ [10.04,10.04.1,10.04.2,10.04.3,10.04.4]:
16
+ - libqt4-dev
14
17
  rmagick:
15
- mac_os_x/homebrew:
16
- default:
17
- - imagemagick
18
- ubuntu/apt:
19
- default:
20
- - imagemagick
21
- - libmagick9-dev
18
+ homebrew:
19
+ mac_os_x:
20
+ default:
21
+ - imagemagick
22
+ apt:
23
+ ubuntu:
24
+ default:
25
+ - imagemagick
26
+ - libmagick9-dev
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+ require 'natives/catalog/normalizer'
3
+
4
+ describe "Catalog Normalizer" do
5
+ let(:normalizer) { Natives::Catalog::Normalizer.new }
6
+
7
+ context "Given valid hash input" do
8
+ it "converts package provider, platform, platform version to string" do
9
+ hash = normalizer.normalize({
10
+ :macports => {
11
+ :mac_os_x => {
12
+ :default => ['foo'],
13
+ :"10.1.2" => ['bar']
14
+ }
15
+ }
16
+ })
17
+
18
+ expect(hash).to eq({
19
+ 'macports' => {
20
+ 'mac_os_x' => {
21
+ 'default' => ['foo'],
22
+ '10.1.2' => ['bar']
23
+ }
24
+ }
25
+ })
26
+ end
27
+
28
+ it "supports default platform" do
29
+ hash = normalizer.normalize({
30
+ apt: {
31
+ default: ['foo'],
32
+ ubuntu: {
33
+ default: ['bar']
34
+ }
35
+ }
36
+ })
37
+
38
+ expect(hash).to eq({
39
+ 'apt' => {
40
+ 'default' => ['foo'],
41
+ 'ubuntu' => {
42
+ 'default' => ['bar']
43
+ }
44
+ }
45
+ })
46
+ end
47
+
48
+ it "normalizes version list" do
49
+ hash = normalizer.normalize({
50
+ apt: {
51
+ ubuntu: {
52
+ :default => ['bar'],
53
+ '13' => ['top'],
54
+ ['11','12','13'] => ['foo'],
55
+ '11' => ['bottom']
56
+ }
57
+ }
58
+ })
59
+
60
+ expect(hash).to eq({
61
+ 'apt' => {
62
+ 'ubuntu' => {
63
+ 'default' => ['bar'],
64
+ '13' => ['foo'],
65
+ '11' => ['bottom'],
66
+ '12' => ['foo']
67
+ }
68
+ }
69
+ })
70
+ end
71
+
72
+ it "ensures native packages is a list" do
73
+ hash = normalizer.normalize({
74
+ apt: {
75
+ default: 'defaultfoo',
76
+ ubuntu: {
77
+ :default => 'bar',
78
+ '14' => 'top',
79
+ ['11','12','13'] => 'foo',
80
+ }
81
+ }
82
+ })
83
+
84
+ expect(hash).to eq({
85
+ 'apt' => {
86
+ 'default' => ['defaultfoo'],
87
+ 'ubuntu' => {
88
+ 'default' => ['bar'],
89
+ '14' => ['top'],
90
+ '11' => ['foo'],
91
+ '12' => ['foo'],
92
+ '13' => ['foo']
93
+ }
94
+ }
95
+ })
96
+ end
97
+
98
+ end
99
+
100
+ context "Invalid input" do
101
+
102
+ it "raises error when package provider hash is not a hash" do
103
+ expect {
104
+ normalizer.normalize("invalid")
105
+ }.to raise_error Natives::InvalidCatalogFormat
106
+
107
+ end
108
+
109
+ it "raises error when platform hash is not a hash" do
110
+ expect {
111
+ normalizer.normalize({
112
+ "macports" => "invalid"
113
+ })
114
+ }.to raise_error Natives::InvalidCatalogFormat
115
+ end
116
+
117
+ it "raises error when version hash is not a hash" do
118
+ expect {
119
+ normalizer.normalize({
120
+ "macports" => {
121
+ "ubuntu" => nil
122
+ }
123
+ })
124
+ }.to raise_error Natives::InvalidCatalogFormat
125
+ end
126
+
127
+ end
128
+ end
@@ -2,123 +2,50 @@ require 'spec_helper'
2
2
  require 'natives/catalog/selector'
3
3
 
4
4
  describe Natives::Catalog::Selector do
5
- describe "#new" do
6
5
 
7
- describe "assert valid platform hash" do
8
- it "raises error if platform hash is not a hash" do
9
- expect {
10
- Natives::Catalog::Selector.new(nil)
11
- }.to raise_error(ArgumentError, "catalog entry should be a hash")
12
- end
13
-
14
- it "raises error when found an invalid string as hash key" do
15
- expect {
16
- Natives::Catalog::Selector.new({
17
- "mac_os_x/homebrew" => {"default" => "value"},
18
- "ubuntu" => {"default" => "value"},
19
- "debian" => {"default" => "value"}
20
- })
21
- }.to raise_error ArgumentError, /Found an invalid key: "ubuntu"/
22
- end
23
-
24
- it "raises error when found an invalid array as hash key" do
25
- expect {
26
- Natives::Catalog::Selector.new({
27
- ["fedora/yum", "redhat/yum"] => {"default" => "value"},
28
- ["centos/yum", "oracle"] => {"default" => "value"},
29
- })
30
- }.to raise_error ArgumentError, /Found an invalid key: "oracle"/
31
- end
32
-
33
- it "raises error if platform hash's value is not a hash" do
34
- expect {
35
- Natives::Catalog::Selector.new({
36
- "ubuntu/apt" => "value",
37
- "mac_os_x/homebrew" => {"default" => "value"},
38
- })
39
- }.to raise_error ArgumentError, /Found an invalid value: "value"/
40
- end
41
-
42
- it "accepts default platform value" do
43
- expect {
44
- Natives::Catalog::Selector.new({
45
- "default" => "value"
46
- })
47
- }.not_to raise_error
48
- end
49
- end
50
-
51
- describe "normalize platform hash" do
52
- class ProxySelector < Natives::Catalog::Selector
53
- def normalized_values
54
- @values
55
- end
56
- end
57
-
58
- it "expand platform array" do
59
- expect(ProxySelector.new({
60
- "mac_os_x/homebrew" => {"default" => "value1"},
61
- ["ubuntu/apt", "debian/apt"] => {"default" => "value2"}
62
- }).normalized_values).to eq({
63
- "mac_os_x/homebrew" => {"default" => "value1"},
64
- "ubuntu/apt" => {"default" => "value2"},
65
- "debian/apt" => {"default" => "value2"}
66
- })
67
- end
68
-
69
- it "expand version array" do
70
- expect(ProxySelector.new({
71
- "mac_os_x/homebrew" => {
72
- "default" => "value1",
73
- ["v1", "v2"] => "value2"
6
+ describe "#value_for" do
7
+ let(:selector) do
8
+ Natives::Catalog::Selector.new({
9
+ apt: {
10
+ default: 'apt-default',
11
+ ubuntu: {
12
+ '12.10' => 'ubuntu-12.10',
13
+ %w(10.10 10.10.1 10.10.2) => %w(ubuntu-10.10s),
14
+ 'default' => %w(ubuntu-default1 ubuntu-default2)
74
15
  }
75
- }).normalized_values).to eq({
76
- "mac_os_x/homebrew" => {
77
- "default" => "value1",
78
- "v1" => "value2",
79
- "v2" => "value2"
16
+ },
17
+ homebrew: {
18
+ mac_os_x: {
19
+ '10' => 'foo'
80
20
  }
81
- })
82
- end
21
+ }
22
+ })
83
23
  end
84
- end
85
24
 
86
- describe "#value_for" do
87
- it "returns the default value when the platform/package_provider doesn't match" do
88
- expect(
89
- Natives::Catalog::Selector.new({
90
- "ubuntu/apt" => {"default" => "libcurl"},
91
- "default" => "curl"
92
- }).value_for('mac_os_x', '10.7.5', 'homebrew')
93
- ).to eq('curl')
25
+ it "returns values for a specific platform version" do
26
+ expect(selector.values_for(:apt, :ubuntu, :'12.10')).to eq(
27
+ ['ubuntu-12.10'])
94
28
  end
95
-
96
- it "returns a value for a specific platform version" do
97
- expect(
98
- Natives::Catalog::Selector.new({
99
- ["mac_os_x/homebrew", "mac_os_x/macports"] => {
100
- "10.7.5" => "curl", "default" => "foo"},
101
- "default" => "bar"
102
- }).value_for('mac_os_x', '10.7.5', 'homebrew')
103
- ).to eq('curl')
29
+ it "returns a value for a specific platform version in version group" do
30
+ expect(selector.values_for(:apt, :ubuntu, :'10.10.1')).to eq(
31
+ ['ubuntu-10.10s'])
104
32
  end
105
-
106
- it "returns a platform-default value if the platform version doesn't match an explicit one" do
107
- expect(
108
- Natives::Catalog::Selector.new({
109
- "mac_os_x/homebrew" => {
110
- "10.7.5" => "curl", "default" => "foo"},
111
- "default" => "bar"
112
- }).value_for('mac_os_x', '10.8.0', 'homebrew')
113
- ).to eq('foo')
33
+ it "returns default version values when no matching platform version" do
34
+ expect(selector.values_for('apt', 'ubuntu', '13')).to eq(
35
+ ['ubuntu-default1', 'ubuntu-default2'])
114
36
  end
115
-
116
- it "returns nil if there is no default and no platforms match" do
117
- expect(
118
- Natives::Catalog::Selector.new({
119
- ["mac_os_x/homebrew", "mac_os_x/macports"] => {"10.7.5" => "curl"}
120
- }).value_for('mac_os_x', '10.8.0', 'homebrew')
121
- ).to be_nil
37
+ it "returns default value when not matching platform" do
38
+ expect(selector.values_for(:apt, :foo, :'13')).to eq(
39
+ ['apt-default'])
40
+ end
41
+ it "returns empty list if there is no matching package provider" do
42
+ expect(selector.values_for(:notfound, :ubuntu, '10')).to eq([])
43
+ end
44
+ it "returns nil if there is no default and no matching platform" do
45
+ expect(selector.values_for(:homebrew, :notfound, 1)).to eq([])
46
+ end
47
+ it "returns nil if there is no default and no matching platform version" do
48
+ expect(selector.values_for(:homebrew, :mac_os_x, '999')).to eq([])
122
49
  end
123
50
  end
124
51
  end
@@ -93,14 +93,18 @@ describe Natives::Catalog do
93
93
  and_return({
94
94
  'rubygems' => {
95
95
  'nokogiri' => {
96
- 'ubuntu/apt' => {
97
- '13.10' => 'value1',
98
- 'default' => 'value2'
96
+ 'apt' => {
97
+ 'ubuntu' => {
98
+ '13.10' => 'value1',
99
+ 'default' => 'value2'
100
+ }
99
101
  }
100
102
  },
101
103
  'curb' => {
102
- 'ubuntu/apt' => {
103
- 'default' => 'value3'
104
+ 'apt' => {
105
+ 'ubuntu' => {
106
+ 'default' => 'value3'
107
+ }
104
108
  }
105
109
  }
106
110
  },
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natives
3
3
  version: !ruby/object:Gem::Version
4
- version: !binary |-
5
- MC41LjU=
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Huiming Teo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2013-11-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ohai
@@ -95,20 +94,6 @@ dependencies:
95
94
  - - ! '>='
96
95
  - !ruby/object:Gem::Version
97
96
  version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: bundler
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ! '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ! '>='
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
97
  - !ruby/object:Gem::Dependency
113
98
  name: jeweler
114
99
  requirement: !ruby/object:Gem::Requirement
@@ -193,9 +178,11 @@ files:
193
178
  - lib/natives/catalog.rb
194
179
  - lib/natives/catalog/loader.rb
195
180
  - lib/natives/catalog/merger.rb
181
+ - lib/natives/catalog/normalizer.rb
196
182
  - lib/natives/catalog/selector.rb
197
183
  - lib/natives/catalog/validator.rb
198
184
  - lib/natives/cli.rb
185
+ - lib/natives/errors.rb
199
186
  - lib/natives/gemfile_viewer.rb
200
187
  - lib/natives/host_detection.rb
201
188
  - lib/natives/host_detection/package_provider.rb
@@ -215,6 +202,7 @@ files:
215
202
  - spec/natives/apps/list_spec.rb
216
203
  - spec/natives/catalog/loader_spec.rb
217
204
  - spec/natives/catalog/merger_spec.rb
205
+ - spec/natives/catalog/normalizer_spec.rb
218
206
  - spec/natives/catalog/selector_spec.rb
219
207
  - spec/natives/catalog/validator_spec.rb
220
208
  - spec/natives/catalog_spec.rb
@@ -243,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
231
  version: '0'
244
232
  requirements: []
245
233
  rubyforge_project:
246
- rubygems_version: 2.1.10
234
+ rubygems_version: 2.1.11
247
235
  signing_key:
248
236
  specification_version: 4
249
237
  summary: Lookup native packages required by gems.