pluginator 0.9.2 → 0.9.3

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.
@@ -0,0 +1,69 @@
1
+ require 'pluginator'
2
+
3
+ class Pluginator
4
+ class UnknownPlugin < StandardError
5
+ def initialize(plugin_type, handler)
6
+ super "Unknown #{plugin_type}: #{handler}"
7
+ end
8
+ end
9
+
10
+ module ExtraNames
11
+ def last_name
12
+ self.name.split(/::/).last
13
+ end
14
+ def last_name_to_sym
15
+ class2file(last_name).to_sym
16
+ end
17
+ def first_name
18
+ self.name.split(/::/).first
19
+ end
20
+ def first_name_to_sym
21
+ class2file(first_name).to_sym
22
+ end
23
+ def class2file(klass)
24
+ klass.gsub(/([A-Z])/){|x| "_#{x.downcase}"}[1..-1]
25
+ end
26
+ end
27
+
28
+ class PluginHandler
29
+ extend ExtraNames
30
+
31
+ class Abstract
32
+ extend ExtraNames
33
+ def self.handles
34
+ last_name_to_sym
35
+ end
36
+ end
37
+
38
+ class << self
39
+ attr_accessor :plugin_prefix
40
+ attr_accessor :plugin_type
41
+ end
42
+
43
+ def self.first(handler)
44
+ result = plugins[@plugin_type].detect{ |_,plugin| plugin.handles == handler }
45
+ result = result.last unless result.nil?
46
+ result
47
+ end
48
+
49
+ def self.first!(handler)
50
+ found = first(handler)
51
+ raise UnknownPlugin.new(@plugin_type, handler) if found.nil?
52
+ found
53
+ end
54
+
55
+ def self.register_class(klass)
56
+ plugins.register_plugin_class(@plugin_type, klass)
57
+ end
58
+
59
+ def self.plugins
60
+ @plugin_prefix ||= first_name_to_sym
61
+ @plugin_type ||= last_name_to_sym
62
+ @plugins ||= Pluginator.new(@plugin_prefix)
63
+ end
64
+
65
+ def self.extend_abstract(&block)
66
+ self.const_get(:Abstract).class_eval(&block)
67
+ end
68
+ end
69
+ end
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.email = ["mpapis@gmail.com"]
6
6
  s.authors = ["Michal Papis"]
7
7
  s.name = "pluginator"
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
9
9
  s.files = `git ls-files`.split("\n")
10
10
  s.required_ruby_version = ">= 1.9.2"
11
11
  s.add_development_dependency("simplecov")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluginator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -72,6 +72,7 @@ files:
72
72
  - README.md
73
73
  - Rakefile
74
74
  - lib/pluginator.rb
75
+ - lib/pluginator/plugin_handler.rb
75
76
  - pluginator.gemspec
76
77
  - test/test_paginator.rb
77
78
  homepage: https://github.com/mpapis/pluginator