ddplugin 1.0.1 → 1.0.2

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
- SHA1:
3
- metadata.gz: 19d0ae996f2999cccb30bc44777e07a1b0c04f1e
4
- data.tar.gz: 8b0bda0c3d2bf442a8e1e8d49313c8b57ff44498
2
+ SHA256:
3
+ metadata.gz: 998e406c491ddfcde5cd7559cd22084fca1327f1b27b8dd177d6fe21b30ff79b
4
+ data.tar.gz: 0b3673fdf1c69fc0ae67ca50ef4ac6575a9973e58d50d86b3a86a91ef3a6c796
5
5
  SHA512:
6
- metadata.gz: f4eb79aa5c0cd23076cf4b32fe37ee40357bf77cf2c6b72929999c1af65f48a44ca29cada37632cebeb53177b694bc9500b9c5dd3c0c9f0bb16a2da4d1334d51
7
- data.tar.gz: 39fe5a9c5b28043cc0c218bed98a2125e100660511a86ddf68e95dfe57fce1cc0902413f3fd05e5660b9a09474bfd2503eb7878b269cef04b1311a56bd87dc61
6
+ metadata.gz: 52a6bfdfadc2f47031beb29dc586cd81e2cf7bfb756148f8f1dec312b890701c075406ba3dbbf9694dc5f084ece2d311b03c78ffa844afa6ccf61b53c80ac98f
7
+ data.tar.gz: 65684a38e9e46dbf83da7e010269712280c7605a9d141ff46a799809f1621dd37edb0feedc019f98e6bbb68753162516fb829628e5526df9f3404911c2ceeeac
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
7
+ gem 'coveralls', require: false
5
8
  gem 'minitest'
6
9
  gem 'rake'
7
- gem 'coveralls', require: false
8
10
  gem 'rubocop'
@@ -1,43 +1,45 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ddplugin (1.0.1)
4
+ ddplugin (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.3.0)
10
- coveralls (0.8.19)
9
+ ast (2.4.0)
10
+ coveralls (0.8.21)
11
11
  json (>= 1.8, < 3)
12
- simplecov (~> 0.12.0)
12
+ simplecov (~> 0.14.1)
13
13
  term-ansicolor (~> 1.3)
14
- thor (~> 0.19.1)
14
+ thor (~> 0.19.4)
15
15
  tins (~> 1.6)
16
16
  docile (1.1.5)
17
- json (2.0.3)
18
- minitest (5.10.1)
19
- parser (2.4.0.0)
20
- ast (~> 2.2)
17
+ json (2.1.0)
18
+ minitest (5.11.3)
19
+ parallel (1.12.1)
20
+ parser (2.5.0.5)
21
+ ast (~> 2.4.0)
21
22
  powerpack (0.1.1)
22
- rainbow (2.2.1)
23
- rake (12.0.0)
24
- rubocop (0.47.1)
25
- parser (>= 2.3.3.1, < 3.0)
23
+ rainbow (3.0.0)
24
+ rake (12.3.1)
25
+ rubocop (0.54.0)
26
+ parallel (~> 1.10)
27
+ parser (>= 2.5)
26
28
  powerpack (~> 0.1)
27
- rainbow (>= 1.99.1, < 3.0)
29
+ rainbow (>= 2.2.2, < 4.0)
28
30
  ruby-progressbar (~> 1.7)
29
31
  unicode-display_width (~> 1.0, >= 1.0.1)
30
- ruby-progressbar (1.8.1)
31
- simplecov (0.12.0)
32
+ ruby-progressbar (1.9.0)
33
+ simplecov (0.14.1)
32
34
  docile (~> 1.1.0)
33
35
  json (>= 1.8, < 3)
34
36
  simplecov-html (~> 0.10.0)
35
- simplecov-html (0.10.0)
36
- term-ansicolor (1.4.0)
37
+ simplecov-html (0.10.2)
38
+ term-ansicolor (1.6.0)
37
39
  tins (~> 1.0)
38
40
  thor (0.19.4)
39
- tins (1.13.2)
40
- unicode-display_width (1.1.3)
41
+ tins (1.16.3)
42
+ unicode-display_width (1.3.0)
41
43
 
42
44
  PLATFORMS
43
45
  ruby
@@ -51,4 +53,4 @@ DEPENDENCIES
51
53
  rubocop
52
54
 
53
55
  BUNDLED WITH
54
- 1.14.5
56
+ 1.16.1
data/NEWS.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ddplugin release notes
2
2
 
3
+ ## 1.0.2 (2018-03-31)
4
+
5
+ Enhancements:
6
+
7
+ * Made it possible to pass strings instead of symbols (#4)
8
+
3
9
  ## 1.0.1 (2017-02-28)
4
10
 
5
11
  Fixes:
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
- [![Build Status](https://travis-ci.org/ddfreyne/ddplugin.png)](https://travis-ci.org/ddfreyne/ddplugin)
2
- [![Code Climate](https://codeclimate.com/github/ddfreyne/ddplugin.png)](https://codeclimate.com/github/ddfreyne/ddplugin)
3
- [![Coverage Status](https://coveralls.io/repos/ddfreyne/ddplugin/badge.png?branch=master)](https://coveralls.io/r/ddfreyne/ddplugin)
4
- [![Inline docs](http://inch-ci.org/github/ddfreyne/ddplugin.png)](http://inch-ci.org/github/ddfreyne/ddplugin)
1
+ [![Gem version](http://img.shields.io/gem/v/ddplugin.svg)](http://rubygems.org/gems/ddplugin)
2
+ [![Gem downloads](https://img.shields.io/gem/dt/ddplugin.svg)](http://rubygems.org/gems/ddplugin)
3
+ [![Build status](http://img.shields.io/travis/ddfreyne/ddplugin.svg)](https://travis-ci.org/ddfreyne/ddplugin)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/ddfreyne/ddplugin.svg)](https://codeclimate.com/github/ddfreyne/ddplugin)
5
+ [![Code Coverage](https://img.shields.io/coveralls/ddfreyne/ddplugin.svg)](https://coveralls.io/r/ddfreyne/ddplugin)
5
6
 
6
7
  # ddplugin
7
8
 
@@ -29,7 +30,7 @@ A typical way to use plugins would be to store the plugin names in a configurati
29
30
 
30
31
  ## Requirements
31
32
 
32
- *ddplugin* requires Ruby 2.1 or higher.
33
+ *ddplugin* requires Ruby 2.3 or higher.
33
34
 
34
35
  ## Versioning
35
36
 
@@ -63,23 +64,27 @@ class DataSource
63
64
  end
64
65
  ```
65
66
 
66
- To define a plugin, create a class that inherits from the plugin type and sets the identifier:
67
+ To define a plugin, create a class that inherits from the plugin type and sets the identifier, either as a symbol or a string:
67
68
 
68
69
  ```ruby
69
70
  class ERBFilter < Filter
71
+ # Specify the identifier as a symbol…
70
72
  identifier :erb
71
73
  end
72
74
 
73
75
  class HamlFilter < Filter
74
- identifier :haml
76
+ # … or as a string …
77
+ identifier 'haml'
75
78
  end
76
79
 
77
80
  class FilesystemDataSource < DataSource
78
- identifier :filesystem
81
+ # … or even provide multiple.
82
+ identifiers :filesystem, :file_system
79
83
  end
80
84
 
81
85
  class PostgresDataSource < DataSource
82
- identifier :postgres
86
+ # … or mix and match (not sure why you would, though)
87
+ identifier :postgres, 'postgresql'
83
88
  end
84
89
  ```
85
90
 
@@ -89,7 +94,7 @@ To find a plugin of a given type and with a given identifier, call `.named` on t
89
94
  Filter.named(:erb)
90
95
  # => ERBFilter
91
96
 
92
- Filter.named(:haml)
97
+ Filter.named('haml')
93
98
  # => HamlFilter
94
99
 
95
100
  DataSource.named(:filesystem)
@@ -99,22 +104,50 @@ DataSource.named(:postgres)
99
104
  # => PostgresDataSource
100
105
  ```
101
106
 
107
+ In a real-world situation, the plugin types could be described in the environment:
108
+
109
+ ```
110
+ % cat .env
111
+ DATA_SOURCE_TYPE=postgres
112
+ ```
113
+
114
+ ```ruby
115
+ DataSource.named(ENV.fetch('DATA_SOURCE_TYPE'))
116
+ # => PostgresDataSource
117
+ ```
118
+
119
+ … or in a configuration file:
120
+
121
+ ```
122
+ % cat config.yml
123
+ data_source: 'filesystem'
124
+ ```
125
+
126
+ ```ruby
127
+ config = YAML.load_file('config.yml')
128
+ DataSource.named(config.fetch('data_source'))
129
+ # => FilesystemDataSource
130
+ ```
131
+
102
132
  To get all plugins of a given type, call `.all` on the plugin type:
103
133
 
104
134
  ```ruby
105
135
  Filter.all
106
- # => [ ERBFilter, HamlFilter ]
136
+ # => [ERBFilter, HamlFilter]
107
137
 
108
138
  DataSource.all
109
- # => [ FilesystemDataSource, PostgresDataSource ]
139
+ # => [FilesystemDataSource, PostgresDataSource]
110
140
  ```
111
141
 
112
- To get the identifier of a plugin, call `.identifier`:
142
+ To get the identifier of a plugin, call `.identifier`, which returns a symbol:
113
143
 
114
144
  ```ruby
115
145
  Filter.named(:erb).identifier
116
146
  # => :erb
117
147
 
148
+ Filter.named('haml').identifier
149
+ # => :haml
150
+
118
151
  PostgresDataSource.identifier
119
152
  # => :postgres
120
153
  ```
@@ -125,8 +158,9 @@ Pull requests and issues are greatly appreciated.
125
158
 
126
159
  When you submit a pull request, make sure that your change is covered by tests, and that the `README` and [YARD](http://yardoc.org/) source code documentation are still up-to-date.
127
160
 
128
- To run the tests, execute `rake`:
161
+ To run the tests:
129
162
 
130
163
  ```
131
- % rake
164
+ % bundle install
165
+ % bundle exec rake
132
166
  ```
data/Rakefile CHANGED
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/testtask'
2
4
  require 'rubocop/rake_task'
3
5
 
4
6
  Rake::TestTask.new do |t|
5
- t.libs = %w( lib test )
7
+ t.libs = %w[lib test]
6
8
  t.test_files = FileList['test/**/test_*.rb', 'test/**/*_spec.rb']
7
9
  end
8
10
 
9
11
  RuboCop::RakeTask.new do |task|
10
- task.options = %w(--display-cop-names --format simple)
12
+ task.options = %w[--display-cop-names --format simple]
11
13
  task.patterns = ['lib/**/*.rb', 'test/**/*.rb']
12
14
  end
13
15
 
14
- task :default => [:test, :rubocop]
16
+ task default: %i[test rubocop]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/ddplugin/version'
2
4
 
3
5
  Gem::Specification.new do |s|
@@ -11,15 +13,15 @@ Gem::Specification.new do |s|
11
13
  s.email = 'denis.defreyne@stoneship.org'
12
14
  s.license = 'MIT'
13
15
 
14
- s.required_ruby_version = '>= 2.1.0'
16
+ s.required_ruby_version = '~> 2.3'
15
17
 
16
18
  s.files = Dir['[A-Z]*'] +
17
19
  Dir['{lib,test}/**/*'] +
18
- [ 'ddplugin.gemspec' ]
19
- s.require_paths = [ 'lib' ]
20
+ ['ddplugin.gemspec']
21
+ s.require_paths = ['lib']
20
22
 
21
- s.rdoc_options = [ '--main', 'README.md' ]
22
- s.extra_rdoc_files = [ 'LICENSE', 'README.md', 'NEWS.md' ]
23
+ s.rdoc_options = ['--main', 'README.md']
24
+ s.extra_rdoc_files = ['LICENSE', 'README.md', 'NEWS.md']
23
25
 
24
26
  s.add_development_dependency('bundler', '~> 1.13')
25
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ddplugin/version'
2
4
  require 'ddplugin/plugin'
3
5
  require 'ddplugin/registry'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DDPlugin
2
4
  # A module that contains class methods for plugins. It provides functions
3
5
  # for setting identifiers and finding plugins. Plugin classes should extend
@@ -7,8 +9,8 @@ module DDPlugin
7
9
  #
8
10
  # Sets the identifiers for this class.
9
11
  #
10
- # @param [Array<Symbol>] identifiers A list of identifiers to assign to
11
- # this class.
12
+ # @param [Array<Symbol, String>] identifiers A list of identifiers to
13
+ # assign to this class.
12
14
  #
13
15
  # @return [void]
14
16
  #
@@ -34,7 +36,8 @@ module DDPlugin
34
36
  #
35
37
  # Sets the identifier for this class.
36
38
  #
37
- # @param [Symbol] identifier The identifier to assign to this class.
39
+ # @param [Symbol, String] identifier The identifier to assign to this
40
+ # class.
38
41
  #
39
42
  # @return [void]
40
43
  #
@@ -54,7 +57,7 @@ module DDPlugin
54
57
  DDPlugin::Registry.instance.find_all(self)
55
58
  end
56
59
 
57
- # @param [Symbol] identifier The identifier of the class to find
60
+ # @param [Symbol, String] identifier The identifier of the class to find
58
61
  #
59
62
  # @return [Class] The class with the given identifier
60
63
  def named(identifier)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DDPlugin
2
4
  # The registry is responsible for keeping track of all loaded plugins.
3
5
  class Registry
@@ -25,7 +27,7 @@ module DDPlugin
25
27
  #
26
28
  # @return [void]
27
29
  def register(root_class, klass, *identifiers)
28
- identifiers.each do |identifier|
30
+ identifiers.map(&:to_sym).each do |identifier|
29
31
  @classes_to_identifiers[root_class][klass] ||= []
30
32
 
31
33
  @identifiers_to_classes[root_class][identifier] = klass
@@ -53,6 +55,7 @@ module DDPlugin
53
55
  #
54
56
  # @return [Class, nil] The class with the given identifier
55
57
  def find(root_class, identifier)
58
+ identifier = identifier.to_sym
56
59
  @identifiers_to_classes[root_class] ||= {}
57
60
  @identifiers_to_classes[root_class][identifier]
58
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DDPlugin
2
- VERSION = '1.0.1'.freeze
4
+ VERSION = '1.0.2'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'coveralls'
2
4
  Coveralls.wear!
3
5
 
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'helper'
2
4
 
3
- class DDPlugin::PluginTest < Minitest::Test
5
+ class PluginTest < Minitest::Test
4
6
  class IdentifierSample
5
7
  extend DDPlugin::Plugin
6
8
  end
@@ -28,15 +30,34 @@ class DDPlugin::PluginTest < Minitest::Test
28
30
  assert_equal :foo, klass.identifier
29
31
  end
30
32
 
33
+ def test_identifier_with_string
34
+ klass = Class.new(IdentifierSample)
35
+ assert_nil klass.identifier
36
+
37
+ klass.identifier 'asdf'
38
+ assert_equal :asdf, klass.identifier
39
+ end
40
+
31
41
  def test_identifiers
32
42
  klass = Class.new(IdentifierSample)
33
43
  assert_empty klass.identifiers
34
44
 
35
45
  klass.identifiers :foo1, :foo2
36
- assert_equal [:foo1, :foo2], klass.identifiers
46
+ assert_equal %i[foo1 foo2], klass.identifiers
37
47
 
38
48
  klass.identifiers :bar1, :bar2
39
- assert_equal [:foo1, :foo2, :bar1, :bar2], klass.identifiers
49
+ assert_equal %i[foo1 foo2 bar1 bar2], klass.identifiers
50
+ end
51
+
52
+ def test_identifiers_with_string
53
+ klass = Class.new(IdentifierSample)
54
+ assert_empty klass.identifiers
55
+
56
+ klass.identifiers 'foo1', 'foo2'
57
+ assert_equal %i[foo1 foo2], klass.identifiers
58
+
59
+ klass.identifiers 'bar1', 'bar2'
60
+ assert_equal %i[foo1 foo2 bar1 bar2], klass.identifiers
40
61
  end
41
62
 
42
63
  def test_root
@@ -50,7 +71,7 @@ class DDPlugin::PluginTest < Minitest::Test
50
71
  assert_equal subklass, InheritanceSample.named(:sub)
51
72
 
52
73
  assert_equal :sub, subklass.identifier
53
- assert_equal [:sub, :also_sub], subklass.identifiers
74
+ assert_equal %i[sub also_sub], subklass.identifiers
54
75
 
55
76
  assert_equal InheritanceSample, superklass.root_class
56
77
  assert_equal InheritanceSample, subklass.root_class
@@ -64,6 +85,14 @@ class DDPlugin::PluginTest < Minitest::Test
64
85
  assert_equal klass, NamedSample.named(:named_test)
65
86
  end
66
87
 
88
+ def test_named_with_string
89
+ klass = Class.new(NamedSample)
90
+ klass.identifier :named_test
91
+
92
+ assert_nil NamedSample.named('unknown')
93
+ assert_equal klass, NamedSample.named('named_test')
94
+ end
95
+
67
96
  def test_all
68
97
  klass1 = Class.new(AllSample)
69
98
  klass1.identifier :one
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddplugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-28 00:00:00.000000000 Z
11
+ date: 2018-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,9 +58,9 @@ require_paths:
58
58
  - lib
59
59
  required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 2.1.0
63
+ version: '2.3'
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 2.6.10
71
+ rubygems_version: 2.7.6
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Plugins for Ruby apps