chanko 2.3.0 → 3.0.0

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: b169eda16ebf38c4052c3379205412a4262230db439066cf5743717797ffb120
4
- data.tar.gz: 27f319ef0ec3012764d0aff3da7e55a940f3954374727c7fe430a8f7ef859bc8
3
+ metadata.gz: 72b1ce54ea0cf5bbf3d56237723d00c9383213d67534c21531ed568465d95435
4
+ data.tar.gz: 74c763b3087ac11d7ddaa4700995240681ceafd6fcfa1dcf26785d547a20e934
5
5
  SHA512:
6
- metadata.gz: 349b4df82abc58b345591e783dfca68444e41d001334e701d9ae8fe227040c04b37c81b76997dd624a964ccf363c75860bd70de8f7fa7a9d33acd0afe60ec263
7
- data.tar.gz: a9ee4a5cd9a3a5193ee4a3a4e597796fe0c214101bcaea094e2d5c8c60d7527ab0d54cebd9ae9a804c009d9ceaff0de73e06fabc77b452323133b2e935d4dd7d
6
+ metadata.gz: ec921fb9b47ca4f5878f902a01de61a8e5c96d4f671a1a3f991c3d047f2102c24245697a27e05e0af928acaa7b5345bf8cd79465082a3aabffaf2e66f26a7d68
7
+ data.tar.gz: a6f855b9f756b034f9098718bc1ad2c0e112f5ad0a616ac2a9023767ba92228c4f41a6cb0e1a21bf53910140dc2a8bf1480180a6aec0b1cbe8b75dd829be7d47
@@ -10,45 +10,21 @@ jobs:
10
10
  strategy:
11
11
  matrix:
12
12
  rails_version:
13
- - "5.0"
14
- - "5.1"
15
- - "5.2"
16
- - "6.0"
17
13
  - "6.1"
14
+ - "7.0"
15
+ - "7.1"
18
16
  ruby_version:
19
- - "2.7"
20
17
  - "3.1"
21
- autoloader:
22
- - "zeitwerk"
23
- - "classic"
18
+ - "3.2"
19
+ - "3.3"
24
20
  eager_load:
25
21
  - "true"
26
22
  - "false"
27
- exclude:
28
- - rails_version: "5.0"
29
- ruby_version: "3.1"
30
- - rails_version: "5.1"
31
- ruby_version: "3.1"
32
- - rails_version: "5.2"
33
- ruby_version: "3.1"
34
- - rails_version: "5.0"
35
- autoloader: "zeitwerk"
36
- - rails_version: "5.1"
37
- autoloader: "zeitwerk"
38
- - rails_version: "5.2"
39
- autoloader: "zeitwerk"
40
- - rails_version: "5.0"
41
- autoloader: "classic"
42
- - rails_version: "5.1"
43
- autoloader: "classic"
44
- - rails_version: "5.2"
45
- autoloader: "classic"
46
- name: Test on Rails ${{ matrix.rails_version }} & Ruby ${{ matrix.ruby_version }} & Autoloader ${{ matrix.autoloader }} & EagerLoad ${{ matrix.eager_load }}
23
+ name: Test on Rails ${{ matrix.rails_version }} & Ruby ${{ matrix.ruby_version }} & EagerLoad ${{ matrix.eager_load }}
47
24
  env:
48
25
  BUNDLE_GEMFILE: gemfiles/Gemfile_rails_${{ matrix.rails_version }}.rb
49
26
  CI: true
50
27
  EAGER_LOAD: ${{ matrix.eager_load }}
51
- AUTOLOADER : ${{ matrix.autoloader }}
52
28
  steps:
53
29
  - uses: actions/checkout@v3
54
30
  - uses: ruby/setup-ruby@v1
@@ -58,7 +34,7 @@ jobs:
58
34
  - name: rspec
59
35
  run: bundle exec rspec
60
36
  - name: Coveralls
