limited_release 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
+ SHA256:
3
+ metadata.gz: 65a4827c2d190b067f669797e9fae853a39f767689265b8ded1c64d47a065f82
4
+ data.tar.gz: 2985d0382e213158697ee214ff07e59de9f491cdf925758855a58145fafa2a90
5
+ SHA512:
6
+ metadata.gz: 2cd2bec9a35a160971d5e6b8ba49fa81ee53921636e3e81b41131b9d9773ed80aea878fe055e24800e524ca3b1caeb1bac665d0f61d58e944e8f88d8fe2dad14
7
+ data.tar.gz: 5c61637a213e12e8593be76a4711b2594ebb7ef0e9c24fc72dfa4c537117fb7663e0d042a9018295f720b4463328a4b0540f0b3c986a362dea57e3f8beabdc72
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,15 @@
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
+
8
+ module LimitedRelease
9
+ def self.load_features
10
+ @features = Dir[::Rails.root.join('config', 'limited_releases', '*.rb')].map do |path|
11
+ load path
12
+ File.basename(path, '.rb').classify.constantize
13
+ end
14
+ end
15
+ 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,37 @@
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
+ LimitedRelease.load_features if ::Rails.env.development?
14
+
15
+ @_limited_release = self.class.name.split('::')[1].sub(/Controller\z/, '').constantize
16
+ end
17
+
18
+ before_action do
19
+ raise InvalidCondition unless @_limited_release.active?(self)
20
+
21
+ self.class.helper @_limited_release.helpers if @_limited_release.helpers
22
+ end
23
+ end
24
+
25
+ def wrap_rescue
26
+ begin
27
+ yield
28
+ rescue LimitedRelease::Controller::InvalidCondition
29
+ headers['X-Cascade'] = 'pass'
30
+ rescue => e
31
+ headers['X-Cascade'] = 'pass'
32
+
33
+ LimitedRelease.config.on_error.call(e)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LimitedRelease
4
+ module Feature
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def active_if(&block)
9
+ @active_if = block
10
+ end
11
+
12
+ def active?(context)
13
+ !!context.instance_eval(&@active_if)
14
+ end
15
+
16
+ def routes(&block)
17
+ @routes = block if block
18
+ @routes
19
+ end
20
+
21
+ def helpers(&block)
22
+ @helpers = Module.new(&block) if block
23
+ @helpers
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
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
+ LimitedRelease.load_features.each do |feature|
8
+ namespace :limited_release, path: nil do
9
+ self.instance_eval(&feature.routes)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LimitedRelease
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: limited_release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jun0kada
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-06 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/version.rb
59
+ homepage: https://github.com/Jun0kada/limited_release
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A simple, safe and rapid prototyping framework
82
+ test_files: []