natives-catalog 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGNiODNjNGQzM2M3MGZhNzM1OTRkNzI1ZjI2Mzk2ODAzMWIyNzdmMg==
5
+ data.tar.gz: !binary |-
6
+ MTM5OWQwZDQ0Yzc0MmNjNjJkZGJjNTZmMDVmNTNjNjc2YWY3ZTc4Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2M1MDM3Yjc4YTNlMTZmYjUxMzEzZTk1ODAyM2FhYjk5Yjk4MWIyMDRiZGFj
10
+ Yjc2N2EzMDk3ZDY4OTlmNDFjNzIwZGVmZTI4YjY1NTNlNGY4NTY4OWQxMmI1
11
+ OGFhOWRkYjE5OWI5NDNhZTFlYTc5NTYwZjBiNWI1MjQyNzI2M2Q=
12
+ data.tar.gz: !binary |-
13
+ ZDM2ZGVjMDc1OTE0MjdkOTQ2YWI0MGJhMDZkZDA0Y2EyYjk5YWIwY2UxYzg5
14
+ MTY5YWQwYWNjMTE4M2U2M2M3MjRhOGRjN2JiMWU3NjRmYWJjNDRmYmJhOGRh
15
+ NTYxOTUxOGRkOWNiOTU1ZTU5MmU3ZGE2YTFjNzZmY2FlODgxNTY=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "chef", '>= 11'
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec"
10
+ gem "yard"
11
+ gem "rdoc"
12
+ gem "bundler"
13
+ gem "jeweler"
14
+ gem "debugger"
15
+ gem "simplecov"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,120 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ chef (11.6.2)
7
+ erubis (~> 2.7)
8
+ highline (~> 1.6, >= 1.6.9)
9
+ json (>= 1.4.4, <= 1.7.7)
10
+ mixlib-authentication (~> 1.3)
11
+ mixlib-cli (~> 1.3)
12
+ mixlib-config (~> 1.1, >= 1.1.2)
13
+ mixlib-log (~> 1.3)
14
+ mixlib-shellout (~> 1.1)
15
+ net-ssh (~> 2.6)
16
+ net-ssh-multi (~> 1.1.0)
17
+ ohai (>= 0.6.0, < 7.0.0)
18
+ rest-client (>= 1.0.4, < 1.7.0)
19
+ yajl-ruby (~> 1.1)
20
+ columnize (0.3.6)
21
+ debugger (1.6.1)
22
+ columnize (>= 0.3.1)
23
+ debugger-linecache (~> 1.2.0)
24
+ debugger-ruby_core_source (~> 1.2.3)
25
+ debugger-linecache (1.2.0)
26
+ debugger-ruby_core_source (1.2.3)
27
+ diff-lcs (1.2.4)
28
+ erubis (2.7.0)
29
+ faraday (0.8.8)
30
+ multipart-post (~> 1.2.0)
31
+ git (1.2.6)
32
+ github_api (0.10.1)
33
+ addressable
34
+ faraday (~> 0.8.1)
35
+ hashie (>= 1.2)
36
+ multi_json (~> 1.4)
37
+ nokogiri (~> 1.5.2)
38
+ oauth2
39
+ hashie (2.0.5)
40
+ highline (1.6.19)
41
+ httpauth (0.2.0)
42
+ ipaddress (0.8.0)
43
+ jeweler (1.8.8)
44
+ builder
45
+ bundler (~> 1.0)
46
+ git (>= 1.2.5)
47
+ github_api (= 0.10.1)
48
+ highline (>= 1.6.15)
49
+ nokogiri (= 1.5.10)
50
+ rake
51
+ rdoc
52
+ json (1.7.7)
53
+ jwt (0.1.8)
54
+ multi_json (>= 1.5)
55
+ mime-types (1.25)
56
+ mixlib-authentication (1.3.0)
57
+ mixlib-log
58
+ mixlib-cli (1.3.0)
59
+ mixlib-config (1.1.2)
60
+ mixlib-log (1.6.0)
61
+ mixlib-shellout (1.2.0)
62
+ multi_json (1.8.2)
63
+ multi_xml (0.5.5)
64
+ multipart-post (1.2.0)
65
+ net-ssh (2.7.0)
66
+ net-ssh-gateway (1.2.0)
67
+ net-ssh (>= 2.6.5)
68
+ net-ssh-multi (1.1)
69
+ net-ssh (>= 2.1.4)
70
+ net-ssh-gateway (>= 0.99.0)
71
+ nokogiri (1.5.10)
72
+ oauth2 (0.9.2)
73
+ faraday (~> 0.8)
74
+ httpauth (~> 0.2)
75
+ jwt (~> 0.1.4)
76
+ multi_json (~> 1.0)
77
+ multi_xml (~> 0.5)
78
+ rack (~> 1.2)
79
+ ohai (6.18.0)
80
+ ipaddress
81
+ mixlib-cli
82
+ mixlib-config
83
+ mixlib-log
84
+ mixlib-shellout
85
+ systemu
86
+ yajl-ruby
87
+ rack (1.5.2)
88
+ rake (10.1.0)
89
+ rdoc (4.0.1)
90
+ json (~> 1.4)
91
+ rest-client (1.6.7)
92
+ mime-types (>= 1.16)
93
+ rspec (2.14.1)
94
+ rspec-core (~> 2.14.0)
95
+ rspec-expectations (~> 2.14.0)
96
+ rspec-mocks (~> 2.14.0)
97
+ rspec-core (2.14.5)
98
+ rspec-expectations (2.14.3)
99
+ diff-lcs (>= 1.1.3, < 2.0)
100
+ rspec-mocks (2.14.3)
101
+ simplecov (0.7.1)
102
+ multi_json (~> 1.0)
103
+ simplecov-html (~> 0.7.1)
104
+ simplecov-html (0.7.1)
105
+ systemu (2.5.2)
106
+ yajl-ruby (1.1.0)
107
+ yard (0.8.7.2)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ bundler
114
+ chef (>= 11)
115
+ debugger
116
+ jeweler
117
+ rdoc
118
+ rspec
119
+ simplecov
120
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Huiming Teo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # natives-catalog
2
+
3
+ Description goes here.
4
+
5
+ ## Contributing to natives-catalog
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2013 Huiming Teo. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "natives-catalog"
18
+ gem.homepage = "http://github.com/teohm/natives-catalog"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A catalog of native packages for ruby gems.}
21
+ gem.description = %Q{A catalog of native packages in different platforms required by ruby gems.}
22
+ gem.email = "teohuiming@gmail.com"
23
+ gem.authors = ["Huiming Teo"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:coverage) do |spec|
35
+ ENV['COVERAGE'] = 'true'
36
+ end
37
+
38
+ task :default => :spec
39
+
40
+ require 'yard'
41
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,11 @@
1
+ rubygems:
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
File without changes
@@ -0,0 +1,43 @@
1
+ require 'natives/catalog/loader'
2
+ require 'natives/catalog/selector'
3
+
4
+ module Natives
5
+ class Catalog
6
+
7
+ CATALOG_PATH_IN_GEM = File.absolute_path(File.join(
8
+ File.dirname(__FILE__), '..', '..', 'catalogs'))
9
+ CATALOG_PATH_IN_WORKING_DIR = File.absolute_path(File.join('.', 'natives-catalogs'))
10
+
11
+ CATALOG_PATHS = [
12
+ CATALOG_PATH_IN_GEM,
13
+ CATALOG_PATH_IN_WORKING_DIR
14
+ ].freeze
15
+
16
+ attr_reader :platform, :platform_version, :package_provider, :name
17
+
18
+ def initialize(catalog_name, platform, platform_version, package_provider)
19
+ reload
20
+
21
+ @name = catalog_name.to_s
22
+ @platform = platform.to_s
23
+ @platform_version = platform_version.to_s
24
+ @package_provider = package_provider.to_s
25
+ end
26
+
27
+ def reload
28
+ @catalogs = Loader.new.load_from_paths(CATALOG_PATHS)
29
+ end
30
+
31
+ def to_hash
32
+ @catalogs.fetch(self.name, {})
33
+ end
34
+
35
+ def native_packages_for(entry_name)
36
+ Array(
37
+ Selector.new(self.to_hash.fetch(entry_name, {})).
38
+ value_for(@platform, @platform_version, @package_provider)
39
+ )
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ require 'natives/catalog/merger'
2
+ require 'yaml'
3
+
4
+ module Natives
5
+ class Catalog
6
+ class Loader
7
+ def initialize(opts={})
8
+ @merger = opts.fetch(:merger, Merger.new)
9
+ end
10
+
11
+ def load_from_paths(paths)
12
+ master_hash = {}
13
+ Array(paths).each do |path|
14
+ yaml_files_in_path(path).sort.each do |file|
15
+ @merger.merge_catalog!(master_hash, load_yaml_file(file))
16
+ end
17
+ end
18
+ master_hash
19
+ end
20
+
21
+ def yaml_files_in_path(path)
22
+ Dir.glob(File.join(path, '*.{yml,yaml}'))
23
+ end
24
+
25
+ def load_yaml_file(filename)
26
+ YAML.load_file(filename)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'natives/catalog/validator'
2
+
3
+ module Natives
4
+ class Catalog
5
+ class Merger
6
+ def initialize(opts={})
7
+ @validator = opts.fetch(:validator, Validator.new)
8
+ end
9
+
10
+ def merge_catalog!(master_hash, hash_to_merge)
11
+ @validator.ensure_valid_catalog_groups(master_hash)
12
+ @validator.ensure_valid_catalog_groups(hash_to_merge)
13
+
14
+ hash_to_merge.each do |group_name, entries|
15
+ if master_hash.key? group_name
16
+ master_hash[group_name].merge! entries
17
+ else
18
+ master_hash[group_name] = entries
19
+ end
20
+ end
21
+
22
+ master_hash
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,79 @@
1
+ module Natives
2
+ class Catalog
3
+ class Selector
4
+ def initialize(platform_hash)
5
+ assert_valid_platform_hash(platform_hash)
6
+ @values = normalize_platform_hash(platform_hash)
7
+ end
8
+
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
29
+ else
30
+ Array(keys).each do |key|
31
+ normalized_hash[key.to_s] = normalize_keys(value)
32
+ end
33
+ end
34
+ end
35
+ normalized_hash
36
+ end
37
+
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
46
+ end
47
+
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
52
+
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
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,18 @@
1
+ module Natives
2
+ class Catalog
3
+ class Validator
4
+ def ensure_valid_catalog_groups(hash)
5
+ unless hash.kind_of? Hash
6
+ raise ArgumentError, 'catalog should be a Hash'
7
+ end
8
+
9
+ invalid_groups = hash.select {|key, value| !value.kind_of?(Hash) }
10
+ unless invalid_groups.empty?
11
+ group_names = invalid_groups.keys
12
+ raise ArgumentError,
13
+ "The following catalog group(s) should be a Hash: #{group_names.join(', ')}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,88 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: natives-catalog 0.2.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "natives-catalog"
9
+ s.version = "0.2.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Huiming Teo"]
13
+ s.date = "2013-10-24"
14
+ s.description = "A catalog of native packages in different platforms required by ruby gems."
15
+ s.email = "teohuiming@gmail.com"
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "catalogs/rubygems.yaml",
30
+ "lib/natives-catalog.rb",
31
+ "lib/natives/catalog.rb",
32
+ "lib/natives/catalog/loader.rb",
33
+ "lib/natives/catalog/merger.rb",
34
+ "lib/natives/catalog/selector.rb",
35
+ "lib/natives/catalog/validator.rb",
36
+ "natives-catalog.gemspec",
37
+ "spec/fixtures/dir_with_matching_files/invalid1.yml",
38
+ "spec/fixtures/dir_with_matching_files/not_matching.json",
39
+ "spec/fixtures/dir_with_matching_files/valid1.yaml",
40
+ "spec/fixtures/dir_with_matching_files/valid2.yml",
41
+ "spec/fixtures/dir_without_matching_file/not_matching.json",
42
+ "spec/natives/catalog/loader_spec.rb",
43
+ "spec/natives/catalog/merger_spec.rb",
44
+ "spec/natives/catalog/selector_spec.rb",
45
+ "spec/natives/catalog/validator_spec.rb",
46
+ "spec/natives/catalog_spec.rb",
47
+ "spec/spec_helper.rb"
48
+ ]
49
+ s.homepage = "http://github.com/teohm/natives-catalog"
50
+ s.licenses = ["MIT"]
51
+ s.require_paths = ["lib"]
52
+ s.rubygems_version = "2.1.9"
53
+ s.summary = "A catalog of native packages for ruby gems."
54
+
55
+ if s.respond_to? :specification_version then
56
+ s.specification_version = 4
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<chef>, [">= 11"])
60
+ s.add_development_dependency(%q<rspec>, [">= 0"])
61
+ s.add_development_dependency(%q<yard>, [">= 0"])
62
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
63
+ s.add_development_dependency(%q<bundler>, [">= 0"])
64
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
65
+ s.add_development_dependency(%q<debugger>, [">= 0"])
66
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
67
+ else
68
+ s.add_dependency(%q<chef>, [">= 11"])
69
+ s.add_dependency(%q<rspec>, [">= 0"])
70
+ s.add_dependency(%q<yard>, [">= 0"])
71
+ s.add_dependency(%q<rdoc>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, [">= 0"])
74
+ s.add_dependency(%q<debugger>, [">= 0"])
75
+ s.add_dependency(%q<simplecov>, [">= 0"])
76
+ end
77
+ else
78
+ s.add_dependency(%q<chef>, [">= 11"])
79
+ s.add_dependency(%q<rspec>, [">= 0"])
80
+ s.add_dependency(%q<yard>, [">= 0"])
81
+ s.add_dependency(%q<rdoc>, [">= 0"])
82
+ s.add_dependency(%q<bundler>, [">= 0"])
83
+ s.add_dependency(%q<jeweler>, [">= 0"])
84
+ s.add_dependency(%q<debugger>, [">= 0"])
85
+ s.add_dependency(%q<simplecov>, [">= 0"])
86
+ end
87
+ end
88
+
@@ -0,0 +1,9 @@
1
+ rubygems:
2
+ invalid_line
3
+ ubuntu/apt:
4
+ default:
5
+ - imagemagick
6
+ - libmagick9-dev
7
+ curb:
8
+ default:
9
+ - curl
@@ -0,0 +1,21 @@
1
+ rubygems:
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
14
+ rmagick:
15
+ mac_os_x/homebrew:
16
+ default:
17
+ - imagemagick
18
+ ubuntu/apt:
19
+ default:
20
+ - imagemagick
21
+ - libmagick9-dev
@@ -0,0 +1,9 @@
1
+ rubygems:
2
+ rmagick:
3
+ ubuntu/apt:
4
+ default:
5
+ - imagemagick
6
+ - libmagick9-dev
7
+ curb:
8
+ default:
9
+ - curl
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+ require 'natives/catalog/loader'
3
+
4
+ describe Natives::Catalog::Loader do
5
+ describe "#load_from_paths" do
6
+ let(:loader) { Natives::Catalog::Loader.new }
7
+
8
+ it "loads files in catalog paths, in the order of given paths and sorted filenames" do
9
+ files = {
10
+ '/to/path1' => ['/to/path1/file1.yaml'],
11
+ '/to/path2' => ['/to/path2/file2.yaml', '/to/path2/file1.yaml'],
12
+ '/to/path3' => ['/to/path3/file2.yaml', '/to/path3/file1.yaml', '/to/path3/file3.yaml']
13
+ }
14
+ catalog_hashes = {
15
+ '/to/path1/file1.yaml' => {"rubygems" => { "p" => "p1f1", "p1" => "p1f1", "p1f1" => "" } },
16
+ '/to/path2/file1.yaml' => {"rubygems" => { "p" => "p2f1", "p2" => "p2f1", "p2f1" => "" } },
17
+ '/to/path2/file2.yaml' => {"rubygems" => { "p" => "p2f2", "p2" => "p2f2", "p2f2" => "" } },
18
+ '/to/path3/file1.yaml' => {"rubygems" => { "p" => "p3f1", "p3" => "p3f1", "p3f1" => "" } },
19
+ '/to/path3/file2.yaml' => {"rubygems" => { "p" => "p3f2", "p3" => "p3f2", "p3f2" => "" } },
20
+ '/to/path3/file3.yaml' => {"rubygems" => { "p" => "p3f3", "p3" => "p3f3", "p3f3" => "" } }
21
+ }
22
+ loader.stub(:yaml_files_in_path) { |path| files[path] }
23
+ loader.stub(:load_yaml_file) {|file| catalog_hashes[file] }
24
+
25
+ given_catalog_paths = ['/to/path3', '/to/path1', '/to/path2']
26
+ expected_hash = {
27
+ "rubygems" => {
28
+ "p" => "p2f2",
29
+ "p1" => "p1f1",
30
+ "p2" => "p2f2",
31
+ "p3" => "p3f3",
32
+ "p1f1" => "",
33
+ "p2f1" => "",
34
+ "p2f2" => "",
35
+ "p3f1" => "",
36
+ "p3f2" => "",
37
+ "p3f3" => ""
38
+ }
39
+ }
40
+
41
+ actual_hash = loader.load_from_paths(given_catalog_paths)
42
+ expect(actual_hash).to include(expected_hash)
43
+ end
44
+
45
+ end
46
+
47
+ describe "#yaml_files_in_path" do
48
+ let(:loader) { Natives::Catalog::Loader.new }
49
+
50
+ it "returns a list of *.yml *.yaml filenames in the given path" do
51
+ path = File.join(RSpec.configuration.fixture_path, 'dir_with_matching_files')
52
+ filenames = loader.yaml_files_in_path(path)
53
+ expected_filenames = [
54
+ File.join(path, 'invalid1.yml'),
55
+ File.join(path, 'valid1.yaml'),
56
+ File.join(path, 'valid2.yml')
57
+ ]
58
+ expect(filenames.sort).to eq(expected_filenames.sort)
59
+ end
60
+
61
+ it "returns empty list if there is no matching file in the given path" do
62
+ path = File.join(RSpec.configuration.fixture_path, 'dir_without_matching_file')
63
+ filenames = loader.yaml_files_in_path(path)
64
+ expect(filenames).to eq([])
65
+ end
66
+
67
+ it "returns empty list if the given path does not exist" do
68
+ path = File.join(RSpec.configuration.fixture_path, 'dir_not_exists')
69
+ filenames = loader.yaml_files_in_path(path)
70
+ expect(filenames).to eq([])
71
+ end
72
+ end
73
+
74
+ describe "#load_yaml_file" do
75
+ let(:loader) { Natives::Catalog::Loader.new }
76
+
77
+ it "loads the given file as YAML" do
78
+ valid_file = File.join(RSpec.configuration.fixture_path,
79
+ 'dir_with_matching_files', 'valid1.yaml')
80
+
81
+ hash = loader.load_yaml_file(valid_file)
82
+
83
+ expect(hash).to include("rubygems")
84
+ end
85
+
86
+ it "raises error when the given file contains invalid YAML" do
87
+ valid_file = File.join(RSpec.configuration.fixture_path,
88
+ 'dir_with_matching_files', 'invalid1.yml')
89
+
90
+ expect {
91
+ loader.load_yaml_file(valid_file)
92
+ }.to raise_error
93
+ end
94
+
95
+ it "raises error when the given file does not exist" do
96
+ expect {
97
+ loader.load_yaml_file("file_not_exists.yaml")
98
+ }.to raise_error
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'natives/catalog/merger'
3
+
4
+ describe Natives::Catalog::Merger do
5
+
6
+ describe "#merge_catalog!" do
7
+ let(:merger) { Natives::Catalog::Merger.new }
8
+
9
+ it "validates both master_hash and hash_to_merge" do
10
+ master_hash = {}
11
+ hash_to_merge = {"rubygems" => {}}
12
+ validator = double("Natives::Catalog::Validator")
13
+ merger = Natives::Catalog::Merger.new(validator: validator)
14
+
15
+ validator.should_receive(:ensure_valid_catalog_groups).with(master_hash)
16
+ validator.should_receive(:ensure_valid_catalog_groups).with(hash_to_merge)
17
+
18
+ merger.merge_catalog!(master_hash, hash_to_merge)
19
+ end
20
+
21
+ it "returns master_hash" do
22
+ master_hash = {}
23
+ expect(merger.merge_catalog!(master_hash, {})).to equal(master_hash)
24
+ end
25
+
26
+ it "adds new catalog group into master_hash" do
27
+ master_hash = {}
28
+ hash_to_merge = {"rubygems" => {}}
29
+
30
+ merger.merge_catalog!(master_hash, hash_to_merge)
31
+
32
+ expect(master_hash).to include("rubygems" => {})
33
+ end
34
+
35
+ it "adds new entries into existing catalog group" do
36
+ master_hash = {"rubygems" => { "curb" => {} }}
37
+ hash_to_merge = {"rubygems" => { "nokogiri" => {} }}
38
+
39
+ merger.merge_catalog!(master_hash, hash_to_merge)
40
+
41
+ expect(master_hash).to include(
42
+ "rubygems" => {"curb" => {}, "nokogiri" => {}})
43
+ end
44
+
45
+ it "replaces existing entries in existing catalog group" do
46
+ master_hash = {"rubygems" => {
47
+ "webkit-capybara" => {},
48
+ "curb" => {} }}
49
+ hash_to_merge = {"rubygems" => {
50
+ "curb" => {"foo" => "bar"}, "nokogiri" => {} }}
51
+
52
+ merger.merge_catalog!(master_hash, hash_to_merge)
53
+
54
+ expect(master_hash).to include(
55
+ "rubygems" => {
56
+ "webkit-capybara" => {},
57
+ "curb" => {"foo" => "bar"}, "nokogiri" => {}})
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ require 'natives/catalog/selector'
3
+
4
+ describe Natives::Catalog::Selector do
5
+ describe "#new" do
6
+
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"
74
+ }
75
+ }).normalized_values).to eq({
76
+ "mac_os_x/homebrew" => {
77
+ "default" => "value1",
78
+ "v1" => "value2",
79
+ "v2" => "value2"
80
+ }
81
+ })
82
+ end
83
+ end
84
+ end
85
+
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')
94
+ 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')
104
+ 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')
114
+ 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
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'natives/catalog/validator'
3
+
4
+ describe Natives::Catalog::Validator do
5
+
6
+ describe "#ensure_valid_catalog_groups" do
7
+ let(:validator) { Natives::Catalog::Validator.new }
8
+
9
+ it "ensures catalog groups is a hash" do
10
+ expect {
11
+ validator.ensure_valid_catalog_groups({"rubygems" => {} })
12
+ }.not_to raise_error
13
+ end
14
+
15
+ it "raises error if catalog groups is not a hash" do
16
+ expect {
17
+ validator.ensure_valid_catalog_groups([])
18
+ }.to raise_error ArgumentError
19
+ end
20
+
21
+ it "allows catalog groups to be empty" do
22
+ expect {
23
+ validator.ensure_valid_catalog_groups({})
24
+ }.not_to raise_error
25
+ end
26
+
27
+ it "ensures each catalog group's value is a hash" do
28
+ expect {
29
+ validator.ensure_valid_catalog_groups({"rubygems" => {"a" => "b"} })
30
+ }.not_to raise_error
31
+ end
32
+
33
+ it "raises error if any catalog group's value is not a hash" do
34
+ expect {
35
+ validator.ensure_valid_catalog_groups({
36
+ "rubygems" => {},
37
+ "npm" => nil,
38
+ "foo" => []
39
+ })
40
+ }.to raise_error(ArgumentError,
41
+ "The following catalog group(s) should be a Hash: npm, foo")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'natives/catalog'
3
+
4
+ describe Natives::Catalog do
5
+
6
+ describe "#new" do
7
+ it "loads catalogs" do
8
+ Natives::Catalog.any_instance.should_receive(:reload)
9
+ Natives::Catalog.new('rubygems', 'mac_os_x', '10.7.5', 'homebrew')
10
+ end
11
+
12
+ it "requires caller to provide platform and package provider details" do
13
+ catalog = Natives::Catalog.new('rubygems', 'mac_os_x', '10.7.5', 'homebrew')
14
+ expect(catalog.name).to eq('rubygems')
15
+ expect(catalog.platform).to eq('mac_os_x')
16
+ expect(catalog.platform_version).to eq('10.7.5')
17
+ expect(catalog.package_provider).to eq('homebrew')
18
+ end
19
+ end
20
+
21
+ describe "#reload" do
22
+ it "reloads catalogs from default catalog paths" do
23
+ Natives::Catalog::Loader.any_instance.
24
+ should_receive(:load_from_paths).
25
+ with(Natives::Catalog::CATALOG_PATHS).
26
+ and_return({
27
+ 'rubygems' => {'foo' => {'key' => 'value'}},
28
+ 'npm' => {'bar' => {'key' => 'value'}}
29
+ })
30
+
31
+ catalog = Natives::Catalog.new('rubygems',
32
+ 'mac_os_x', '10.7.5', 'homebrew')
33
+
34
+ expect(catalog.to_hash).to eq({'foo' => {'key' => 'value'}})
35
+ end
36
+ end
37
+
38
+ describe "#to_hash" do
39
+ before do
40
+ Natives::Catalog::Loader.any_instance.
41
+ stub(:load_from_paths).
42
+ with(Natives::Catalog::CATALOG_PATHS).
43
+ and_return({
44
+ 'rubygems' => {'foo' => {'key' => 'value'}},
45
+ 'npm' => {'bar' => {'key' => 'value'}}
46
+ })
47
+ end
48
+
49
+ it "returns catalog hash of the specified catalog name" do
50
+ catalog = Natives::Catalog.new("npm", nil, nil, nil)
51
+ expect(catalog.to_hash).to eq({'bar' => {'key' => 'value'}})
52
+ end
53
+
54
+ it "returns empty hash if the sepcified catalog not found" do
55
+ catalog = Natives::Catalog.new("notfound", nil, nil, nil)
56
+ expect(catalog.to_hash).to eq({})
57
+ end
58
+ end
59
+
60
+ describe "#native_packages_for" do
61
+ before do
62
+ Natives::Catalog::Loader.any_instance.
63
+ stub(:load_from_paths).
64
+ with(Natives::Catalog::CATALOG_PATHS).
65
+ and_return({
66
+ 'rubygems' => {
67
+ 'nokogiri' => {
68
+ 'ubuntu/apt' => {
69
+ '13.10' => 'value1',
70
+ 'default' => 'value2'
71
+ }
72
+ }
73
+ },
74
+ })
75
+ end
76
+
77
+ it "returns native packages for the given catalog entry name" do
78
+ catalog = Natives::Catalog.new(:rubygems, 'ubuntu', '13.10', 'apt')
79
+ expect(catalog.native_packages_for('nokogiri')).to eq(['value1'])
80
+ end
81
+
82
+ it "returns empty list if the given catalog entry name does not exist" do
83
+ catalog = Natives::Catalog.new(:rubygems, 'ubuntu', '13.10', 'apt')
84
+ expect(catalog.native_packages_for('notfound')).to eq([])
85
+ end
86
+ end
87
+
88
+ describe "::CATALOG_PATHS" do
89
+ it "contains the default catalog paths" do
90
+ expect(Natives::Catalog::CATALOG_PATHS).to eq([
91
+ Natives::Catalog::CATALOG_PATH_IN_GEM,
92
+ Natives::Catalog::CATALOG_PATH_IN_WORKING_DIR
93
+ ])
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'natives-catalog'
5
+
6
+ if ENV['COVERAGE']
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+ end
10
+
11
+ # Requires supporting files with custom matchers and macros, etc,
12
+ # in ./support/ and its subdirectories.
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
14
+
15
+ RSpec.configure do |config|
16
+ config.add_setting :fixture_path
17
+ config.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
18
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: natives-catalog
3
+ version: !ruby/object:Gem::Version
4
+ version: !binary |-
5
+ MC4yLjA=
6
+ platform: ruby
7
+ authors:
8
+ - Huiming Teo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chef
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ MTE=
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: !binary |-
29
+ MTE=
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: yard
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: bundler
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: jeweler
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: debugger
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ - !ruby/object:Gem::Dependency
115
+ name: simplecov
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ description: A catalog of native packages in different platforms required by ruby
129
+ gems.
130
+ email: teohuiming@gmail.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files:
134
+ - LICENSE.txt
135
+ - README.md
136
+ files:
137
+ - .document
138
+ - .rspec
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - VERSION
145
+ - catalogs/rubygems.yaml
146
+ - lib/natives-catalog.rb
147
+ - lib/natives/catalog.rb
148
+ - lib/natives/catalog/loader.rb
149
+ - lib/natives/catalog/merger.rb
150
+ - lib/natives/catalog/selector.rb
151
+ - lib/natives/catalog/validator.rb
152
+ - natives-catalog.gemspec
153
+ - spec/fixtures/dir_with_matching_files/invalid1.yml
154
+ - spec/fixtures/dir_with_matching_files/not_matching.json
155
+ - spec/fixtures/dir_with_matching_files/valid1.yaml
156
+ - spec/fixtures/dir_with_matching_files/valid2.yml
157
+ - spec/fixtures/dir_without_matching_file/not_matching.json
158
+ - spec/natives/catalog/loader_spec.rb
159
+ - spec/natives/catalog/merger_spec.rb
160
+ - spec/natives/catalog/selector_spec.rb
161
+ - spec/natives/catalog/validator_spec.rb
162
+ - spec/natives/catalog_spec.rb
163
+ - spec/spec_helper.rb
164
+ homepage: http://github.com/teohm/natives-catalog
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.1.9
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: A catalog of native packages for ruby gems.
188
+ test_files: []