ru.Bee 1.10.1 → 1.11
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 +4 -4
- data/lib/rubee/extensions/hookable.rb +9 -41
- data/lib/rubee.rb +1 -1
- data/lib/tests/controllers/hookable_test.rb +56 -0
- data/lib/tests/logger_test.rb +0 -6
- data/lib/tests/test.db +0 -0
- data/readme.md +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b13412e9ba012f30b62abd7a994f6b4ed927be61a5e8d24503b63d5fe0d2b1d1
|
4
|
+
data.tar.gz: adea3313785a63c6bbd9c502d51885c8a8325344a2b0976bfcc0e0aa3e5d5532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d13cb1aabdd86f70109a496fecd67b135b5f364d6bb3ec7d0e1c5423b1bc5a8f73fcb127a7e3fda6a3b84b83d11d2fdc5acd19ec37a6665aae0dc260a29ac1a4
|
7
|
+
data.tar.gz: ebee546824550e812aea3e15fe19ef43d7538be4b8c6fd560d555e667e3477e55bc85d52d1bf57602d15e1439981f20f16a2c80a0a6abe6f748f0b59dbe1f568
|
@@ -7,16 +7,6 @@ module Rubee
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def before(*methods, handler, **options)
|
10
|
-
if options[:class_methods]
|
11
|
-
methods.each do |method|
|
12
|
-
define_method(method) do |*args, &block|
|
13
|
-
self.class.send(method, *args, &block)
|
14
|
-
end
|
15
|
-
|
16
|
-
private(method)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
methods.each do |method|
|
21
11
|
hook = Module.new do
|
22
12
|
define_method(method) do |*args, &block|
|
@@ -28,21 +18,11 @@ module Rubee
|
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
31
|
-
prepend(hook)
|
21
|
+
options[:class_methods] ? singleton_class.prepend(hook) : prepend(hook)
|
32
22
|
end
|
33
23
|
end
|
34
24
|
|
35
25
|
def after(*methods, handler, **options)
|
36
|
-
if options[:class_methods]
|
37
|
-
methods.each do |method|
|
38
|
-
define_method(method) do |*args, &block|
|
39
|
-
self.class.send(method, *args, &block)
|
40
|
-
end
|
41
|
-
|
42
|
-
private(method)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
26
|
methods.each do |method|
|
47
27
|
hook = Module.new do
|
48
28
|
define_method(method) do |*args, &block|
|
@@ -56,21 +36,11 @@ module Rubee
|
|
56
36
|
end
|
57
37
|
end
|
58
38
|
|
59
|
-
prepend(hook)
|
39
|
+
options[:class_methods] ? singleton_class.prepend(hook) : prepend(hook)
|
60
40
|
end
|
61
41
|
end
|
62
42
|
|
63
43
|
def around(*methods, handler, **options)
|
64
|
-
if options[:class_methods]
|
65
|
-
methods.each do |method|
|
66
|
-
define_method(method) do |*args, &block|
|
67
|
-
self.class.send(method, *args, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
private(method)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
44
|
methods.each do |method|
|
75
45
|
hook = Module.new do
|
76
46
|
define_method(method) do |*args, &block|
|
@@ -93,17 +63,9 @@ module Rubee
|
|
93
63
|
end
|
94
64
|
end
|
95
65
|
|
96
|
-
prepend(hook)
|
66
|
+
options[:class_methods] ? singleton_class.prepend(hook) : prepend(hook)
|
97
67
|
end
|
98
68
|
end
|
99
|
-
end
|
100
|
-
|
101
|
-
module InstanceMethods
|
102
|
-
private
|
103
|
-
|
104
|
-
def handle_class_method
|
105
|
-
self.class.send(name, *args, &block)
|
106
|
-
end
|
107
69
|
|
108
70
|
def conditions_met?(if_condition = nil, unless_condition = nil)
|
109
71
|
return true if if_condition.nil? && unless_condition.nil?
|
@@ -128,5 +90,11 @@ module Rubee
|
|
128
90
|
if_condition_result && !unless_condition_result
|
129
91
|
end
|
130
92
|
end
|
93
|
+
|
94
|
+
module InstanceMethods
|
95
|
+
def conditions_met?(if_condition = nil, unless_condition = nil)
|
96
|
+
self.class.conditions_met?(if_condition, unless_condition)
|
97
|
+
end
|
98
|
+
end
|
131
99
|
end
|
132
100
|
end
|
data/lib/rubee.rb
CHANGED
@@ -16,7 +16,7 @@ module Rubee
|
|
16
16
|
JS_DIR = File.join(APP_ROOT, LIB, 'js') unless defined?(JS_DIR)
|
17
17
|
CSS_DIR = File.join(APP_ROOT, LIB, 'css') unless defined?(CSS_DIR)
|
18
18
|
ROOT_PATH = File.expand_path(File.join(__dir__, '..')) unless defined?(ROOT_PATH)
|
19
|
-
VERSION = '1.
|
19
|
+
VERSION = '1.11'
|
20
20
|
|
21
21
|
require_relative 'rubee/router'
|
22
22
|
require_relative 'rubee/logger'
|
@@ -54,6 +54,11 @@ class TestHookable
|
|
54
54
|
before :prep_unless_condition, :set_value
|
55
55
|
after :set_unless_condition, :set_glue, unless: :value_red
|
56
56
|
|
57
|
+
# Check class methods
|
58
|
+
before :before_print_hello, :print_world, class_methods: true
|
59
|
+
after :after_print_hello, :print_world, class_methods: true
|
60
|
+
around :around_print_hello, :around_print_world, class_methods: true
|
61
|
+
|
57
62
|
def after_around_before; end
|
58
63
|
|
59
64
|
def before_around_after; end
|
@@ -82,6 +87,31 @@ class TestHookable
|
|
82
87
|
value == 'red'
|
83
88
|
end
|
84
89
|
|
90
|
+
class << self
|
91
|
+
def before_print_hello
|
92
|
+
puts 'hello'
|
93
|
+
end
|
94
|
+
|
95
|
+
def after_print_hello
|
96
|
+
puts 'hello'
|
97
|
+
end
|
98
|
+
|
99
|
+
def around_print_hello
|
100
|
+
puts 'hello'
|
101
|
+
end
|
102
|
+
|
103
|
+
def print_world
|
104
|
+
puts 'world'
|
105
|
+
end
|
106
|
+
|
107
|
+
def around_print_world
|
108
|
+
puts 'world1'
|
109
|
+
res = yield
|
110
|
+
puts 'world2'
|
111
|
+
res
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
85
115
|
private
|
86
116
|
|
87
117
|
def set_value
|
@@ -217,4 +247,30 @@ describe 'Hookable Controller' do
|
|
217
247
|
_(hookable.glue).must_be_nil
|
218
248
|
end
|
219
249
|
end
|
250
|
+
|
251
|
+
describe 'class methods' do
|
252
|
+
it 'calls before print hello hook' do
|
253
|
+
output = capture_io do
|
254
|
+
TestHookable.before_print_hello
|
255
|
+
end.first # capture_io returns [stdout, stderr]
|
256
|
+
|
257
|
+
_(output).must_equal("world\nhello\n")
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'calls after print hello hook' do
|
261
|
+
output = capture_io do
|
262
|
+
TestHookable.after_print_hello
|
263
|
+
end.first # capture_io returns [stdout, stderr]
|
264
|
+
|
265
|
+
_(output).must_equal("hello\nworld\n")
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'calls around print hello hook' do
|
269
|
+
output = capture_io do
|
270
|
+
TestHookable.around_print_hello
|
271
|
+
end.first # capture_io returns [stdout, stderr]
|
272
|
+
|
273
|
+
_(output).must_equal("world1\nhello\nworld2\n")
|
274
|
+
end
|
275
|
+
end
|
220
276
|
end
|
data/lib/tests/logger_test.rb
CHANGED
@@ -19,14 +19,12 @@ end
|
|
19
19
|
describe 'Rubee::Logger' do
|
20
20
|
describe 'logger' do
|
21
21
|
it 'exists' do
|
22
|
-
puts "logger exists"
|
23
22
|
_(Rubee::Logger).wont_be_nil
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
26
|
describe '.warn' do
|
28
27
|
it 'output message' do
|
29
|
-
puts "warn output message"
|
30
28
|
output = capture_stdout { Rubee::Logger.warn(message: 'test') }
|
31
29
|
|
32
30
|
assert_includes(output, "WARN test")
|
@@ -35,7 +33,6 @@ describe 'Rubee::Logger' do
|
|
35
33
|
|
36
34
|
describe '.info' do
|
37
35
|
it 'output message' do
|
38
|
-
puts "info output message"
|
39
36
|
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
40
37
|
|
41
38
|
assert_includes(output, "INFO test")
|
@@ -52,7 +49,6 @@ describe 'Rubee::Logger' do
|
|
52
49
|
|
53
50
|
describe '.critical' do
|
54
51
|
it 'output message' do
|
55
|
-
puts "critical output message"
|
56
52
|
output = capture_stdout { Rubee::Logger.critical(message: 'test') }
|
57
53
|
|
58
54
|
assert_includes(output, "CRITICAL test")
|
@@ -61,7 +57,6 @@ describe 'Rubee::Logger' do
|
|
61
57
|
|
62
58
|
describe '.debug' do
|
63
59
|
it 'output message' do
|
64
|
-
puts "debug output message"
|
65
60
|
output = capture_stdout { Rubee::Logger.debug(object: User.new(email: 'ok@ok.com', password: 123)) }
|
66
61
|
|
67
62
|
assert_includes(output, "DEBUG #<User:")
|
@@ -70,7 +65,6 @@ describe 'Rubee::Logger' do
|
|
70
65
|
|
71
66
|
describe 'when custom logger defined in the configuration' do
|
72
67
|
it 'uses custom logger' do
|
73
|
-
puts "CUSTOM INFO test"
|
74
68
|
Rubee::Configuration.setup(env = :test) { _1.logger = { logger: CustomLogger, env: } }
|
75
69
|
|
76
70
|
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
data/lib/tests/test.db
CHANGED
Binary file
|
data/readme.md
CHANGED
@@ -148,6 +148,8 @@ rubee start_dev --jit=yjit
|
|
148
148
|
rubee test
|
149
149
|
# or you can specify specific test file
|
150
150
|
rubee test models/user_model_test.rb
|
151
|
+
# you can run specicfc line in the test file
|
152
|
+
rubee test models/user_model_test.rb --line=12
|
151
153
|
```
|
152
154
|
[Back to content](#content)
|
153
155
|
|
@@ -812,6 +814,28 @@ after log around
|
|
812
814
|
127.0.0.1 - - [17/Feb/2025:11:42:14 -0500] "GET /apples HTTP/1.1" 401 - 0.0359
|
813
815
|
```
|
814
816
|
|
817
|
+
Starting from ver 1.11 hooks are able to be pinned to class methods.
|
818
|
+
|
819
|
+
```ruby
|
820
|
+
class AnyClass
|
821
|
+
before :print_world, :print_hello, instance_methods: true # you can useinstance method as a handler
|
822
|
+
|
823
|
+
class << self
|
824
|
+
def print_world
|
825
|
+
puts "world!"
|
826
|
+
end
|
827
|
+
|
828
|
+
def print_hello
|
829
|
+
puts "hello!"
|
830
|
+
end
|
831
|
+
end
|
832
|
+
end
|
833
|
+
```
|
834
|
+
```bash
|
835
|
+
hello!
|
836
|
+
world!
|
837
|
+
```
|
838
|
+
|
815
839
|
[Back to content](#content)
|
816
840
|
|
817
841
|
## JWT based authentification
|