much-rails 0.2.0 → 0.2.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: 612174b3a0ff8ace3d3f203a69a69586be9e2d2a7946ab20c8934e07209f8e95
4
- data.tar.gz: d74beef0988406dc358b7bbccd6f5d23dc47e8f2997616b1323af8467c16dfff
3
+ metadata.gz: d51379c3bb8253d5fabab0c4511f4ed283e032d437633d01cfa3cd521037f5e8
4
+ data.tar.gz: f2673e4327993de4bca57e2d3060eec56ed11bd9f5db5933b0634e526cb48e4a
5
5
  SHA512:
6
- metadata.gz: ffe4bf14bdafb94b01c7078b70d0f01eda42e45aedc5dcc935d616e2fc5149c7b1901577af8da172c2df457da8cbeed9dbd30327276dca94ce214f808fac51be
7
- data.tar.gz: 77a0d880a84289e969c99644429458a991c125287205b086953f73c683e1b730842d727e42621561c1b9d7cfb122de2c7f025951b7e7cafc852f50efce3a345a
6
+ metadata.gz: 04f1496ff51bb461ddebebf710fc58793f2c5b3f945e8be5f3823a9eaa2a6f0b6c9a142810351e18f044ff56b49724808dde604d109f5951dffae981e86fbd1f
7
+ data.tar.gz: bc7581eb52e1e501ec755700f7a6380e49fc39dc1961d90161d10b5dd340ce84b7b7c7b2b8220727e7f5ad4ed074eb257713edaa9a59fa09f0bc6281c7adc6c4
data/lib/much-rails.rb CHANGED
@@ -4,6 +4,7 @@ require "active_support"
4
4
  require "active_support/core_ext"
5
5
 
6
6
  require "much-rails/version"
7
+ require "much-rails/abstract_class"
7
8
  require "much-rails/action"
8
9
  require "much-rails/boolean"
9
10
  require "much-rails/call_method"
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "much-rails/mixin"
4
+
5
+ # MuchRails::AbstractClass overrides the `new` class method to prevent a class
6
+ # from being instantiated directly.
7
+ module MuchRails::AbstractClass
8
+ include MuchRails::Mixin
9
+
10
+ after_mixin_included do
11
+ self.abstract_class = self
12
+
13
+ define_singleton_method(:new) do |*args, &block|
14
+ if abstract_class?
15
+ raise(
16
+ NotImplementedError,
17
+ "#{self} is an abstract class and cannot be instantiated.",
18
+ )
19
+ end
20
+
21
+ super(*args, &block)
22
+ end
23
+ end
24
+
25
+ mixin_class_methods do
26
+ def abstract_class
27
+ @abstract_class
28
+ end
29
+
30
+ def abstract_class=(value)
31
+ @abstract_class = value
32
+ end
33
+
34
+ def abstract_class?
35
+ !!(abstract_class == self)
36
+ end
37
+ end
38
+ end
@@ -70,8 +70,8 @@ class MuchRails::Action::BaseRouter
70
70
  # url :users, "/users", "Users::Index"
71
71
  # }
72
72
  # AdminRouter.path_for(:users) # => "/admin/users"
73
- def path_for(name, *args)
74
- @url_set.path_for(name, *args)
73
+ def path_for(name, **kargs)
74
+ @url_set.path_for(name, **kargs)
75
75
  end
76
76
 
77
77
  # Example:
@@ -87,8 +87,8 @@ class MuchRails::Action::BaseRouter
87
87
  # url :users, "/users", "Users::Index"
88
88
  # }
89
89
  # AdminRouter.url_for(:users) # => "http://example.org/admin/users"
90
- def url_for(name, *args)
91
- @url_set.url_for(name, *args)
90
+ def url_for(name, **kargs)
91
+ @url_set.url_for(name, **kargs)
92
92
  end
93
93
 
94
94
  # Example:
