spaced 0.3.1 → 0.5.0

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: 496fc25b4cc4a7b4d8332661ace97b36a26ee5cb9592bfeb06e1743483c47c3b
4
- data.tar.gz: 96b4ddf6c1c5e89ead4f894ced1f71c2b2a671c7838766572f94f85462bedf82
3
+ metadata.gz: d76a45f4639e8fef5d2efb99dd8aec566912cb61930aaa61d52b16bfd6e0c6f2
4
+ data.tar.gz: 8b1d370e2b948d2bd9fcfdc03736dcadcef9d95eeef2d4e017f3cea53d9e723a
5
5
  SHA512:
6
- metadata.gz: 4751df5962de7c88361b534dff26007baeed5a91bd8a4f796aa75d6ff31f5a48c10c8b9dc8d53528af00f9089cc8bc8865b3c97b209227cb5c9dab96f84f4c33
7
- data.tar.gz: eb9fd26c2e44f605bf9c9f733b22263ff86a0f5fd4d8003fe1457544b3a4b2a7f08ac13b3132a7447230c3017aab6c1c4bce5d407ee4bc56d53a6fc4dd86f8ef
6
+ metadata.gz: 15281d8d117f2bac3f6fff7a676de0b09fbb5817930356b71ca16d294c2facacbae6e7e18c3f07566ab98a349ae80a139187b2eeb1eb250f81dd5652ebe166a1
7
+ data.tar.gz: eadbae3132d5130a5290852dc14247f1ca180863a0f5d6b846d0ec008a0c8f062fd3f619e748e61dc48b98cee0dafa413d5289f5d22b2c08c5ac0b225c95b690
data/.rubocop.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 3.1.0
3
- SuggestExtensions: false
4
3
  NewCops: enable
5
4
 
6
5
  Style/StringLiterals:
@@ -15,5 +14,8 @@ Layout/LineLength:
15
14
  Max: 120
16
15
  Metrics/MethodLength:
17
16
  Max: 20
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - test/**/*
18
20
  Style/Documentation:
19
- Enabled: false
21
+ Enabled: false
data/Gemfile CHANGED
@@ -5,8 +5,8 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in spaced.gemspec
6
6
  gemspec
7
7
 
8
- gem "minitest", "~> 5.0"
9
- gem "minitest-focus"
10
8
  gem "rake", "~> 13.0"
11
9
  gem "rubocop", "~> 1.21"
12
10
  gem "rubocop-minitest"
