syosset-plugins-base 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0312b92486f63db2b3ab8010cae06c3b0389830
4
+ data.tar.gz: 27f57d20807fc5aa6cbbcdf8d38ce07df9a9cc44
5
+ SHA512:
6
+ metadata.gz: e408a991b30a7877a4dbf8d8b931f86d705d28875e716524187f39548af423f7be2d8a0d22003af517db1f3444ed8a18b8fa58e64bfc768bef605660cc13b506
7
+ data.tar.gz: 2928fa3b5e8769cce50a296ede06ce0426fd290088b7ab7f30d22727c64da4c4cde1f673654b19d7f832b494932e507322d5b17c20c50f6f388427678c2db047
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in syosset-plugins-base.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Syosset::Plugins::Base
2
+
3
+ This is the base code for a plugin system designed to autoload "plugins" (Rails Engines) in `vendor/plugins` which follow a certain convention.
4
+
5
+ TODO: Document this convention
6
+ See https://github.com/Syosset/syosset to see this plugin framework in use.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'syosset-plugins-base'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install syosset-plugins-base
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/syosset-plugins-base.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "syosset/plugins/base"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ module Concerns
2
+ # Models which can have plugins should inclue this concern
3
+ module Plugable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ field :enabled_plugins, type: Array, default: []
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require "syosset/plugins/base/version"
2
+ require "active_support"
3
+ require "app/models/concerns/plugable"
4
+
5
+ module Syosset
6
+ module Plugins
7
+ module Base
8
+ extend ::ActiveSupport::Autoload
9
+
10
+ autoload :Plugin
11
+ autoload :Registry
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ module Syosset
2
+ module Plugins
3
+ module Base
4
+ # The plugin's main class (Rails engine entrypoint) should include this module
5
+ # Note: Inclusion is not enough; you must register the plugin with the registry
6
+ module Plugin
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ cattr_accessor :plugin_name, :plugin_description
11
+ end
12
+
13
+ module ClassMethods
14
+ # Sets the plugin name
15
+ def name(name)
16
+ self.plugin_name = name
17
+ end
18
+
19
+ # Sets the plugin's usage
20
+ def description(description)
21
+ self.plugin_description = description
22
+ end
23
+
24
+ # Includes a module into a concern which all plugables use
25
+ # This is useful if you want to define relations into models which can have plugins
26
+ # Example: A photo gallery plugin might need to define a relation like department has_many :images
27
+ def plugable_include(mod)
28
+ Concerns::Plugable.include(mod)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ module Syosset
2
+ module Plugins
3
+ module Base
4
+ class Railtie < Rails::Railtie
5
+ config.after_initialize do
6
+ logger = Logger.new(STDOUT)
7
+
8
+ logger.info "Loading plugins..."
9
+ Dir[Rails.root.to_s + '/vendor/plugins/**/*.rb'].each do |file|
10
+ path = file.split("/")
11
+ if path[-1] == "engine.rb"
12
+ logger.info "Loading #{file}"
13
+ require file
14
+
15
+ plugin = "Syosset::Plugins::#{path[-2].camelize}::Engine".constantize
16
+ Registry.register plugin
17
+ logger.info "Added #{plugin} to Registry"
18
+
19
+ logger.info "Attempting to mount on /plugins/#{plugin.plugin_name.parameterize}"
20
+ Rails.application.routes.draw do
21
+ mount plugin => "/plugins/#{plugin.plugin_name.parameterize}"
22
+ end
23
+
24
+ logger.info "Loaded #{plugin.plugin_name} { #{plugin.plugin_description} }"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ module Syosset
2
+ module Plugins
3
+ module Base
4
+ module Registry
5
+ mattr_accessor :plugins, :callbacks
6
+ @@plugins = []
7
+ @@callbacks = {on_register: [], on_enable: [], on_disable: []}
8
+
9
+ def self.register(klass, options = {})
10
+ @@plugins << [klass, options]
11
+ @@callbacks[:on_register].each {|x| x.call }
12
+ end
13
+
14
+ def self.enabled? plugin_class, plugable
15
+ raise "Plugin must include Syosset::Plugins::Base::Plugin" unless plugin_class.include? Syosset::Plugins::Base::Plugin
16
+ raise "Plugable must include Concerns::Plugable" unless plugable.class.include? Concerns::Plugable
17
+ plugable.enabled_plugins.include? plugin_class.to_s
18
+ end
19
+
20
+ def self.enable plugin_class, plugable
21
+ raise "Plugin must include Syosset::Plugins::Base::Plugin" unless plugin_class.include? Syosset::Plugins::Base::Plugin
22
+ raise "Plugable must include Concerns::Plugable" unless plugable.class.include? Concerns::Plugable
23
+ plugable.enabled_plugins << plugin_class.to_s
24
+ @@callbacks[:on_enable].each {|x| x.call(plugin_class) } if plugable.save
25
+ end
26
+
27
+ def self.disable plugin_class, plugable
28
+ raise "Plugin must include Syosset::Plugins::Base::Plugin" unless plugin_class.include? Syosset::Plugins::Base::Plugin
29
+ raise "Plugable must include Concerns::Plugable" unless plugable.class.include? Concerns::Plugable
30
+ plugable.enabled_plugins.delete(plugin_class.to_s)
31
+ @@callbacks[:on_disable].each {|x| x.call(plugin_class) } if plugable.save
32
+ end
33
+
34
+ def self.on_register(&callback)
35
+ @@callbacks[:on_register] << callback
36
+ end
37
+
38
+ def self.on_enable(&callback)
39
+ @@callbacks[:on_enable] << callback
40
+ end
41
+
42
+ def self.on_disable(&callback)
43
+ @@callbacks[:on_disable] << callback
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ module Syosset
2
+ module Plugins
3
+ module Base
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "syosset/plugins/base/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "syosset-plugins-base"
8
+ spec.version = Syosset::Plugins::Base::VERSION
9
+ spec.authors = ["Neil Johari"]
10
+ spec.email = ["neil@johari.tech"]
11
+
12
+ spec.summary = %q{Base of the plugin management system used at syosseths.com}
13
+ spec.description = %{Provides base classes for plugins, and includes railtie to autoload plugins}
14
+ spec.homepage = "https://github.com/Syosset/syosset-plugins-base"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "activesupport", "~> 5.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "mongoid", "~> 6.1.0"
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syosset-plugins-base
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Neil Johari
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 6.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 6.1.0
83
+ description: Provides base classes for plugins, and includes railtie to autoload plugins
84
+ email:
85
+ - neil@johari.tech
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/app/models/concerns/plugable.rb
99
+ - lib/syosset/plugins/base.rb
100
+ - lib/syosset/plugins/base/plugin.rb
101
+ - lib/syosset/plugins/base/railtie.rb
102
+ - lib/syosset/plugins/base/registry.rb
103
+ - lib/syosset/plugins/base/version.rb
104
+ - syosset-plugins-base.gemspec
105
+ homepage: https://github.com/Syosset/syosset-plugins-base
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.12
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Base of the plugin management system used at syosseths.com
128
+ test_files: []