limited_release 0.1.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +59 -0
- data/Rakefile +27 -0
- data/lib/generators/limited_release_generator.rb +19 -0
- data/lib/generators/templates/config.rb +18 -0
- data/lib/limited_release.rb +27 -0
- data/lib/limited_release/config.rb +16 -0
- data/lib/limited_release/controller.rb +35 -0
- data/lib/limited_release/feature.rb +32 -0
- data/lib/limited_release/railtie.rb +21 -0
- data/lib/limited_release/reloader.rb +20 -0
- data/lib/limited_release/version.rb +5 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e1793f17daec59d15f6e169206d729c13817ba005efb6ea2d2a3db1b40e1ca63
|
4
|
+
data.tar.gz: c061742f097b893a9e15b58210531a04bc29186e243d785e95949a80a2950db5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70602c0598144dee50ae7d2562dfe48497fcaf2705d97670bd0d4c3dfe4eb3329ec236b2b15a684a2a33450f6470b59487897f1a91b504c3fbe1e36ba9943d70
|
7
|
+
data.tar.gz: 35facc7d76f151040a5b20c57d08f529863fc200f38faa218172a9efe3f7510a21dfe3625efc2f027022a74337bbd3a776e520c6db489fece3b3a451d99e6974
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Jun0kada
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# LimitedRelease
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'limited_release'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
```bash
|
18
|
+
$ gem install limited_release
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### View override
|
24
|
+
### Controller override
|
25
|
+
### Add path
|
26
|
+
### Helper method
|
27
|
+
|
28
|
+
### On Error
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# config/initializers/limited_release.rb
|
32
|
+
|
33
|
+
LimitedRelease.configure do |config|
|
34
|
+
config.on_error = -> (error) do
|
35
|
+
::Rails.logger.error(e)
|
36
|
+
::Rails.logger.error(e.backtrace.join("\n"))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Generator
|
42
|
+
|
43
|
+
```
|
44
|
+
$ rails generate limited_release FEATURE_NAME
|
45
|
+
```
|
46
|
+
|
47
|
+
### Example
|
48
|
+
```
|
49
|
+
$ rails generate limited_release new_feature
|
50
|
+
```
|
51
|
+
|
52
|
+
create `config/limited_releases/new_feature.rb`
|
53
|
+
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
Contribution directions go here.
|
57
|
+
|
58
|
+
## License
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'LimitedRelease'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class LimitedReleaseGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
5
|
+
|
6
|
+
def create_config_file
|
7
|
+
template 'config.rb', "config/limited_releases/#{file_name}.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def file_name
|
13
|
+
name.gsub('/', '_').underscore
|
14
|
+
end
|
15
|
+
|
16
|
+
def class_name
|
17
|
+
file_name.classify
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class <%= class_name %>
|
4
|
+
include LimitedRelease::Feature
|
5
|
+
|
6
|
+
active_if do
|
7
|
+
# current_user.admin?
|
8
|
+
end
|
9
|
+
|
10
|
+
routes do
|
11
|
+
# get '/', to: '<%= file_name.pluralize %>#show', as: '<%= file_name %>'
|
12
|
+
end
|
13
|
+
|
14
|
+
helpers do
|
15
|
+
# def my_helper_method
|
16
|
+
# end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'limited_release/railtie'
|
4
|
+
require 'limited_release/config'
|
5
|
+
require 'limited_release/feature'
|
6
|
+
require 'limited_release/controller'
|
7
|
+
require 'limited_release/reloader'
|
8
|
+
|
9
|
+
module LimitedRelease
|
10
|
+
def self.features
|
11
|
+
@features ||= Dir[::Rails.root.join('config', 'limited_releases', '*.rb')].map do |path|
|
12
|
+
name = File.basename(path, '.rb').classify
|
13
|
+
|
14
|
+
Object.send(:remove_const, name) if Object.const_defined?(name)
|
15
|
+
|
16
|
+
load path
|
17
|
+
name.constantize
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.reload!
|
22
|
+
@features = nil
|
23
|
+
self.features
|
24
|
+
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LimitedRelease
|
4
|
+
include ActiveSupport::Configurable
|
5
|
+
|
6
|
+
configure do |config|
|
7
|
+
config.on_error = -> (e) do
|
8
|
+
if ::Rails.env.development? || ::Rails.env.test?
|
9
|
+
raise e
|
10
|
+
else
|
11
|
+
::Rails.logger.error(e)
|
12
|
+
::Rails.logger.error(e.backtrace.join("\n"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LimitedRelease
|
4
|
+
module Controller
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class InvalidCondition < StandardError; end
|
8
|
+
|
9
|
+
included do
|
10
|
+
prepend_around_action :wrap_rescue
|
11
|
+
|
12
|
+
prepend_before_action do
|
13
|
+
@_limited_release = self.class.name.split('::')[1].sub(/Controller\z/, '').constantize
|
14
|
+
end
|
15
|
+
|
16
|
+
before_action do
|
17
|
+
raise InvalidCondition unless @_limited_release.active?(self)
|
18
|
+
|
19
|
+
self.class.helper @_limited_release.helpers
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def wrap_rescue
|
24
|
+
begin
|
25
|
+
yield
|
26
|
+
rescue LimitedRelease::Controller::InvalidCondition
|
27
|
+
headers['X-Cascade'] = 'pass'
|
28
|
+
rescue => e
|
29
|
+
headers['X-Cascade'] = 'pass'
|
30
|
+
|
31
|
+
LimitedRelease.config.on_error.call(e)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LimitedRelease
|
4
|
+
module Feature
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
self.const_set(:Helper, Module.new)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def active_if(&block)
|
13
|
+
@active_if = block
|
14
|
+
end
|
15
|
+
|
16
|
+
def active?(context)
|
17
|
+
!!context.instance_eval(&@active_if)
|
18
|
+
end
|
19
|
+
|
20
|
+
def routes(&block)
|
21
|
+
@routes = block if block
|
22
|
+
@routes
|
23
|
+
end
|
24
|
+
|
25
|
+
def helpers(&block)
|
26
|
+
helper = self.const_get(:Helper)
|
27
|
+
helper.module_eval(&block) if block
|
28
|
+
helper
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LimitedRelease
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
ActiveSupport.on_load :after_initialize do
|
6
|
+
::Rails.application.routes.prepend do
|
7
|
+
namespace :limited_release, path: nil do
|
8
|
+
::LimitedRelease.features.each do |feature|
|
9
|
+
self.instance_eval(&feature.routes) if feature.routes
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if ::Rails.env.development?
|
16
|
+
initializer 'limited_release.insert_reloader' do |app|
|
17
|
+
app.config.middleware.use ::LimitedRelease::Reloader
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LimitedRelease
|
4
|
+
class Reloader
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
|
8
|
+
@reloader = ActiveSupport::FileUpdateChecker.new(Dir[::Rails.root.join('config', 'limited_releases', '**', '*.rb')]) do
|
9
|
+
::LimitedRelease.reload!
|
10
|
+
::Rails.application.reload_routes!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
@reloader.execute_if_updated
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: limited_release
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun0kada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A simple, safe and rapid prototyping framework
|
42
|
+
email:
|
43
|
+
- jun.0kada.dev@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/generators/limited_release_generator.rb
|
52
|
+
- lib/generators/templates/config.rb
|
53
|
+
- lib/limited_release.rb
|
54
|
+
- lib/limited_release/config.rb
|
55
|
+
- lib/limited_release/controller.rb
|
56
|
+
- lib/limited_release/feature.rb
|
57
|
+
- lib/limited_release/railtie.rb
|
58
|
+
- lib/limited_release/reloader.rb
|
59
|
+
- lib/limited_release/version.rb
|
60
|
+
homepage: https://github.com/Jun0kada/limited_release
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.0.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: A simple, safe and rapid prototyping framework
|
83
|
+
test_files: []
|