@@ -350,12 +350,12 @@ class MuchRails::Action::BaseRouter
350
350
  end
351
351
  end
352
352
 
353
- def path_for(name, *args)
354
- fetch(name).path_for(*args)
353
+ def path_for(name, **kargs)
354
+ fetch(name).path_for(**kargs)
355
355
  end
356
356
 
357
- def url_for(name, *args)
358
- fetch(name).url_for(*args)
357
+ def url_for(name, **kargs)
358
+ fetch(name).url_for(**kargs)
359
359
  end
360
360
  end
361
361
 
@@ -396,11 +396,11 @@ class MuchRails::Action::BaseRouter
396
396
  self.class.url_path(@router, @url_path)
397
397
  end
398
398
 
399
- def path_for(*args)
399
+ def path_for(**kargs)
400
400
  raise NotImplementedError
401
401
  end
402
402
 
403
- def url_for(*args)
403
+ def url_for(**kargs)
404
404
  raise NotImplementedError
405
405
  end
406
406
 
@@ -90,12 +90,18 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
90
90
  alias_method :draw, :apply_to
91
91
 
92
92
  class URL < MuchRails::Action::BaseRouter::BaseURL
93
- def path_for(*args)
94
- MuchRails::RailsRoutes.instance.public_send("#{name}_path", *args)
93
+ def path_for(**kargs)
94
+ MuchRails::RailsRoutes.instance.public_send(
95
+ "#{name}_path",
96
+ **kargs.symbolize_keys,
97
+ )
95
98
  end
96
99
 
97
- def url_for(*args)
98
- MuchRails::RailsRoutes.instance.public_send("#{name}_url", *args)
100
+ def url_for(**kargs)
101
+ MuchRails::RailsRoutes.instance.public_send(
102
+ "#{name}_url",
103
+ **kargs.symbolize_keys,
104
+ )
99
105
  end
100
106
  end
101
107
  end
@@ -12,20 +12,16 @@ end
12
12
  module MuchRails::Assets
13
13
  def self.configure_for_rails(rails)
14
14
  MuchRails::Assets.configure do |config|
15
- # Cache fingerprints in memory for performance gains.
16
- config.fingerprint_cache MuchRails::Assets::MemCache.new
17
-
18
- # Cache compiled content in memory in development/test for performance
19
- # gains since we aren't caching to the file system. Otherwise, don't
20
- # cache in memory as we are caching to the file system and won't benefit
21
- # from the in memory cache.
22
- much_rails_content_cache =
23
- if rails.env.development? || rails.env.test?
24
- MuchRails::Assets::MemCache.new
25
- else
26
- MuchRails::Assets::NoCache.new
27
- end
28
- config.content_cache much_rails_content_cache
15
+ # Cache fingerprints/content in memory in non-development for performance
16
+ # gains. Don't cache in memory in developlemnt so changes are reflected
17
+ # without restarting the server.
18
+ if !rails.env.development?
19
+ config.fingerprint_cache MuchRails::Assets::MemCache.new
20
+ config.content_cache MuchRails::Assets::MemCache.new
21
+ else
22
+ config.fingerprint_cache MuchRails::Assets::NoCache.new
23
+ config.content_cache MuchRails::Assets::NoCache.new
24
+ end
29
25
 
30
26
  # Cache out compiled file content to the public folder in non
31
27
  # development/test environments.
@@ -33,21 +29,40 @@ module MuchRails::Assets
33
29
  config.file_store rails.root.join("public")
34
30
  end
35
31
 
36
- # Look for asset files in the app/assets folder. Support ERB processing
37
- # on all .js and .scss files. Support compilation of .scss files.
38
- config.source rails.root.join("app", "assets") do |s|
32
+ # Look for asset files in the app/assets/css folder. Support ERB
33
+ # on all .scss files. Support compilation of .scss files.
34
+ config.source rails.root.join("app", "assets", "css") do |s|
35
+ s.base_path "css"
36
+
39
37
  # Reject SCSS partials
40
38
  s.filter do |paths|
41
39
  paths.reject{ |p| File.basename(p) =~ /^_.*\.scss$/ }
42
40
  end
43
41
 
44
- s.engine "js", MuchRails::Assets::Erubi::Engine
45
42
  s.engine "scss", MuchRails::Assets::Erubi::Engine
46
43
  s.engine "scss", MuchRails::Assets::Sass::Engine, {
47
44
  syntax: "scss",
48
45
  output_style: "compressed",
49
46
  }
50
47
  end
48
+
49
+ # Look for asset files in the app/assets/img folder.
50
+ config.source rails.root.join("app", "assets", "img") do |s|
51
+ s.base_path "img"
52
+ end
53
+
54
+ # Look for asset files in the app/assets/js folder. Support ERB
55
+ # on all .js files.
56
+ config.source rails.root.join("app", "assets", "js") do |s|
57
+ s.base_path "js"
58
+
59
+ s.engine "js", MuchRails::Assets::Erubi::Engine
60
+ end
61
+
62
+ # Look for asset files in the app/assets/vendor folder
63
+ config.source rails.root.join("app", "assets", "vendor") do |s|
64
+ s.base_path "vendor"
65
+ end
51
66
  end
52
67
  MuchRails::Assets.init
53
68
  end
@@ -27,13 +27,6 @@ class MuchRails::Railtie < Rails::Railtie
27
27
  # This should be `false` in all other envs so proper HTTP response
28
28
  # statuses are returned.
29
29
  config.action.raise_response_exceptions = Rails.env.development?
30
-
31
- config.save_service_validation_error_exception_classes = [
32
- ActiveRecord::RecordInvalid,
33
- ]
34
- config.destroy_service_validation_error_exception_classes = [
35
- MuchRails::Records::DestructionInvalid,
36
- ]
37
30
  end
38
31
  end
39
32
  end
@@ -10,7 +10,7 @@ class MuchRails::ServiceValidationErrors
10
10
  end
11
11
 
12
12
  def add(exception_class, &block)
13
- unless exception_class < Exception
13
+ unless exception_class && exception_class < Exception
14
14
  raise(ArgumentError, "#{exception_class} is not an Exception")
15
15
  end
16
16
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuchRails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.5"
5
5
  end
data/much-rails.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
29
29
 
30
30
  gem.add_dependency("activerecord", ["> 5.0", "< 7.0"])
31
31
  gem.add_dependency("activesupport", ["> 5.0", "< 7.0"])
32
- gem.add_dependency("dassets", ["~> 0.15.1"])
32
+ gem.add_dependency("dassets", ["~> 0.15.2"])
33
33
  gem.add_dependency("dassets-erubi", ["~> 0.1.1"])
34
34
  gem.add_dependency("dassets-sass", ["~> 0.5.1"])
35
35
  gem.add_dependency("much-boolean", ["~> 0.2.1"])
@@ -37,6 +37,6 @@ Gem::Specification.new do |gem|
37
37
  gem.add_dependency("much-mixin", ["~> 0.2.4"])
38
38
  gem.add_dependency("much-not-given", ["~> 0.1.2"])
39
39
  gem.add_dependency("much-result", ["~> 0.1.3"])
40
- gem.add_dependency("much-slug", ["~> 0.1.1"])
40
+ gem.add_dependency("much-slug", ["~> 0.1.2"])
41
41
  gem.add_dependency("oj", ["~> 3.10"])
42
42
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "assert"
4
+ require "much-rails/abstract_class"
5
+
6
+ module MuchRails::AbstractClassTest
7
+ class UnitTests < Assert::Context
8
+ desc "MuchRails::AbstractClass"
9
+ subject{ unit_class }
10
+
11
+ let(:unit_class){ MuchRails::AbstractClass }
12
+
13
+ should "include MuchRails::Mixin" do
14
+ assert_that(subject).includes(MuchRails::Mixin)
15
+ end
16
+ end
17
+
18
+ class ReceiverTests < UnitTests
19
+ desc "receiver"
20
+ subject{ receiver_class }
21
+
22
+ let(:receiver_class) do
23
+ Class.new.tap{ |c| c.include unit_class }
24
+ end
25
+ let(:receiver_subclass) do
26
+ Class.new(receiver_class)
27
+ end
28
+
29
+ should have_accessor :abstract_class
30
+ should have_imeths :new, :abstract_class?
31
+
32
+ should "know if it is an abstract class or not" do
33
+ assert_that(subject.abstract_class?).equals(true)
34
+ assert_that(receiver_subclass.abstract_class?).equals(false)
35
+ end
36
+
37
+ should "prevent calling .new on the receiver" do
38
+ assert_that{ subject.new }.raises(NotImplementedError)
39
+ end
40
+
41
+ should "allow calling .new on subclasses of the receiver" do
42
+ assert_that(receiver_subclass.new).is_a?(subject)
43
+ end
44
+ end
45
+ end
@@ -80,13 +80,13 @@ class MuchRails::Action::BaseRouter
80
80
  end
81
81
 
82
82
  should "build path/URL strings for named URLs" do
83
- path_string = subject.path_for(:url1, "TEST PATH ARGS")
83
+ path_string = subject.path_for(:url1, test: "args")
84
84
  assert_that(path_string).equals("TEST PATH STRING")
85
- assert_that(@url_set_path_for_call.args).equals([:url1, "TEST PATH ARGS"])
85
+ assert_that(@url_set_path_for_call.args).equals([:url1, { test: "args" }])
86
86
 
87
- url_string = subject.url_for(:url1, "TEST URL ARGS")
87
+ url_string = subject.url_for(:url1, test: "args")
88
88
  assert_that(url_string).equals("TEST URL STRING")
89
- assert_that(@url_set_url_for_call.args).equals([:url1, "TEST URL ARGS"])
89
+ assert_that(@url_set_url_for_call.args).equals([:url1, { test: "args" }])
90
90
  end
91
91
 
92
92
  should "define request types" do
@@ -380,13 +380,13 @@ class MuchRails::Action::BaseRouter
380
380
 
381
381
  subject.add(:url1, Factory.url)
382
382
 
383
- path_string = subject.path_for(:url1, "TEST PATH ARGS")
383
+ path_string = subject.path_for(:url1, test: "args")
384
384
  assert_that(path_string).equals("TEST PATH STRING")
385
- assert_that(@url_path_for_call.args).equals(["TEST PATH ARGS"])
385
+ assert_that(@url_path_for_call.args).equals([{ test: "args" }])
386
386
 
387
- url_string = subject.url_for(:url1, "TEST URL ARGS")
387
+ url_string = subject.url_for(:url1, test: "args")
388
388
  assert_that(url_string).equals("TEST URL STRING")
389
- assert_that(@url_url_for_call.args).equals(["TEST URL ARGS"])
389
+ assert_that(@url_url_for_call.args).equals([{ test: "args" }])
390
390
  end
391
391
  end
392
392
 
@@ -450,8 +450,8 @@ class MuchRails::Action::BaseRouter
450
450
  assert_that(subject.path)
451
451
  .equals(base_url_class.url_path(router1, url_path1))
452
452
 
453
- assert_that{ subject.path_for("TEST ARGS") }.raises(NotImplementedError)
454
- assert_that{ subject.url_for("TEST ARGS") }.raises(NotImplementedError)
453
+ assert_that{ subject.path_for(test: "args") }.raises(NotImplementedError)
454
+ assert_that{ subject.url_for(test: "args") }.raises(NotImplementedError)
455
455
  end
456
456
  end
457
457
 
@@ -206,15 +206,15 @@ class MuchRails::Action::Router
206
206
  should have_imeths :path_for, :url_for
207
207
 
208
208
  should "know its attributes" do
209
- path_string = subject.path_for("TEST PATH ARGS")
209
+ path_string = subject.path_for(test: "args")
210
210
  assert_that(path_string).equals("TEST PATH OR URL STRING")
211
211
  assert_that(@rails_routes_method_missing_call.args)
212
- .equals(["#{url_name1}_path".to_sym, "TEST PATH ARGS"])
212
+ .equals(["#{url_name1}_path".to_sym, { test: "args" }])
213
213
 
214
- url_string = subject.url_for("TEST URL ARGS")
214
+ url_string = subject.url_for(test: "args")
215
215
  assert_that(url_string).equals("TEST PATH OR URL STRING")
216
216
  assert_that(@rails_routes_method_missing_call.args)
217
- .equals(["#{url_name1}_url".to_sym, "TEST URL ARGS"])
217
+ .equals(["#{url_name1}_url".to_sym, { test: "args" }])
218
218
  end
219
219
  end
220
220
 
@@ -23,7 +23,7 @@ module MuchRails::Assets
23
23
  setup do
24
24
  subject.reset
25
25
 
26
- in_development_env = Factory.boolean
26
+ in_development_env = true
27
27
  Assert.stub(FakeRails.env, :development?){ in_development_env }
28
28
  Assert.stub(FakeRails.env, :test?){ !in_development_env }
29
29
 
@@ -34,14 +34,11 @@ module MuchRails::Assets
34
34
  subject.configure_for_rails(FakeRails)
35
35
  end
36
36
 
37
- should "configure the fingerprint cache to use a memory cache" do
37
+ should "configure the fingerprint/content cache to use no cache" do
38
38
  assert_that(subject.config.fingerprint_cache)
39
- .is_instance_of(subject::MemCache)
40
- end
41
-
42
- should "configure the content cache to use a memory cache" do
39
+ .is_instance_of(subject::NoCache)
43
40
  assert_that(subject.config.content_cache)
44
- .is_instance_of(subject::MemCache)
41
+ .is_instance_of(subject::NoCache)
45
42
  end
46
43
 
47
44
  should "not configure a file store" do
@@ -49,16 +46,14 @@ module MuchRails::Assets
49
46
  .is_not_equal_to(FakeRails.root.join("public"))
50
47
  end
51
48
 
52
- should "configure the app's app/assets folder as a source" do
49
+ should "configure the app's app/assets/css folder as a source" do
53
50
  source =
54
51
  subject.config.sources.detect do |source|
55
- source.path == FakeRails.root.join("app", "assets").to_s
52
+ source.path == FakeRails.root.join("app", "assets", "css").to_s
56
53
  end
57
54
 
58
55
  assert_that(source).is_not_nil
59
- assert_that(source.engines["js"].size).equals(1)
60
- assert_that(source.engines["js"].first)
61
- .is_instance_of(subject::Erubi::Engine)
56
+ assert_that(source.base_path).equals("css")
62
57
  assert_that(source.engines["scss"].size).equals(2)
63
58
  assert_that(source.engines["scss"].first)
64
59
  .is_instance_of(subject::Erubi::Engine)
@@ -66,6 +61,41 @@ module MuchRails::Assets
66
61
  .is_instance_of(subject::Sass::Engine)
67
62
  end
68
63
 
64
+ should "configure the app's app/assets/img folder as a source" do
65
+ source =
66
+ subject.config.sources.detect do |source|
67
+ source.path == FakeRails.root.join("app", "assets", "img").to_s
68
+ end
69
+
70
+ assert_that(source).is_not_nil
71
+ assert_that(source.base_path).equals("img")
72
+ assert_that(source.engines.empty?).is_true
73
+ end
74
+
75
+ should "configure the app's app/assets/js folder as a source" do
76
+ source =
77
+ subject.config.sources.detect do |source|
78
+ source.path == FakeRails.root.join("app", "assets", "js").to_s
79
+ end
80
+
81
+ assert_that(source).is_not_nil
82
+ assert_that(source.base_path).equals("js")
83
+ assert_that(source.engines["js"].size).equals(1)
84
+ assert_that(source.engines["js"].first)
85
+ .is_instance_of(subject::Erubi::Engine)
86
+ end
87
+
88
+ should "configure the app's app/assets/vendor folder as a source" do
89
+ source =
90
+ subject.config.sources.detect do |source|
91
+ source.path == FakeRails.root.join("app", "assets", "vendor").to_s
92
+ end
93
+
94
+ assert_that(source).is_not_nil
95
+ assert_that(source.base_path).equals("vendor")
96
+ assert_that(source.engines.empty?).is_true
97
+ end
98
+
69
99
  should "initialize itself" do
70
100
  assert_that(@init_call).is_not_nil
71
101
  end
@@ -84,9 +114,11 @@ module MuchRails::Assets
84
114
  subject.configure_for_rails(FakeRails)
85
115
  end
86
116
 
87
- should "configure the content cache to use no cache" do
117
+ should "configure the fingerprint/content cache to use a memory cache" do
118
+ assert_that(subject.config.fingerprint_cache)
119
+ .is_instance_of(subject::MemCache)
88
120
  assert_that(subject.config.content_cache)
89
- .is_instance_of(subject::NoCache)
121
+ .is_instance_of(subject::MemCache)
90
122
  end
91
123
 
92
124
  should "configure a file store for the app's public folder" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: much-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-26 00:00:00.000000000 Z
12
+ date: 2021-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: much-style-guide
@@ -105,14 +105,14 @@ dependencies:
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: 0.15.1
108
+ version: 0.15.2
109
109
  type: :runtime
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: 0.15.1
115
+ version: 0.15.2
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: dassets-erubi
118
118
  requirement: !ruby/object:Gem::Requirement
@@ -217,14 +217,14 @@ dependencies:
217
217
  requirements:
218
218
  - - "~>"
219
219
  - !ruby/object:Gem::Version
220
- version: 0.1.1
220
+ version: 0.1.2
221
221
  type: :runtime
222
222
  prerelease: false
223
223
  version_requirements: !ruby/object:Gem::Requirement
224
224
  requirements:
225
225
  - - "~>"
226
226
  - !ruby/object:Gem::Version
227
- version: 0.1.1
227
+ version: 0.1.2
228
228
  - !ruby/object:Gem::Dependency
229
229
  name: oj
230
230
  requirement: !ruby/object:Gem::Requirement
@@ -251,6 +251,7 @@ files:
251
251
  - LICENSE
252
252
  - README.md
253
253
  - lib/much-rails.rb
254
+ - lib/much-rails/abstract_class.rb
254
255
  - lib/much-rails/action.rb
255
256
  - lib/much-rails/action/base_command_result.rb
256
257
  - lib/much-rails/action/base_result.rb
@@ -306,6 +307,7 @@ files:
306
307
  - test/support/factory.rb
307
308
  - test/support/fake_action_controller.rb
308
309
  - test/system/.keep
310
+ - test/unit/abstract_class_tests.rb
309
311
  - test/unit/action/base_command_result_tests.rb
310
312
  - test/unit/action/base_result_tests.rb
311
313
  - test/unit/action/base_router_tests.rb
@@ -381,6 +383,7 @@ test_files:
381
383
  - test/support/factory.rb
382
384
  - test/support/fake_action_controller.rb
383
385
  - test/system/.keep
386
+ - test/unit/abstract_class_tests.rb
384
387
  - test/unit/action/base_command_result_tests.rb
385
388
  - test/unit/action/base_result_tests.rb
386
389
  - test/unit/action/base_router_tests.rb