61
- if: matrix.rails_version == '6.1' && matrix.ruby_version == '3.1'
37
+ if: matrix.rails_version == '7.1' && matrix.ruby_version == '3.3'
62
38
  uses: coverallsapp/github-action@master
63
39
  with:
64
40
  github-token: ${{ secrets.GITHUB_TOKEN }}
data/.gitignore CHANGED
@@ -8,7 +8,7 @@ spec/dummy/.sass-cache
8
8
  .bundle
9
9
  .config
10
10
  .yardoc
11
- Gemfile.lock
11
+ gemfiles/Gemfile_rails_*.rb.lock
12
12
  InstalledFiles
13
13
  _yardoc
14
14
  coverage
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ## Unreleased
1
+ ## 3.0.0
2
+ * Support Rails 6,1. 7.0, 7.1.
3
+ * Support Ruby >= 3.0.
4
+ * Drop support for Rails <= 6.0.
5
+ * Drop support for Ruby 2.
6
+ * Drop support for classic loader.
7
+ * The functionality to extend the view_paths has been discontinued.
8
+ * The functionality to extend the models has been discontinued.
2
9
 
3
10
  ## 2.3.0
4
11
  * Support Rails 5.0, 5.1, 5,2, 6.0, 6,1.
data/README.md CHANGED
@@ -10,11 +10,9 @@ With Chanko, you can release many features concurrently and manage target users
10
10
  When any errors are raised from chanko's features,
11
11
  it will be automatically hidden and fallback to its normal behavior.
12
12
 
13
-
14
13
  ## Requirements
15
- * Ruby >= 2.6.0
16
- * Rails >= 5.0.0
17
-
14
+ * Ruby >= 3.0.0
15
+ * Rails >= 6.1.0
18
16
 
19
17
  ## Usage
20
18
  Add to your Gemfile.
@@ -63,11 +61,6 @@ end
63
61
  = invoke(:example_unit, :render_example)
64
62
  ```
65
63
 
66
- ```
67
- -# app/units/example_unit/views/_example.html.slim
68
- = foo
69
- ```
70
-
71
64
  ## Unit
72
65
  You can see [the real example of an unit module file](https://github.com/cookpad/chanko/blob/master/spec/dummy/app/units/entry_deletion/entry_deletion.rb).
73
66
 
@@ -120,39 +113,7 @@ end
120
113
  ```
121
114
 
122
115
  ### render
123
- The view path app/units/example_unit/views is added into view_paths in invoking.
124
- So you can render app/units/example_unit/views/_example.html.slim in invoking.
125
-
126
- ```ruby
127
- scope(:view) do
128
- function(:render_example) do
129
- render "/example", :foo => hello("world")
130
- end
131
- end
132
- ```
133
-
134
- ### models
135
- In models block, you can expand model features by `expand` method.
136
- The expanded methods are available via unit proxy like `User.unit.active`,
137
- `User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.
138
-
139
- ```ruby
140
- models do
141
- expand(:User) do
142
- scope :active, lambda { where(:deleted_at => nil) }
143
-
144
- def active?
145
- deleted_at.nil?
146
- end
147
-
148
- class_methods do
149
- def gc_all_soft_deleted_users
150
- where.not(deleted_at: nil).delete_all
151
- end
152
- end
153
- end
154
- end
155
- ```
116
+ In version 2 and earlier, Chanko extended Rails' search path to include the views path of the unit. This functionality has been discontinued. To maintain the views path under the unit, you will need to manually create a symbolic link in app/views/units to access it.
156
117
 
157
118
  ### shared
158
119
  You can call methods defined by `shared` in invoking.
@@ -174,7 +135,6 @@ helpers do
174
135
  end
175
136
  ```
176
137
 
177
-
178
138
  ## Example
179
139
  https://github.com/cookpad/chanko/tree/master/spec/dummy
180
140
  Chanko provides an example rails application in spec/dummy directory.
data/chanko.gemspec CHANGED
@@ -12,12 +12,11 @@ Gem::Specification.new do |gem|
12
12
  gem.homepage = "https://github.com/cookpad/chanko"
13
13
 
14
14
  gem.files = `git ls-files`.split($/)
15
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
16
  gem.require_paths = ["lib"]
18
- gem.required_ruby_version = '>= 2.6.0'
17
+ gem.required_ruby_version = '>= 3.0.0'
19
18
 
20
- gem.add_dependency "rails", ">= 5.0.0"
19
+ gem.add_dependency "rails", ">= 6.1.0"
21
20
  gem.add_development_dependency "byebug"
22
21
  gem.add_development_dependency "coffee-rails", ">= 3.0.10"
23
22
  gem.add_development_dependency "jquery-rails"
@@ -28,7 +27,7 @@ Gem::Specification.new do |gem|
28
27
  gem.add_development_dependency "simplecov"
29
28
  gem.add_development_dependency 'simplecov-lcov'
30
29
  gem.add_development_dependency "slim"
31
- gem.add_development_dependency "sqlite3"
30
+ gem.add_development_dependency "sqlite3", ">= 1.4"
32
31
  gem.add_development_dependency "thin"
33
32
  gem.add_development_dependency "uglifier"
34
33
  end
@@ -1,8 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 6.1.0'
6
- gem 'net-smtp'
7
- gem 'net-pop'
8
- gem 'net-imap'
6
+ gem 'sqlite3', '~> 1.4'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 7.0.0'
6
+ gem 'sqlite3', '~> 1.4'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 7.1.0'
6
+ gem 'sqlite3', '~> 1.4'
@@ -22,12 +22,10 @@ module Chanko
22
22
 
23
23
  def invoke(context, options = {})
24
24
  with_unit_stack(context) do
25
- with_unit_view_path(context) do
26
- capture_exception(context) do
27
- result = context.instance_eval(&block)
28
- result = decorate(result, context, options[:type]) if context.view? && result.present?
29
- result
30
- end
25
+ capture_exception(context) do
26
+ result = context.instance_eval(&block)
27
+ result = decorate(result, context, options[:type]) if context.view? && result.present?
28
+ result
31
29
  end
32
30
  end
33
31
  end
@@ -59,13 +57,6 @@ module Chanko
59
57
  context.units.pop
60
58
  end
61
59
 
62
- def with_unit_view_path(context)
63
- context.view_paths.unshift unit.resolver if context.respond_to?(:view_paths)
64
- yield
65
- ensure
66
- context.view_paths.paths.shift if context.respond_to?(:view_paths)
67
- end
68
-
69
60
  def capture_exception(context)
70
61
  yield
71
62
  rescue Exception => exception
@@ -7,11 +7,6 @@ module Chanko
7
7
  ActiveSupport.on_load :action_controller do
8
8
  ::ActionController::Base.send(:include, Controller, Invoker, UnitProxyProvider)
9
9
  end
10
- ActiveSupport.on_load :active_record do
11
- ::ActiveRecord::Base.send(:include, UnitProxyProvider)
12
- ::ActiveRecord::Relation.send(:include, UnitProxyProvider)
13
- ::ActiveRecord::Associations::CollectionAssociation.send(:include, UnitProxyProvider)
14
- end
15
10
  end
16
11
 
17
12
 
@@ -21,14 +16,6 @@ module Chanko
21
16
  Chanko::Loader.prepare_eager_load(mode: :zeitwerk)
22
17
  end
23
18
 
24
- initializer("chanko.classic.prepare_eager_load", after: :load_environment_config) do |app|
25
- # Rails5 doens't load environments/*.rb files before :set_autoload_paths.
26
- # In other words, at this stage, config.eager_load cannot be determined to be true or false.
27
- # But classic loader does not freeze paths on :set_autoload_paths.
28
- # After all, It's ok if it is executed after :set_autoload_paths on Rails5 and Rails6(classic).
29
- Chanko::Loader.prepare_eager_load(mode: :classic)
30
- end
31
-
32
19
  initializer("chanko.eager_load_units", before: :eager_load!) do |app|
