jenkins-plugin-runtime 0.1.5 → 0.1.6

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.
@@ -1,7 +1,7 @@
1
1
  module Jenkins
2
2
  class Plugin
3
3
  module Runtime
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
6
6
  end
7
7
  end
@@ -39,11 +39,37 @@ module Jenkins
39
39
  end
40
40
  end
41
41
 
42
+ # Evaluates `path` as ruby code, expecting it to contain an instance
43
+ # of `Jenkins::Plugin::Specification`.
44
+ #
45
+ # @return [Jenkins::Plugin::Specification] the loaded specification
42
46
  def self.load(path)
43
47
  eval(File.read(path), binding, path, 1)
44
48
  end
49
+
50
+ # Looks inside `dir` for a file ending in .pluginspec, and if found,
51
+ # loads it.
52
+ #
53
+ # @return [Jenkins::Plugin::Specification] the loaded specification object, nil otherwise
54
+ def self.find(dir = Dir.pwd)
55
+ dir = Pathname(dir)
56
+ if spec_path = Pathname(dir).entries.find {|e| e.to_s =~ /\.pluginspec$/}
57
+ load(dir.join(spec_path))
58
+ end
59
+ rescue Errno::ENOENT => e
60
+ fail SpecificationNotFound, "#{dir} does not appear to be a directory"
61
+ end
62
+
63
+ # Attempts to `#find` a plugin spec in `dir` and raises an exception if unsuccessful
64
+ #
65
+ # @param [String] path in which to look
66
+ # @return [Jenkins::Plugin::Specification] the found specifiaction object
67
+ def self.find!(dir = Dir.pwd)
68
+ find(dir) or fail SpecificationNotFound, "no plugin specification found in #{dir}"
69
+ end
45
70
  end
46
71
 
47
72
  SpecificationError = Class.new(StandardError)
73
+ SpecificationNotFound = Class.new(SpecificationError)
48
74
  end
49
75
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Jenkins::Plugin::Specification do
4
+ Specification = Jenkins::Plugin::Specification
4
5
  it "is invalid by default" do
5
6
  expect {subject.validate!}.should raise_error Jenkins::Plugin::SpecificationError
6
7
  end
@@ -19,10 +20,19 @@ describe Jenkins::Plugin::Specification do
19
20
  end
20
21
 
21
22
  describe "a spec loaded from a file" do
22
- subject {Jenkins::Plugin::Specification.load(Pathname(__FILE__).dirname.join('example.pluginspec'))}
23
+ subject {Specification.load(Pathname(__FILE__).dirname.join('example.pluginspec'))}
23
24
  its(:name) {should eql "the-name"}
24
25
  its(:version) {should eql "1.0.0"}
25
26
  its(:description) {should eql "one great plugin"}
26
27
  its(:dependencies) {should be_empty}
27
28
  end
29
+
30
+ describe "find!" do
31
+ it "looks for a .pluginspec in the current directory and loads it" do
32
+ Specification.find!(Pathname(__FILE__).dirname.to_s).name.should eql "the-name"
33
+ end
34
+ it "raises an exception if one cannot be found" do
35
+ expect {Specification.find!('..')}.should raise_error Jenkins::Plugin::SpecificationNotFound
36
+ end
37
+ end
28
38
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jenkins-plugin-runtime
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-16 00:00:00 -05:00
13
+ date: 2011-09-19 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency