limited_release 0.1.0 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65a4827c2d190b067f669797e9fae853a39f767689265b8ded1c64d47a065f82
4
- data.tar.gz: 2985d0382e213158697ee214ff07e59de9f491cdf925758855a58145fafa2a90
3
+ metadata.gz: 6f0a45b2fb3719c78df1bed2243234033887bda5d429a69aa2a97572af988d2e
4
+ data.tar.gz: b77cf64ddf56a9da761e577cd1d47e72abbad3a2fcece78fd2313a14f2bfe606
5
5
  SHA512:
6
- metadata.gz: 2cd2bec9a35a160971d5e6b8ba49fa81ee53921636e3e81b41131b9d9773ed80aea878fe055e24800e524ca3b1caeb1bac665d0f61d58e944e8f88d8fe2dad14
7
- data.tar.gz: 5c61637a213e12e8593be76a4711b2594ebb7ef0e9c24fc72dfa4c537117fb7663e0d042a9018295f720b4463328a4b0540f0b3c986a362dea57e3f8beabdc72
6
+ metadata.gz: d1cade85a7e1fe48ea607f99271de3cc1abc6328671cfe120d1115551190684d96df80bde00911e596e4d7ef1d3e1a6ce37cf8440f5107f7103599d31db3501d
7
+ data.tar.gz: c16f659d6bbfc3cb9adc7effc810728f2e2f16c6fdce4aed960af120614e075ea650a4b7114c3bef47ba03f29a63a6668aaa58d3868b9862b29fbfd3ec50299f
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # LimitedRelease
2
- Short description and motivation.
2
+ A simple, safe and rapid prototyping framework for Rails
3
3
 
4
4
  ## Installation
5
5
  Add this line to your application's Gemfile:
@@ -9,31 +9,77 @@ gem 'limited_release'
9
9
  ```
10
10
 
11
11
  And then execute:
12
- ```bash
12
+ ```
13
13
  $ bundle
14
14
  ```
15
15
 
16
16
  Or install it yourself as:
17
- ```bash
17
+ ```
18
18
  $ gem install limited_release
19
19
  ```
20
20
 
21
21
  ## Usage
22
22
 
23
- ### View override
24
- ### Controller override
25
- ### Add path
26
- ### Helper method
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)
27
66
 
28
- ### On Error
67
+ ### Config
29
68
 
30
69
  ```ruby
31
70
  # config/initializers/limited_release.rb
71
+ require 'limited_release'
32
72
 
33
73
  LimitedRelease.configure do |config|
34
- config.on_error = -> (error) do
35
- ::Rails.logger.error(e)
36
- ::Rails.logger.error(e.backtrace.join("\n"))
74
+ config.controller_namespace = :limited_release
75
+
76
+ config.on_error = -> (e) do
77
+ if ::Rails.env.development? || ::Rails.env.test?
78
+ raise e
79
+ else
80
+ ::Rails.logger.error(e)
81
+ ::Rails.logger.error(e.backtrace.join("\n"))
82
+ end
37
83
  end
38
84
  end
39
85
  ```
@@ -53,7 +99,7 @@ create `config/limited_releases/new_feature.rb`
53
99
 
54
100
 
55
101
  ## Contributing
56
- Contribution directions go here.
102
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Jun0kada/limited_release
57
103
 
58
104
  ## License
59
105
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -10,7 +10,7 @@ class LimitedReleaseGenerator < ::Rails::Generators::NamedBase
10
10
  private
11
11
 
12
12
  def file_name
13
- name.gsub('/', '_').underscore
13
+ name.underscore
14
14
  end
15
15
 
16
16
  def class_name
@@ -1,15 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'limited_release/railtie'
4
3
  require 'limited_release/config'
5
4
  require 'limited_release/feature'
6
5
  require 'limited_release/controller'
6
+ require 'limited_release/reloader'
7
+ require 'limited_release/railtie'
7
8
 
8
9
  module LimitedRelease
9
- def self.load_features
10
- @features = Dir[::Rails.root.join('config', 'limited_releases', '*.rb')].map do |path|
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|
11
18
  load path
12
- File.basename(path, '.rb').classify.constantize
13
- end
19
+ name.constantize
20
+ }
21
+ end
22
+
23
+ def self.reload!
24
+ @features = nil
25
+ self.features
26
+
27
+ true
14
28
  end
15
29
  end
@@ -4,6 +4,8 @@ module LimitedRelease
4
4
  include ActiveSupport::Configurable
5
5
 
6
6
  configure do |config|
7
+ config.controller_namespace = :limited_release
8
+
7
9
  config.on_error = -> (e) do
8
10
  if ::Rails.env.development? || ::Rails.env.test?
9
11
  raise e
@@ -4,24 +4,26 @@ module LimitedRelease
4
4
  module Controller
5
5
  extend ActiveSupport::Concern
6
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
7
+ module ClassMethods
8
+ def limited_release(name = nil)
9
+ @_limited_release = name.to_s if name
10
+ @_limited_release
16
11
  end
12
+ end
17
13
 
18
- before_action do
19
- raise InvalidCondition unless @_limited_release.active?(self)
14
+ class InvalidCondition < StandardError; end
20
15
 
21
- self.class.helper @_limited_release.helpers if @_limited_release.helpers
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
22
  end
23
23
  end
24
24
 
25
+ private
26
+
25
27
  def wrap_rescue
26
28
  begin
27
29
  yield
@@ -33,5 +35,21 @@ module LimitedRelease
33
35
  LimitedRelease.config.on_error.call(e)
34
36
  end
35
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
36
54
  end
37
55
  end
@@ -4,6 +4,10 @@ module LimitedRelease
4
4
  module Feature
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ included do
8
+ self.const_set(:Helper, Module.new)
9
+ end
10
+
7
11
  module ClassMethods
8
12
  def active_if(&block)
9
13
  @active_if = block
@@ -19,8 +23,9 @@ module LimitedRelease
19
23
  end
20
24
 
21
25
  def helpers(&block)
22
- @helpers = Module.new(&block) if block
23
- @helpers
26
+ helper = self.const_get(:Helper)
27
+ helper.module_eval(&block) if block
28
+ helper
24
29
  end
25
30
  end
26
31
  end
@@ -3,13 +3,23 @@
3
3
  module LimitedRelease
4
4
  class Railtie < ::Rails::Railtie
5
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)
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
10
  end
11
11
  end
12
12
  end
13
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
14
24
  end
15
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LimitedRelease
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limited_release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jun0kada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-06 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -55,6 +55,7 @@ files:
55
55
  - lib/limited_release/controller.rb
56
56
  - lib/limited_release/feature.rb
57
57
  - lib/limited_release/railtie.rb
58
+ - lib/limited_release/reloader.rb
58
59
  - lib/limited_release/version.rb
59
60
  homepage: https://github.com/Jun0kada/limited_release
60
61
  licenses: