everyday-plugins 1.0.0 → 1.1.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: aef7ff8b3547cb61a4fe29ba134fc62a33899dea
4
- data.tar.gz: 5ac025923337b937c39c2ae97aa76c725549619b
3
+ metadata.gz: f5261638c746e3841cd0eb250b76fc6d00102ebd
4
+ data.tar.gz: 88f21dd9ddc7be4345739315ecfe0037763a126e
5
5
  SHA512:
6
- metadata.gz: 1c51fe1fc1b868bf1300d7955b073fe5e73da16845b20fe038fe9d5a8fb4dcec4ec1c27a77fa458d5455a701e0447d42702e45f4a41f456829e8aaa67087e51b
7
- data.tar.gz: cba503a3718084028bc52d40eb44892bd490cd2809b79889209e35cbf7c30c3026ef57a74025e3ef64625c1ade6339bb8666f6c1d1373559605cd862b723da39
6
+ metadata.gz: c2c1926e386e1f9a6cc586ee145fa9ac6f2ce8c87182275d807a6004020dc9309b45ae79b4d54fba1da2185830c0b0ab43b4d66a839307e728be3d635560a999
7
+ data.tar.gz: 50a30e9063b3b723128f3651b298e2206290509cf0f45ad6a96692a06c8d6fb1fd1175109fa66639b4986ca2ca14a48de56570440d03fcd20a0163a4f55add5e
data/README.md CHANGED
@@ -18,6 +18,29 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ###For conditionally running plugin setup code (or other code) based on installed gems
22
+ As of version 1.1.0, there is support for running a block of code based on whether or not certain gems are installed. This is via the `EverydayPlugins::Loader` module. You can either `extend` it and use the `depend` method like any other plugin setup method, or you can use the static `EverydayPlugins::Loader.depend` method. The method takes each dependency as a separate argument. If you want to specify more than just the name of the gem (for example, if you want to require a minimum version), you need to put the parameters for that argument into an array.
23
+
24
+ Here is an example:
25
+
26
+ ```ruby
27
+ EverydayPlugins::Loader.depend(['bundler', '~> 1.5'], 'rake') {
28
+ #do stuff here
29
+ }
30
+ ```
31
+
32
+ And here is an example using `extend`:
33
+
34
+ ```ruby
35
+ class MyLoader
36
+ extend EverydayPlugins::Loader
37
+
38
+ depend(['bundler', '~> 1.5'], 'rake') {
39
+ #do stuff here
40
+ }
41
+ end
42
+ ```
43
+
21
44
  ###For supporting plugins:
22
45
  See below for info on defining and using plugin types. As for including plugins, use
23
46
 
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new('spec')
7
+
8
+ task :default => :spec
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency 'bundler', '~> 1.5'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
24
25
  end
@@ -86,6 +86,19 @@ module EverydayPlugins
86
86
  instance.set_vars(vars)
87
87
  end
88
88
  end
89
+ module Loader
90
+ def depend(*deps, &block)
91
+ EverydayPlugins::Loader.depend(*deps, &block)
92
+ end
93
+
94
+ def self.depend(*deps, &block)
95
+ met = deps.all? { |dep|
96
+ matches = Gem::Specification.find_all_by_name(*dep)
97
+ !(matches.nil? || matches.empty?)
98
+ }
99
+ block.call if met
100
+ end
101
+ end
89
102
  module Plugin
90
103
  def register(type, options = {}, &block)
91
104
  EverydayPlugins::Plugins.instance.register(type, options, &block)
@@ -1,3 +1,3 @@
1
1
  module EverydayPlugins
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -0,0 +1,30 @@
1
+ require_relative '../lib/everyday-plugins/plugin'
2
+ class Loader1
3
+ extend EverydayPlugins::Loader
4
+ end
5
+
6
+ describe EverydayPlugins::Loader do
7
+ it 'runs the block when the dependencies are met' do
8
+ rval = false
9
+ Loader1.depend(['bundler', '~> 1.5'], 'rake') { rval = true }
10
+ rval.should be_true
11
+ end
12
+
13
+ it 'does not run the block when the dependencies are not met' do
14
+ rval = false
15
+ Loader1.depend(['bundler', '>= 10.5'], 'rake') { rval = true }
16
+ rval.should be_false
17
+ end
18
+
19
+ it 'runs the block when the dependencies are met using a static method' do
20
+ rval = false
21
+ EverydayPlugins::Loader.depend(['bundler', '~> 1.5'], 'rake') { rval = true }
22
+ rval.should be_true
23
+ end
24
+
25
+ it 'does not run the block when the dependencies are not met using a static method' do
26
+ rval = false
27
+ EverydayPlugins::Loader.depend(['bundler', '>= 10.5'], 'rake') { rval = true }
28
+ rval.should be_false
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everyday-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: A simple gem plugin system. Extracted from the mvn2 gem.
42
56
  email:
43
57
  - henderea@gmail.com
@@ -54,6 +68,7 @@ files:
54
68
  - lib/everyday-plugins.rb
55
69
  - lib/everyday-plugins/plugin.rb
56
70
  - lib/everyday-plugins/version.rb
71
+ - spec/loader_spec.rb
57
72
  homepage: https://github.com/henderea/everyday-plugins
58
73
  licenses:
59
74
  - MIT
@@ -78,5 +93,6 @@ rubygems_version: 2.2.0
78
93
  signing_key:
79
94
  specification_version: 4
80
95
  summary: A simple gem plugin system
81
- test_files: []
96
+ test_files:
97
+ - spec/loader_spec.rb
82
98
  has_rdoc: