much-rails 0.2.2 → 0.2.3

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: 65f11e22f8ed34e4bd1e940584390a1487e1c69d2c35d6641fb6352fc6179d4f
4
- data.tar.gz: 1824ade309dee8f599074986d52b120d3fcecc79ba302f725500177d353274bd
3
+ metadata.gz: f4834b7655c265c28bb9f46729491681daa8003dd99615c2074f27a010f22e10
4
+ data.tar.gz: 70603cc1bd5717a2edf35ff23cf2fa50ae35dc494431e2fbc476388af8c3d6a1
5
5
  SHA512:
6
- metadata.gz: c0c4c70fbaeec9574a8b66465fbf11668242a521d9693a52f8f7f737558e28ed04a77047c6d634ebed576266fc5f5b4c065dd729a02108cadb07bce05f87bb86
7
- data.tar.gz: 630142f5702e5ad4694a758ded2c8eff9487a19acc0c8611075fd606f0ada5e0d8e486ef7ff0003e28b128d8ce0e8ce80bbe26d4e0cf89dd630b6b780a6114cc
6
+ metadata.gz: d3e614697001a8f9dd5d09a78dcfa3c5e4f6fb458406a7af6c018d7a829687b74c1a98c673ef3e62ec8f7a28f85e4a59f4b3bd7c01ccb95b4ff0d661f569cb61
7
+ data.tar.gz: dcd670e7ca04b1394a92a8a9a7a55b31fd825f5f99bf0282a18d4907e7f614536f30195756ceda6b4320a2fec0d073caf96ab5b74aa57428e4331a1c73381cd7
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuchRails
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  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
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.2
4
+ version: 0.2.3
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-02-01 00:00:00.000000000 Z
12
+ date: 2021-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: much-style-guide
@@ -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
@@ -380,6 +382,7 @@ test_files:
380
382
  - test/support/factory.rb
381
383
  - test/support/fake_action_controller.rb
382
384
  - test/system/.keep
385
+ - test/unit/abstract_class_tests.rb
383
386
  - test/unit/action/base_command_result_tests.rb
384
387
  - test/unit/action/base_result_tests.rb
385
388
  - test/unit/action/base_router_tests.rb