11
+ gem "rubocop-rake"
12
+ gem "sus", group: :test
data/Gemfile.lock CHANGED
@@ -1,48 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spaced (0.3.0)
4
+ spaced (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- minitest (5.15.0)
11
- minitest-focus (1.3.1)
12
- minitest (>= 4, < 6)
13
- parallel (1.22.1)
14
- parser (3.1.2.0)
10
+ json (2.7.2)
11
+ language_server-protocol (3.17.0.3)
12
+ parallel (1.24.0)
13
+ parser (3.3.0.5)
15
14
  ast (~> 2.4.1)
15
+ racc
16
+ racc (1.7.3)
16
17
  rainbow (3.1.1)
17
- rake (13.0.6)
18
- regexp_parser (2.4.0)
19
- rexml (3.2.5)
20
- rubocop (1.30.0)
18
+ rake (13.2.1)
19
+ regexp_parser (2.9.0)
20
+ rexml (3.2.6)
21
+ rubocop (1.63.2)
22
+ json (~> 2.3)
23
+ language_server-protocol (>= 3.17.0)
21
24
  parallel (~> 1.10)
22
- parser (>= 3.1.0.0)
25
+ parser (>= 3.3.0.2)
23
26
  rainbow (>= 2.2.2, < 4.0)
24
27
  regexp_parser (>= 1.8, < 3.0)
25
28
  rexml (>= 3.2.5, < 4.0)
26
- rubocop-ast (>= 1.18.0, < 2.0)
29
+ rubocop-ast (>= 1.31.1, < 2.0)
27
30
  ruby-progressbar (~> 1.7)
28
- unicode-display_width (>= 1.4.0, < 3.0)
29
- rubocop-ast (1.18.0)
30
- parser (>= 3.1.1.0)
31
- rubocop-minitest (0.19.1)
32
- rubocop (>= 0.90, < 2.0)
33
- ruby-progressbar (1.11.0)
34
- unicode-display_width (2.1.0)
31
+ unicode-display_width (>= 2.4.0, < 3.0)
32
+ rubocop-ast (1.31.2)
33
+ parser (>= 3.3.0.4)
34
+ rubocop-minitest (0.35.0)
35
+ rubocop (>= 1.61, < 2.0)
36
+ rubocop-ast (>= 1.31.1, < 2.0)
37
+ rubocop-rake (0.6.0)
38
+ rubocop (~> 1.0)
39
+ ruby-progressbar (1.13.0)
40
+ sus (0.24.6)
41
+ unicode-display_width (2.5.0)
35
42
 
36
43
  PLATFORMS
37
44
  arm64-darwin-21
45
+ arm64-darwin-22
38
46
 
39
47
  DEPENDENCIES
40
- minitest (~> 5.0)
41
- minitest-focus
42
48
  rake (~> 13.0)
43
49
  rubocop (~> 1.21)
44
50
  rubocop-minitest
51
+ rubocop-rake
45
52
  spaced!
53
+ sus
46
54
 
47
55
  BUNDLED WITH
48
56
  2.3.7
data/README.md CHANGED
@@ -8,7 +8,7 @@ Spaced is a super simple and convenient way to isolate and namespace a collectio
8
8
  class User
9
9
  include Spaced
10
10
 
11
- # Pass a black with a bunch of methods.
11
+ # Pass a block with a bunch of methods.
12
12
  namespace :twitter do
13
13
  def create(msg)
14
14
  api.create_tweet msg
@@ -38,28 +38,28 @@ In the example above, `namespace` creates and initializes a new class `Twitter`
38
38
 
39
39
  ## Magic bang and predicate methods
40
40
 
41
- If you define a `call` method in your namespaced class, you can then conveniently call that with a bang method:
41
+ If you define a `#_!` or `#call` method in your namespaced class, you can then conveniently call that with a bang method:
42
42
 
43
43
  ```ruby
44
- class User < Spaced::Base
44
+ class User
45
45
  include Spaced
46
46
 
47
47
  namespace :tweet do
48
- def call(content)
48
+ def _!(content)
49
49
  create_tweet content
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  user = User.new
55
- user.tweet!('my new tweet') # Will call the `#call` method with whatever arguments you give it.
55
+ user.tweet!('my new tweet') # Will call the `#_!` method with whatever arguments you give it.
56
56
  ```
57
57
 
58
- There is also an equivalent `predicate` method:
58
+ There is also an equivalent predicate method:
59
59
 
60
60
  ```ruby
61
61
  namespace :tweet do
62
- def predicate
62
+ def _?
63
63
  false
64
64
  end
65
65
  end
@@ -67,6 +67,23 @@ user = User.new
67
67
  user.tweet? # Will call the `#predicate` method.
68
68
  ```
69
69
 
70
+ Both bang and predicate methods can be defined using identically named methods:
71
+
72
+ ```ruby
73
+ namespace :tweet do
74
+ def tweet?
75
+ false
76
+ end
77
+
78
+ def tweet!
79
+ # ...
80
+ end
81
+ end
82
+ user = User.new
83
+ user.tweet? # Will call the `#tweet?` method on `:tweet` namespace.
84
+ user.tweet! # Will call the `#tweet!` method on `:tweet` namespace.
85
+ ```
86
+
70
87
  ## Installation
71
88
 
72
89
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require "rake/testtask"
4
+ require "rubocop/rake_task"
5
5
 
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
6
+ task :test do
7
+ sh "bundle exec sus"
10
8
  end
11
9
 
12
- require "rubocop/rake_task"
13
-
14
10
  RuboCop::RakeTask.new
15
11
 
16
12
  task default: %i[test rubocop]
data/fixtures/daddy.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Daddy < Spaced::Base
4
+ def full_name
5
+ "Kevin Moss"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spaced"
4
+ require "bundler"
5
+
6
+ Bundler.require :test
7
+
8
+ require "daddy"
9
+ require "user"
data/fixtures/user.rb ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ class User
4
+ include Spaced
5
+
6
+ namespace :mum do
7
+ def full_name
8
+ "Lesley Moss"
9
+ end
10
+ end
11
+
12
+ namespace :dad, Daddy
13
+ namespace :brother do
14
+ def call(append = nil)
15
+ "Andy Moss#{append}"
16
+ end
17
+
18
+ def predicate
19
+ true
20
+ end
21
+ end
22
+
23
+ namespace :sister do
24
+ def sister!(append = nil)
25
+ "Alex Moss#{append}"
26
+ end
27
+
28
+ def sister?
29
+ true
30
+ end
31
+ end
32
+
33
+ namespace :mother do
34
+ def _!(append = nil)
35
+ "Lesley Moss#{append}"
36
+ end
37
+
38
+ def _?(*, **)
39
+ true
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spaced
4
- VERSION = "0.3.1"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/spaced.rb CHANGED
@@ -14,7 +14,7 @@ module Spaced
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- def namespace(name, klass = nil, &)
17
+ def namespace(name, klass = nil, &) # rubocop:disable Metrics/*
18
18
  if klass
19
19
  raise "#{klass} must be a subclass of Spaced::Base" unless klass < Spaced::Base
20
20
  else
@@ -40,21 +40,41 @@ module Spaced
40
40
  # Define the bang and predicate methods.
41
41
  methods = klass.instance_methods(false)
42
42
 
43
- if methods.include?(:call)
43
+ if methods.include?(:_!)
44
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
45
+ def #{name}!(...); #{name}._!(...); end # def user!; user._!; end
46
+ RUBY
47
+ elsif methods.include?(:"#{name}!")
48
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
49
+ def #{name}!(...); #{name}.#{name}!(...); end # def user!; user.user!; end
50
+ RUBY
51
+ elsif methods.include?(:call) # DEPRECATED
44
52
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
45
53
  def #{name}!(...); #{name}.call(...); end # def user!(...); user.call(...); end
46
54
  RUBY
47
55
  else
48
56
  define_method :"#{name}!" do
49
- raise NoMethodError, "undefined method `#{name}!' for #<#{klass}>. Have you defined `#{klass}#call`?", caller
57
+ raise NoMethodError,
58
+ "undefined method `#{name}!' for #<#{klass}>. Have you defined `#{klass}#_!`?", caller
50
59
  end
51
60
  end
52
61
 
53
- if methods.include?(:predicate)
54
- define_method(:"#{name}?") { send(name).predicate }
62
+ if methods.include?(:_?)
63
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
64
+ def #{name}?(...); #{name}._?(...); end # def user?; user._?; end
65
+ RUBY
66
+ elsif methods.include?(:"#{name}?")
67
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
68
+ def #{name}?(...); #{name}.#{name}?(...); end # def user?; user.user?; end
69
+ RUBY
70
+ elsif methods.include?(:predicate) # DEPRECATED
71
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
72
+ def #{name}?(...); #{name}.predicate(...); end # def user?; user.predicate; end
73
+ RUBY
55
74
  else
56
75
  define_method :"#{name}?" do
57
- raise NoMethodError, "undefined method `#{name}?' for #<#{klass}>. Have you defined `#{klass}#predicate`?",
76
+ raise NoMethodError,
77
+ "undefined method `#{name}?' for #<#{klass}>. Have you defined `#{klass}#_?`?",
58
78
  caller
59
79
  end
60
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spaced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -24,6 +24,9 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
+ - fixtures/daddy.rb
28
+ - fixtures/test_helper.rb
29
+ - fixtures/user.rb
27
30
  - lib/spaced.rb
28
31
  - lib/spaced/version.rb
29
32
  - sig/spaced.rbs
@@ -50,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
53
  - !ruby/object:Gem::Version
51
54
  version: '0'
52
55
  requirements: []
53
- rubygems_version: 3.3.7
56
+ rubygems_version: 3.5.7
54
57
  signing_key:
55
58
  specification_version: 4
56
59
  summary: Super simple and convenient way to isolate and namespace a collection of