33
20
  # This is why we need handmade eager-loading
34
21
  # https://github.com/cookpad/chanko/pull/38
@@ -2,8 +2,6 @@ module Chanko
2
2
  module Unit
3
3
  class Extender
4
4
  class Extension < Module
5
- include ActiveRecordClassMethods
6
-
7
5
  def initialize(mod, prefix = nil, &block)
8
6
  @mod = mod
9
7
  @prefix = prefix
@@ -1,4 +1,3 @@
1
- require "chanko/unit/extender/active_record_class_methods"
2
1
  require "chanko/unit/extender/extension"
3
2
 
4
3
  module Chanko
data/lib/chanko/unit.rb CHANGED
@@ -33,10 +33,6 @@ module Chanko
33
33
  Helper.define(unit_name, &block)
34
34
  end
35
35
 
36
- def models(&block)
37
- extender.instance_eval(&block)
38
- end
39
-
40
36
  def active_if(*conditions, &block)
41
37
  @active_if = ActiveIf.new(*conditions, &block)
42
38
  end
@@ -70,10 +66,6 @@ module Chanko
70
66
  UnitProxy.generate_prefix(unit_name)
71
67
  end
72
68
 
73
- def view_path
74
- Rails.root.join("#{Config.units_directory_path}/#{unit_name}/views").to_s
75
- end
76
-
77
69
  def find_function(identifier, label)
78
70
  scope = ScopeFinder.find(identifier)
79
71
  target = scope.ancestors.find {|klass| scopes[klass] }
@@ -93,10 +85,6 @@ module Chanko
93
85
  @shared_methods ||= {}
94
86
  end
95
87
 
96
- def resolver
97
- @resolver ||= Config.resolver.new(view_path)
98
- end
99
-
100
88
  def extender
101
89
  @extender ||= Extender.new(to_prefix)
102
90
  end
@@ -1,3 +1,3 @@
1
1
  module Chanko
2
- VERSION = "2.3.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -14,7 +14,7 @@ module <%= class_name %>
14
14
  # ```
15
15
 
16
16
  # ## raise_error
17
- # `raise_error` is used to force an unit to raise up errors occured in invoking.
17
+ # `raise_error` is used to force an unit to raise up errors occurred in invoking.
18
18
  # You can force to raise up errors also by `Config.raise_error`.
19
19
  #
20
20
  # ```
@@ -34,36 +34,11 @@ module <%= class_name %>
34
34
  # ```
35
35
 
36
36
  # ## render
37
- # In addition, the view path "<%= "#{directory}/views" %>" is added into view_paths.
38
- # So you can render <%= "#{directory}/views/_example.html.erb" %> in invoking.
39
- #
37
+ # If you want to place the views path under the unit, create a symbolic link under app/views/units and refer to it.
40
38
  # ```
41
39
  # scope(:view) do
42
40
  # function(:function_name) do
43
- # render "/example", :foo => "bar"
44
- # end
45
- # end
46
- # ```
47
-
48
- # ## models
49
- # In models block, you can expand model features by `expand` method.
50
- # The expanded methods are available via unit proxy like `User.unit.active`,
51
- # `User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.
52
- #
53
- # ```
54
- # models do
55
- # expand(:User) do
56
- # scope :active, lambda { where(:deleted_at => nil) }
57
- #
58
- # def active?
59
- # deleted_at.nil?
60
- # end
61
- #
62
- # class_methods do
63
- # def gc_all_soft_deleted_users
64
- # where.not(deleted_at: nil).delete_all
65
- # end
66
- # end
41
+ # render "/units/<%= file_name.underscore %>/example", :foo => "bar"
67
42
  # end
68
43
  # end
69
44
  # ```
@@ -6,44 +6,53 @@ module Chanko
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
8
  def create_unit_directory
9
- empty_directory(directory)
9
+ empty_directory(unit_directory)
10
10
  end
11
11
 
12
12
  def create_unit_file
13
- template("unit.rb.erb", "#{directory}/#{file_name}.rb")
13
+ template("unit.rb.erb", "#{unit_directory}/#{file_name}.rb")
14
14
  end
15
15
 
16
- def create_views_directory
17
- create_file("#{directory}/views/.gitkeep", "")
16
+ def create_views_unit_directory
17
+ create_file("#{unit_directory}/views/.gitkeep", "")
18
18
  end
19
19
 
20
20
  ASSETS_TYPES.each do |type|
21
- define_method("create_#{type}_directory") do
22
- create_file("#{directory}/#{type}/.gitkeep", "")
21
+ define_method("create_#{type}_unit_directory") do
22
+ create_file("#{unit_directory}/#{type}/.gitkeep", "")
23
23
  end
24
- end
25
24
 
26
- ASSETS_TYPES.each do |type|
27
- define_method("create_#{type}_symlink") do
25
+ define_method("create_#{type}_unit_symlink") do
28
26
  create_assets_symlink(type)
29
27
  end
30
28
  end
31
29
 
30
+ def create_views_symlink
31
+ from = "app/views/#{units_directory_name}/#{file_name}"
32
+ to = "../../../#{relative_unit_directory}/views"
33
+ create_link(from, to)
34
+ end
35
+
32
36
  private
33
37
 
34
38
  def create_assets_symlink(type)
35
- from = "app/assets/#{type}/#{directory_name}/#{file_name}"
36
- to = "../../../../#{directory}/#{type}"
39
+ from = "app/assets/#{type}/#{units_directory_name}/#{file_name}"
40
+ to = "../../../../#{relative_unit_directory}/#{type}"
37
41
  create_link(from, to)
38
42
  end
39
43
 
40
- def directory
44
+ def relative_unit_directory
45
+ Pathname.new(unit_directory).relative_path_from(Rails.root)
46
+ end
47
+
48
+ def unit_directory
41
49
  "#{Chanko::Config.units_directory_path}/#{file_name}"
42
50
  end
43
51
 
44
- def directory_name
52
+ def units_directory_name
45
53
  Chanko::Config.units_directory_path.split("/").last
46
54
  end
47
55
  end
48
56
  end
49
57
  end
58
+
@@ -6,24 +6,7 @@ module Chanko
6
6
  Loader.load(:example_unit)
7
7
  end
8
8
 
9
- def rails5_action_view_instance
10
- klass = Class.new(ActionView::Base) do
11
- def current_unit
12
- units.last
13
- end
14
-
15
- def units
16
- @units ||= []
17
- end
18
-
19
- def path
20
- view_paths.first.to_s
21
- end
22
- end
23
- klass.new
24
- end
25
-
26
- def rails6_action_view_instance
9
+ def action_view_instance
27
10
  klass = Class.new(ActionView::Base.with_empty_template_cache) do
28
11
  def current_unit
29
12
  units.last
@@ -32,32 +15,12 @@ module Chanko
32
15
  def units
33
16
  @units ||= []
34
17
  end
35
-
36
- def path
37
- view_paths.first.to_s
38
- end
39
18
  end
40
-
41
19
  klass.with_view_paths([], {}, nil)
42
20
  end
43
21
 
44
22
  let(:context) do
45
- case Rails::VERSION::MAJOR
46
- when 5
47
- rails5_action_view_instance
48
- when 6
49
- rails6_action_view_instance
50
- end
51
- end
52
-
53
- let(:context_without_view_paths) do
54
- Class.new do
55
- include Chanko::Invoker
56
-
57
- def units
58
- @units ||= []
59
- end
60
- end.new
23
+ action_view_instance
61
24
  end
62
25
 
63
26
  let(:options) do
@@ -68,19 +31,6 @@ module Chanko
68
31
  it "invokes block with given context and stacked unit" do
69
32
  expect(described_class.new(unit, :label) { current_unit }.invoke(context, options)).to eq(unit)
