plug 0.1.23 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb469dfe189640aa012dfba0b1784b6b58af48ab0a72f43f86e18aa9557cf342
4
- data.tar.gz: b0ecc6ea23fdbfc103e4b66fbd7ac98c6acbad94e580e2b9372cbc5aa4445607
3
+ metadata.gz: b83146ab631927c0756e4f9e1db5224b731e7ff6f3cb34504cc52f687c0294de
4
+ data.tar.gz: 8cb113cc3497c15054b62198c7fb8ab66583ace08b346481eac56e6d467b36eb
5
5
  SHA512:
6
- metadata.gz: 88ed333f9efd4189debd2e8b892d3da8a33775a1d47919bab8819314b5b0860bb76f0892cb97dee6b93771a5dc543c6c528f3216d42872f5054f0313a5e9840a
7
- data.tar.gz: ca7f17e98fc0902191b0734b61c6cb69a4adff7ca3ba7ba1eee7342b0d049793bc06c8022ebf421f1fab2b813ea847432d62f429f2518f44718a8aa41ae2847f
6
+ metadata.gz: 0a1fc2650f634afa48066f635f1c911248a684074243afdacb27a679191a7ad8d6330c8c479825b7a5cdfd59d70409430d4ea615ed426bf0475d48bfba88a3ea
7
+ data.tar.gz: b7cc1b56cd7d2da25f23012f76ecf773b59366fdb37bb5614cb08b5e1391982e0e38d8abe33efee817c7b6b03a05b5e4d0a0e5ea55b039e1c39f7d781de267cf
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Plug [![Maintainability](https://api.codeclimate.com/v1/badges/6246b1cd8e42603c42f6/maintainability)](https://codeclimate.com/github/DigitalNZ/plug/maintainability) [![Build Status](https://travis-ci.org/DigitalNZ/plug.svg?branch=master)](https://travis-ci.org/DigitalNZ/plug)
1
+ # Plug [![Maintainability](https://api.codeclimate.com/v1/badges/6246b1cd8e42603c42f6/maintainability)](https://codeclimate.com/github/DigitalNZ/plug/maintainability)
2
2
 
3
3
  A Rails engine to turn on/off features (Feature flipper).
4
4
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
@@ -14,7 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
16
  rdoc.rdoc_files.include('lib/**/*.rb')
15
17
  end
16
18
 
17
- APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
19
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
18
20
  load 'rails/tasks/engine.rake'
19
21
 
20
22
  load 'rails/tasks/statistics.rake'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module Api
3
5
  class ApiController < ActionController::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_dependency 'plug/application_controller'
2
4
 
3
5
  module Plug
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class ApplicationController < ActionController::Base
3
5
  protect_from_forgery with: :exception
4
6
 
5
7
  content_security_policy false
6
8
 
7
- if Plug.auth_user.present? && Plug.auth_password.present?
8
- http_basic_authenticate_with name: Plug.auth_user, password: Plug.auth_password
9
- end
9
+ http_basic_authenticate_with name: Plug.auth_user, password: Plug.auth_password if Plug.auth_user.present? && Plug.auth_password.present?
10
10
  end
11
11
  end
@@ -1,12 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_dependency 'plug/application_controller'
2
4
 
3
5
  module Plug
4
6
  class FeaturesController < ApplicationController
5
- if Rails.version.to_i < 5
6
- before_filter :set_feature, only: [:edit, :update, :destroy]
7
- else
8
- before_action :set_feature, only: [:edit, :update, :destroy]
9
- end
7
+ before_action :set_feature, only: %i[edit update destroy]
10
8
 
11
9
  # GET /features
12
10
  def index
@@ -37,7 +35,7 @@ module Plug
37
35
 
38
36
  # PATCH/PUT /features/1
39
37
  def update
40
- if @feature.update_attributes(feature_params)
38
+ if @feature.update(feature_params)
41
39
  redirect_to features_path, notice: 'Feature was successfully updated.'
42
40
  else
43
41
  render :edit
@@ -65,19 +63,15 @@ module Plug
65
63
  end
66
64
 
67
65
  private
68
- # Use callbacks to share common setup or constraints between actions.
69
- def set_feature
70
- @feature = Feature.find(params[:id])
71
- end
72
66
 
73
- # Only allow a trusted parameter "white list" through.
74
- # TODO: Strong params not available for older Rails
75
- def feature_params
76
- if Rails.version.to_i < 5
77
- ActiveSupport::HashWithIndifferentAccess.new(params[:feature])
78
- else
79
- params.require(:feature).permit(:name, :description, :state, :notice)
80
- end
81
- end
67
+ # Use callbacks to share common setup or constraints between actions.
68
+ def set_feature
69
+ @feature = Feature.find(params[:id])
70
+ end
71
+
72
+ # Only allow a trusted parameter "white list" through.
73
+ def feature_params
74
+ params.require(:feature).permit(:name, :description, :state, :notice)
75
+ end
82
76
  end
83
77
  end
@@ -1,12 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_dependency 'plug/application_controller'
2
4
 
3
5
  module Plug
4
6
  class SiteNoticesController < ApplicationController
5
- if Rails.version.to_i < 5
6
- before_filter :set_site_notice, only: [:edit, :update, :destroy]
7
- else
8
- before_action :set_site_notice, only: [:edit, :update, :destroy]
9
- end
7
+ before_action :set_site_notice, only: %i[edit update destroy]
10
8
 
11
9
  # GET /site_notices
12
10
  def index
@@ -37,7 +35,7 @@ module Plug
37
35
 
38
36
  # PATCH/PUT /site_notices/1
39
37
  def update
40
- if @site_notice.update_attributes(site_notice_params)
38
+ if @site_notice.update(site_notice_params)
41
39
  redirect_to site_notices_path, notice: 'Site Notice was successfully updated.'
42
40
  else
43
41
  render :edit
@@ -51,19 +49,15 @@ module Plug
51
49
  end
52
50
 
53
51
  private
54
- # Use callbacks to share common setup or constraints between actions.
55
- def set_site_notice
56
- @site_notice = SiteNotice.find(params[:id])
57
- end
58
52
 
59
- # Only allow a trusted parameter "white list" through.
60
- # TODO: Strong params not available for older Rails
61
- def site_notice_params
62
- if Rails.version.to_i < 5
63
- ActiveSupport::HashWithIndifferentAccess.new(params[:site_notice])
64
- else
65
- params.require(:site_notice).permit(:name, :notice, :state, :theme)
66
- end
67
- end
53
+ # Use callbacks to share common setup or constraints between actions.
54
+ def set_site_notice
55
+ @site_notice = SiteNotice.find(params[:id])
56
+ end
57
+
58
+ # Only allow a trusted parameter "white list" through.
59
+ def site_notice_params
60
+ params.require(:site_notice).permit(:name, :notice, :state, :theme)
61
+ end
68
62
  end
69
63
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module ApplicationHelper
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class ApplicationMailer < ActionMailer::Base
3
5
  default from: 'from@example.com'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class ApplicationRecord < ActiveRecord::Base
3
5
  self.abstract_class = true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Plug
@@ -9,9 +11,9 @@ module Plug
9
11
  include AASM
10
12
 
11
13
  # Validations
12
- validates :name, presence: { message: "#{self.humanized_class_name} name is required" },
13
- uniqueness: { message: "#{self.humanized_class_name} name must be unique", case_sensitive: false }
14
- validates :state, presence: { message: "#{self.humanized_class_name} state is required" }
14
+ validates :name, presence: { message: "#{humanized_class_name} name is required" },
15
+ uniqueness: { message: "#{humanized_class_name} name must be unique", case_sensitive: false }
16
+ validates :state, presence: { message: "#{humanized_class_name} state is required" }
15
17
 
16
18
  # Callbacks
17
19
  before_save { self.slug = name.parameterize }
@@ -32,12 +34,11 @@ module Plug
32
34
  transitions from: :enabled, to: :disabled
33
35
  end
34
36
  end
35
-
36
37
  end
37
38
 
38
39
  module ClassMethods
39
40
  def humanized_class_name
40
- self.name.demodulize.underscore.humanize.capitalize
41
+ name.demodulize.underscore.humanize.capitalize
41
42
  end
42
43
  end
43
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class Feature < ApplicationRecord
3
5
  include AASM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module Resources
3
5
  class SiteNotice < ActiveResource::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class SiteNotice < ApplicationRecord
3
5
  include AASM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
 
3
5
  module Plug
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Plug::Engine.routes.draw do
2
4
  root to: 'features#index'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddThemeToPlugSiteNotice < ActiveRecord::Migration[5.1]
2
4
  def change
3
5
  add_column :plug_site_notices, :theme, :string
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class InstallGenerator < Rails::Generators::Base
3
- source_root File.expand_path('../templates', __FILE__)
5
+ source_root File.expand_path('templates', __dir__)
4
6
 
5
7
  def copy_initializer_file
6
8
  copy_file 'plug.rb', 'config/initializers/plug.rb'
data/lib/plug.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'plug/engine'
2
4
  require 'plug/configuration'
3
5
  require 'plug/constraint'
@@ -12,9 +14,9 @@ module Plug
12
14
  #
13
15
  # @return [Boolean] true - Feature found and enabled | true - Feature not found (We don't want to block) | false - Feature was set to disabled
14
16
  def enabled?(arg)
15
- return get_feature(arg).enabled?
16
- rescue
17
- return true
17
+ get_feature(arg).enabled?
18
+ rescue StandardError
19
+ true
18
20
  end
19
21
 
20
22
  #
@@ -27,21 +29,21 @@ module Plug
27
29
  feature = get_feature(arg)
28
30
 
29
31
  render_notice(feature.notice, &block) unless feature.enabled? || feature.notice.blank?
30
- rescue
31
- return nil
32
+ rescue StandardError
33
+ nil
32
34
  end
33
35
 
34
36
  private
35
37
 
36
- def get_feature(arg)
37
- arg = arg.to_s if arg.is_a? Symbol
38
+ def get_feature(arg)
39
+ arg = arg.to_s if arg.is_a? Symbol
38
40
 
39
- return Plug::Feature.slug_and_name(arg).first
40
- end
41
+ return Plug::Feature.slug_and_name(arg).first
42
+ end
41
43
 
42
- def render_notice(notice, &block)
43
- return notice unless block_given?
44
+ def render_notice(notice, &block)
45
+ return notice unless block_given?
44
46
 
45
- yield(notice)
46
- end
47
+ yield(notice)
48
+ end
47
49
  end
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  module Configuration
3
5
  AUTH_USER = ''
4
6
  AUTH_PASSWORD = ''
5
7
  ALLOW_DELETE = true
6
8
 
7
- VALID_OPTIONS_KEYS = [
8
- :auth_user,
9
- :auth_password,
10
- :allow_delete,
11
- :buttons,
12
- :api_path,
13
- :themes
9
+ VALID_OPTIONS_KEYS = %i[
10
+ auth_user
11
+ auth_password
12
+ allow_delete
13
+ buttons
14
+ api_path
15
+ themes
14
16
  ].freeze
15
17
 
16
- attr_accessor *VALID_OPTIONS_KEYS
18
+ attr_accessor(*VALID_OPTIONS_KEYS)
17
19
 
18
20
  def configure
19
21
  yield self
20
22
  end
21
23
 
22
24
  def options
23
- Hash[ * VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten ]
25
+ Hash[* VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten]
24
26
  end
25
27
  end
26
28
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
4
  class Constraint
3
5
  def initialize(feature)
4
6
  @feature = feature
5
7
  end
6
8
 
7
- def matches?(request)
9
+ def matches?(_request)
8
10
  Plug.enabled?(@feature)
9
- rescue
11
+ rescue StandardError
10
12
  true
11
13
  end
12
14
  end
data/lib/plug/engine.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Require engine dependencies
2
4
  require 'haml-rails'
3
5
  require 'aasm'
@@ -9,6 +11,8 @@ module Plug
9
11
 
10
12
  config.generators do |g|
11
13
  g.test_framework :rspec
14
+ g.fixture_replacement :factory_bot
15
+ g.factory_bot dir: 'spec/factories'
12
16
  end
13
17
  end
14
18
  end
data/lib/plug/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plug
2
- VERSION = '0.1.23'
4
+ VERSION = '0.1.24'
3
5
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # desc "Explaining what the task does"
2
3
  # task :plug do
3
4
  # # Task goes here
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
- - Ben
8
7
  - Boost
8
+ - DNZ
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-16 00:00:00.000000000 Z
12
+ date: 2021-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails
15
+ name: aasm
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: sass-rails
29
+ name: activeresource
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: jquery-rails
43
+ name: haml-rails
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: haml-rails
57
+ name: jquery-rails
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -68,21 +68,21 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: aasm
71
+ name: rails
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: '5.2'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '0'
83
+ version: '5.2'
84
84
  - !ruby/object:Gem::Dependency
85
- name: activeresource
85
+ name: sass-rails
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: sqlite3
99
+ name: capybara
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -110,35 +110,35 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: rspec-rails
113
+ name: factory_bot_rails
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: 3.7.1
118
+ version: '0'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
- version: 3.7.1
125
+ version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rails-controller-testing
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "~>"
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 1.0.2
132
+ version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "~>"
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 1.0.2
139
+ version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
- name: factory_bot_rails
141
+ name: rspec-rails
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - ">="
@@ -152,7 +152,7 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: capybara
155
+ name: selenium-webdriver
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
@@ -166,7 +166,7 @@ dependencies:
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
- name: selenium-webdriver
169
+ name: shoulda-matchers
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ">="
@@ -180,7 +180,7 @@ dependencies:
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  - !ruby/object:Gem::Dependency
183
- name: shoulda-matchers
183
+ name: sqlite3
184
184
  requirement: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
@@ -193,9 +193,8 @@ dependencies:
193
193
  - - ">="
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
- description: Rails engine that can plug/unplug features with notice (WIP)
196
+ description: Rails engine that can plug/unplug features with notice
197
197
  email:
198
- - benedict@boost.co.nz
199
198
  - info@boost.co.nz
200
199
  executables: []
201
200
  extensions: []
@@ -267,7 +266,7 @@ files:
267
266
  - lib/plug/engine.rb
268
267
  - lib/plug/version.rb
269
268
  - lib/tasks/plug_tasks.rake
270
- homepage: https://github.com/hapiben/plug
269
+ homepage: https://github.com/digitalnz/plug
271
270
  licenses:
272
271
  - MIT
273
272
  metadata: {}