gem-content 0.0.1 → 1.0.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
  SHA1:
3
- metadata.gz: 50aeb6e3b5db212e8dec98eeebf81ad91c6e5551
4
- data.tar.gz: 0261aabe5a473a72be81e3698e933c7850b02d37
3
+ metadata.gz: f35a306f31ac54437438fc0ee24fca20e9f8dc90
4
+ data.tar.gz: 4b8c7ef518e994c297ddcd5cea8b2c30f29db6dd
5
5
  SHA512:
6
- metadata.gz: b61e70facfeeeb4b1f2c8e857a541291028a28267e28f35479e5f268e6f6eeaa880daedfba83d894d93f270be6ff1a697bbdd9b0fb2c96b7c9d97bbeaffab5dc
7
- data.tar.gz: 63c4b500b0b486014f44b9e13273bf3098267b87af67f73111f5c33fe82b1fe7d26a0c528c43ab2efb3e13a2f4a45a2bf11a1dc1efa2c8b45a32ff0edc67a76d
6
+ metadata.gz: fcf87c6bc3e7b5ac019490d57d27552c965b2b78127b76085462ecc69fc566b8c8eed7ba16d41a273095dd6bdfd8fb88751ebe9a3b99ec554f65394a351e20ac
7
+ data.tar.gz: c7b1f2b9bb3cf4722e5d0db75a4494fa7cb1dd54500e45416dff7bf10c688db90aff7e10f8710c0663f570af79ed100e42fc626571cfcba9afb1b8151943face
data/lib/gem-content.rb CHANGED
@@ -5,3 +5,62 @@ See the file LICENSE for copying permission.
5
5
  =end
6
6
 
7
7
  require "gem-content/version"
8
+
9
+ # Find gems with defined content name in metadata and
10
+ # return pull path to the content
11
+ class GemContent
12
+
13
+ # shortcut to initialize and get the paths in one line
14
+ # @param content_name [String] the path marker to read from gems metadata
15
+ # @return [Array<String>] all gems paths containing requested content
16
+ def self.get_gem_paths(content_name)
17
+ self.new(content_name).get_gem_paths
18
+ end
19
+
20
+ # @return [String] content name filter
21
+ attr_reader :content_name
22
+
23
+ # initializes the filtered content path
24
+ # @param content_name [String] the path marker to read from gems metadata
25
+ def initialize(content_name)
26
+ @content_name = content_name
27
+ end
28
+
29
+ # @return [Array<String>] all gems paths containing requested content
30
+ def get_gem_paths
31
+ active_or_latest_gems_matching.map do |specification|
32
+ File.join(
33
+ specification.full_gem_path,
34
+ specification.metadata[content_name]
35
+ )
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # filter active / latest gem versions
42
+ def active_or_latest_gems_matching
43
+ all_gems_matching.group_by(&:name).map(&method(:active_or_latest_gem))
44
+ end
45
+
46
+ # find active or latest gem in given set
47
+ def active_or_latest_gem(params)
48
+ _, specifications = params
49
+ specifications.find(&:activated) or
50
+ specifications.sort_by(&:version).last
51
+ end
52
+
53
+ # filter gems with content_name metadata
54
+ def all_gems_matching
55
+ all_gems.select do |specification|
56
+ specification.metadata.is_a?(Hash) and
57
+ specification.metadata[content_name]
58
+ end
59
+ end
60
+
61
+ # get all gem specifications
62
+ def all_gems
63
+ Gem::Specification._all
64
+ end
65
+
66
+ end
@@ -5,5 +5,5 @@ See the file LICENSE for copying permission.
5
5
  =end
6
6
 
7
7
  class GemContent
8
- VERSION = "0.0.1"
8
+ VERSION = "1.0.0"
9
9
  end