70
33
  end
71
-
72
- context "when context is a view" do
73
- it "invokes with unit's view path" do
74
- expect(described_class.new(unit, :label) { path }.invoke(context, options)).to eq(unit.view_path)
75
- end
76
- end
77
-
78
- context "when context does not have view_paths" do
79
- it "invokes successfully" do
80
- expect(described_class.new(unit, :label) { "test" }.
81
- invoke(context_without_view_paths, options)).to eq("test")
82
- end
83
- end
84
34
  end
85
35
  end
86
36
  end
@@ -3,24 +3,11 @@ require "chanko/test"
3
3
 
4
4
  module Chanko
5
5
  describe Test do
6
- def rails5_action_view_instance
7
- Class.new(ActionView::Base).new
8
- end
9
-
10
- def rails6_action_view_instance
6
+ let(:view) do
11
7
  klass = Class.new(ActionView::Base.with_empty_template_cache)
12
8
  klass.with_view_paths(nil, {}, nil)
13
9
  end
14
10
 
15
- let(:view) do
16
- case Rails::VERSION::MAJOR
17
- when 5
18
- rails5_action_view_instance
19
- when 6
20
- rails6_action_view_instance
21
- end
22
- end
23
-
24
11
  describe "#enable_unit" do
25
12
  it "forces to enable specified unit" do
26
13
  enable_unit(:inactive_unit)
@@ -188,68 +188,5 @@ module Chanko
188
188
  expect(view.__example_unit_test).to eq("test")
189
189
  end
190
190
  end
191
-
192
- describe ".models" do
193
- before do
194
- stub_const("ExampleModel", model_class)
195
- unit.models do
196
- expand(:ExampleModel) do
197
- scope :active, lambda { where(:deleted_at => nil) }
198
-
199
- has_one :user
200
-
201
- def test
202
- "test"
203
- end
204
-
205
- class_methods do
206
- def test
207
- "test"
208
- end
209
- end
210
- end
211
- end
212
- end
213
-
214
- let(:model_class) do
215
- Class.new do
216
- include UnitProxyProvider
217
-
218
- def self.scope(name, *args)
219
- singleton_class.class_eval do
220
- define_method(name) { "scoped" }
221
- end
222
- end
223
-
224
- def self.has_one(name, *args)
225
- singleton_class.class_eval do
226
- define_method(name) { args }
227
- end
228
- end
229
- end
230
- end
231
-
232
- it "defines instance methods with prefix" do
233
- expect(ExampleModel.new.__example_unit_test).to eq("test")
234
- end
235
-
236
- it "defines class methods with prefix" do
237
- expect(ExampleModel.__example_unit_test).to eq("test")
238
- end
239
-
240
- it "defines scope method with prefix" do
241
- expect(ExampleModel.__example_unit_active).to eq("scoped")
242
- end
243
-
244
- it "defines has_one association method with prefix" do
245
- expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"])
246
- end
247
- end
248
-
249
- describe ".view_path" do
250
- it "returns path for its view directory" do
251
- expect(unit.view_path).to eq("#{Config.units_directory_path}/example_unit/views")
252
- end
253
- end
254
191
  end
255
192
  end
@@ -19,22 +19,6 @@ module EntryDeletion
19
19
  end
20
20
  end
21
21
 
22
- models do
23
- expand(:Entry) do
24
- scope :active, lambda { where(:deleted_at => nil) }
25
-
26
- def soft_delete
27
- update_attributes(:deleted_at => Time.now)
28
- end
29
-
30
- class_methods do
31
- def gc_all_soft_deleted_users
32
- where.not(deleted_at: nil).delete_all
33
- end
34
- end
35
- end
36
- end
37
-
38
22
  helpers do
39
23
  def link_to_deletion(entry)
40
24
  link_to "Delete", entry, :method => :delete
@@ -0,0 +1 @@
1
+ ../../../../fixtures/units/example_unit/views