limited_release 0.1.4

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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d244217c2cb2e60b25b6d5daf2135054190843322b674c9b1726cb758c394dce
4
+ data.tar.gz: 2d3dc35dd2677947e70911db6ffab93ea6dd5b2a7bd399ac4178d9ae86b9f4cf
5
+ SHA512:
6
+ metadata.gz: fde5ff57e95d70f7ab666708e3e92dd2e0c59539ffdfc7d8dce0f25e1dcc36f150d40dd8f0e9c05751bf1643cfcfe46d1d784b9a59664ae1621de89e40ec2b9d
7
+ data.tar.gz: 5bd8aff14f28008c5c9c6b49a0a2c08892237336a80c823d5130d1c37ea804b2029ad748034312e80ed26a1b960f20a890fef34c5f8f9908a5700b18f90268d9
@@ -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.
@@ -0,0 +1,104 @@
1
+ # LimitedRelease
2
+ A simple, safe and rapid prototyping framework for Rails
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
+ ```
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```
18
+ $ gem install limited_release
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # config/limited_releases/top_page_design.rb
25
+
26
+ class TopPageDesign
27
+ include LimitedRelease::Feature
28
+
29
+ active_if do
30
+ params[:new_design].present?
31
+ end
32
+
33
+ routes do
34
+ get '/', to: 'top_page_designs#show', as: 'top_page_design'
35
+ end
36
+
37
+ helpers do
38
+ def title
39
+ 'Welcome to New Design!'
40
+ end
41
+ end
42
+ end
43
+ ```
44
+
45
+ ```ruby
46
+ # app/controllers/limited_release/top_page_designs_controller.rb
47
+
48
+ class LimitedRelease::TopPageDesignsController < TopController
49
+ ## you can specify limited_release class name
50
+ # limited_release 'TopPageDesign'
51
+
52
+ def show
53
+ super
54
+ end
55
+ end
56
+ ```
57
+
58
+ ```html
59
+ <!-- app/views/limited_release/top_page_designs/show.html.erb -->
60
+
61
+ <h1><%= title %></h1>
62
+ ...
63
+ ```
64
+
65
+ [Other examples](https://github.com/Jun0kada/limited_release/tree/master/test/dummy)
66
+
67
+ ### Config
68
+
69
+ ```ruby
70
+ # config/initializers/limited_release.rb
71
+
72
+ LimitedRelease.configure do |config|
73
+ config.controller_namespace = :limited_release
74
+
75
+ config.on_error = -> (e) do
76
+ if ::Rails.env.development? || ::Rails.env.test?
77
+ raise e
78
+ else
79
+ ::Rails.logger.error(e)
80
+ ::Rails.logger.error(e.backtrace.join("\n"))
81
+ end
82
+ end
83
+ end
84
+ ```
85
+
86
+ ## Generator
87
+
88
+ ```
89
+ $ rails generate limited_release FEATURE_NAME
90
+ ```
91
+
92
+ ### Example
93
+ ```
94
+ $ rails generate limited_release new_feature
95
+ ```
96
+
97
+ create `config/limited_releases/new_feature.rb`
98
+
99
+
100
+ ## Contributing
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Jun0kada/limited_release
102
+
103
+ ## License
104
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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.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,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'limited_release/config'
4
+ require 'limited_release/feature'
5
+ require 'limited_release/controller'
6
+ require 'limited_release/reloader'
7
+ require 'limited_release/railtie'
8
+
9
+ module LimitedRelease
10
+ def self.features
11
+ @features ||= Dir[::Rails.root.join('config', 'limited_releases', '**', '*.rb')].sort_by { |path| path.split('/').length }.map { |path|
12
+ name = path.gsub(/(.+limited_releases\/|\.rb\z)/, '').classify
13
+
14
+ Object.send(:remove_const, name.split('::').first) if Object.const_defined?(name.split('::').first)
15
+
16
+ [path, name]
17
+ }.map { |path, name|
18
+ load path
19
+ name.constantize
20
+ }
21
+ end
22
+
23
+ def self.reload!
24
+ @features = nil
25
+ self.features
26
+
27
+ true
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LimitedRelease
4
+ include ActiveSupport::Configurable
5
+
6
+ configure do |config|
7
+ config.controller_namespace = :limited_release
8
+
9
+ config.on_error = -> (e) do
10
+ if ::Rails.env.development? || ::Rails.env.test?
11
+ raise e
12
+ else
13
+ ::Rails.logger.error(e)
14
+ ::Rails.logger.error(e.backtrace.join("\n"))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LimitedRelease
4
+ module Controller
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def limited_release(name = nil)
9
+ @_limited_release = name.to_s if name
10
+ @_limited_release
11
+ end
12
+ end
13
+
14
+ class InvalidCondition < StandardError; end
15
+
16
+ included do
17
+ with_options if: :limited_release_controller? do
18
+ around_action :wrap_rescue
19
+ before_action :set_limited_release
20
+ before_action :check_limited_release_condition
21
+ before_action :append_limited_release_helper
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def wrap_rescue
28
+ begin
29
+ yield
30
+ rescue LimitedRelease::Controller::InvalidCondition
31
+ headers['X-Cascade'] = 'pass'
32
+ rescue => e
33
+ headers['X-Cascade'] = 'pass'
34
+
35
+ LimitedRelease.config.on_error.call(e)
36
+ end
37
+ end
38
+
39
+ def set_limited_release
40
+ @_limited_release = self.class.limited_release&.constantize || self.class.name.split('::')[1].sub(/Controller\z/, '').classify.constantize
41
+ end
42
+
43
+ def check_limited_release_condition
44
+ raise InvalidCondition unless @_limited_release.active?(self)
45
+ end
46
+
47
+ def append_limited_release_helper
48
+ self.class.helper @_limited_release.helpers
49
+ end
50
+
51
+ def limited_release_controller?
52
+ self.class.name.split('::').first == LimitedRelease.config.controller_namespace.to_s.classify
53
+ end
54
+ end
55
+ 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,25 @@
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 ::LimitedRelease.config.controller_namespace, 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
+ ActiveSupport.on_load :action_controller do
16
+ ActionController::Base.include ::LimitedRelease::Controller
17
+ end
18
+
19
+ if ::Rails.env.development?
20
+ initializer 'limited_release.insert_reloader' do |app|
21
+ app.config.middleware.use ::LimitedRelease::Reloader
22
+ end
23
+ end
24
+ end
25
+ 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.reloader.reload!
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LimitedRelease
4
+ VERSION = '0.1.4'
5
+ 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.4
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: []