@@ -0,0 +1,90 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "test_helper"
8
+ require "context-filters/context"
9
+
10
+ describe GemContent do
11
+
12
+ subject do
13
+ GemContent.new("some-templates")
14
+ end
15
+
16
+ let(:gems_all) do
17
+ Gem::Specification._all
18
+ end
19
+
20
+ let(:gems_one) do
21
+ gems_all.select{|s| s.name == "fake-gem-name-one"}
22
+ end
23
+
24
+ let(:gems_one_expected) do
25
+ gems_one.select{|s| s.metadata && s.metadata["some-templates"] }
26
+ end
27
+
28
+ let(:gems_two) do
29
+ gems_all.select{|s| s.name == "fake-gem-name-two"}
30
+ end
31
+
32
+ before do
33
+ gems_two.find{ |s| s.version == Gem::Version.new("1.0.0") }.activate
34
+ end
35
+
36
+ it "initializes content_name" do
37
+ subject.content_name.must_equal("some-templates")
38
+ end
39
+
40
+ it "detects gems" do
41
+ subject.expects(:all_gems).returns(gems_one)
42
+ subject.send(:all_gems_matching).sort.must_equal(gems_one_expected.sort)
43
+ end
44
+
45
+ it "finds latest gems" do
46
+ subject.expects(:all_gems_matching).returns(gems_one_expected)
47
+ subject.send(:active_or_latest_gems_matching).must_equal([gems_one_expected.sort.last])
48
+ end
49
+
50
+ it "finds latest gem from list" do
51
+ subject.send(:active_or_latest_gem, ["fake-gem-name-one", gems_one_expected]).must_equal(gems_one_expected.sort.last)
52
+ end
53
+
54
+ it "finds active gems" do
55
+ subject.expects(:all_gems_matching).returns(gems_two)
56
+ subject.send(:active_or_latest_gems_matching).must_equal([gems_two.sort.first])
57
+ end
58
+
59
+ it "finds active gem on list" do
60
+ subject.send(:active_or_latest_gem, ["fake-gem-name-two", gems_two]).must_equal(gems_two.sort.first)
61
+ end
62
+
63
+ it "returns gems paths" do
64
+ subject.expects(:active_or_latest_gems_matching).returns(gems_one_expected.sort)
65
+ subject.get_gem_paths.must_equal(
66
+ [
67
+ File.expand_path("../gems/gems/fake-gem-name-one-1.0.0/templates-v1", __FILE__),
68
+ File.expand_path("../gems/gems/fake-gem-name-one-2.0.0/templates-v2", __FILE__),
69
+ ]
70
+ )
71
+ end
72
+
73
+ it "returns gems paths - no mocking - the real test" do
74
+ subject.get_gem_paths.must_equal(
75
+ [
76
+ File.expand_path("../gems/gems/fake-gem-name-one-2.0.0/templates-v2", __FILE__),
77
+ File.expand_path("../gems/gems/fake-gem-name-two-1.0.0/templates-v1", __FILE__),
78
+ ]
79
+ )
80
+ end
81
+
82
+ it "has class helper" do
83
+ test_subject = mock()
84
+ test_subject.expects(:get_gem_paths).once.returns([:a, :b])
85
+ GemContent.expects(:new).once.with("some-templates").returns(test_subject)
86
+
87
+ GemContent.get_gem_paths("some-templates").must_equal([:a, :b])
88
+ end
89
+
90
+ end
@@ -0,0 +1,42 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ require "rubygems"
8
+ require "minitest"
9
+
10
+ # fix lib in LOAD_PATH and load version for gems manipulation
11
+ lib = File.expand_path("../lib", __FILE__)
12
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
13
+
14
+ # register our own path with gems
15
+ Gem.path << File.expand_path("../gems", __FILE__)
16
+ Gem.refresh
17
+
18
+ if
19
+ RUBY_VERSION == "2.0.0" && # check Gemfile
20
+ $0 != "-e" # do not do that in guard
21
+ then
22
+ require "coveralls"
23
+ require "simplecov"
24
+
25
+ SimpleCov.start do
26
+ formatter SimpleCov::Formatter::MultiFormatter[
27
+ SimpleCov::Formatter::HTMLFormatter,
28
+ Coveralls::SimpleCov::Formatter,
29
+ ]
30
+ command_name "Unit Tests"
31
+ add_filter "/test/"
32
+ end
33
+
34
+ Coveralls.noisy = true unless ENV["CI"]
35
+ end
36
+
37
+ # Autoload all lib/**/*.rb files so simplecov does not misses anything
38
+ Dir[File.expand_path("../../lib/**/*.rb", __FILE__)].each{|f| require f }
39
+
40
+ require "minitest/autorun" unless $0=="-e" # skip in guard
41
+ require "minitest/unit"
42
+ require "mocha/setup"
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-18 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: context-filters
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '0.11'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '0.11'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: guard
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +103,12 @@ extra_rdoc_files: []
117
103
  files:
118
104
  - lib/gem-content.rb
119
105
  - lib/gem-content/version.rb
106
+ - test/gem-content_test.rb
107
+ - test/gems/gems/fake-gem-name-one-1.0.0/lib/fake-gem-name-one.rb
108
+ - test/gems/gems/fake-gem-name-one-2.0.0/lib/fake-gem-name-one.rb
109
+ - test/gems/gems/fake-gem-name-two-1.0.0/lib/fake-gem-name-two.rb
110
+ - test/gems/gems/fake-gem-name-two-2.0.0/lib/fake-gem-name-two.rb
111
+ - test/test_helper.rb
120
112
  homepage: https://github.com/mpapis/gem-content
121
113
  licenses:
122
114
  - MIT
@@ -141,5 +133,11 @@ rubygems_version: 2.2.2
141
133
  signing_key:
142
134
  specification_version: 4
143
135
  summary: Search gems for content directory
144
- test_files: []
136
+ test_files:
137
+ - test/test_helper.rb
138
+ - test/gems/gems/fake-gem-name-one-1.0.0/lib/fake-gem-name-one.rb
139
+ - test/gems/gems/fake-gem-name-one-2.0.0/lib/fake-gem-name-one.rb
140
+ - test/gems/gems/fake-gem-name-two-1.0.0/lib/fake-gem-name-two.rb
141
+ - test/gems/gems/fake-gem-name-two-2.0.0/lib/fake-gem-name-two.rb
142
+ - test/gem-content_test.rb
145
143
  has_rdoc: