ru.Bee 2.7.7 → 2.7.8
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/db/test.db +0 -0
- data/lib/rubee/extensions/hookable.rb +2 -2
- data/lib/rubee.rb +1 -1
- data/lib/tests/controllers/base_controller_test.rb +20 -0
- data/readme.md +24 -4
- 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: 6fda6033bcea8b06d6c16acb8a311890bffff185065180d34e9251dd4dfde2ad
|
|
4
|
+
data.tar.gz: ad9be6f289ca514edc1f0a773bafde9d5f46205304e8752b139c665f1a792956
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ab7565588364fa4c1590978209e1db758d6665ef38e7d86cbb8a7c3da7a2c376a4d34e699a0545c9855a6ac665b12950c888f2f0364ee1c1225f876adac1ec4
|
|
7
|
+
data.tar.gz: 43b5bee1d5f7ba3e878f4456363604d042fc1d5607260f435688882abced06cc92bde5a9a2864d6300e9eb1a6b90b34e6127d0f450cfa7f46bf48d62cc1d24fe
|
data/lib/db/test.db
CHANGED
|
Binary file
|
|
@@ -47,11 +47,11 @@ module Rubee
|
|
|
47
47
|
if conditions_met?(options[:if], options[:unless])
|
|
48
48
|
if handler.respond_to?(:call)
|
|
49
49
|
result = nil
|
|
50
|
-
safe_call(handler, [self, args]) do
|
|
50
|
+
handler_result = safe_call(handler, [self, args]) do
|
|
51
51
|
result = super(*args, &block)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
result
|
|
54
|
+
result || handler_result
|
|
55
55
|
else
|
|
56
56
|
send(handler) do
|
|
57
57
|
super(*args, &block)
|
data/lib/rubee.rb
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
require_relative '../test_helper'
|
|
2
2
|
|
|
3
3
|
class TestRedirectController < Rubee::BaseController
|
|
4
|
+
around :test_me, ->(controller, &test_method) do
|
|
5
|
+
if true # We wnat to make sure that origianl method is replaced
|
|
6
|
+
controller.response_with(type: :json, object: { hijacked: :yes })
|
|
7
|
+
else
|
|
8
|
+
test_method.call
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
4
12
|
def index
|
|
5
13
|
response_with(type: :redirect, to: '/test')
|
|
6
14
|
end
|
|
@@ -8,6 +16,10 @@ class TestRedirectController < Rubee::BaseController
|
|
|
8
16
|
def test
|
|
9
17
|
response_with(type: :json, object: { ok: :ok })
|
|
10
18
|
end
|
|
19
|
+
|
|
20
|
+
def test_me
|
|
21
|
+
response_with(type: :json, object: { ok: :ok })
|
|
22
|
+
end
|
|
11
23
|
end
|
|
12
24
|
|
|
13
25
|
class BaseControllerTest < Minitest::Test
|
|
@@ -21,6 +33,7 @@ class BaseControllerTest < Minitest::Test
|
|
|
21
33
|
Rubee::Router.draw do |route|
|
|
22
34
|
route.get('/test', to: 'test_redirect#test')
|
|
23
35
|
route.get('/index', to: 'test_redirect#index')
|
|
36
|
+
route.get('/test_me', to: 'test_redirect#test_me')
|
|
24
37
|
end
|
|
25
38
|
end
|
|
26
39
|
|
|
@@ -45,4 +58,11 @@ class BaseControllerTest < Minitest::Test
|
|
|
45
58
|
assert_equal('/test', last_response.headers['Location'])
|
|
46
59
|
assert_equal('', last_response.body)
|
|
47
60
|
end
|
|
61
|
+
|
|
62
|
+
def test_hijacked_test_by_around
|
|
63
|
+
get('/test_me')
|
|
64
|
+
|
|
65
|
+
assert_equal(200, last_response.status)
|
|
66
|
+
assert_equal({ "hijacked" => "yes" }, JSON.parse(last_response.body))
|
|
67
|
+
end
|
|
48
68
|
end
|
data/readme.md
CHANGED
|
@@ -380,12 +380,12 @@ Get all records scoped by a field
|
|
|
380
380
|
irb(main):005> User.where(email: "ok23@ok.com")
|
|
381
381
|
=> [#<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">]
|
|
382
382
|
```
|
|
383
|
-
Get the first record. It is a shortcut for `User.where(email: "ok23@ok.com").order(:id).limit(1).last`
|
|
383
|
+
Get the first record, scoped by field. It is a shortcut for `User.where(email: "ok23@ok.com").order(:id).limit(1).last`
|
|
384
384
|
```ruby
|
|
385
385
|
irb(main):006> User.find_first(email: "ok23@ok.com")
|
|
386
386
|
=> #<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">
|
|
387
387
|
```
|
|
388
|
-
Get the last record. It is a shortcut for `User.where(email: "ok23@ok.com").order(id: :desc).limit(1).last`
|
|
388
|
+
Get the last record, scoped by field. It is a shortcut for `User.where(email: "ok23@ok.com").order(id: :desc).limit(1).last`
|
|
389
389
|
```ruby
|
|
390
390
|
irb(main):007> User.find_last(email: "ok23@ok.com")
|
|
391
391
|
=> #<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">
|
|
@@ -940,11 +940,31 @@ class AnyClass
|
|
|
940
940
|
end
|
|
941
941
|
end
|
|
942
942
|
```
|
|
943
|
+
The "around" hook can be used to hijack origianl method execution:
|
|
944
|
+
```ruby
|
|
945
|
+
class AnyClass
|
|
946
|
+
include Rubee::Hookable
|
|
947
|
+
around :print_world, ->(this_instance, &target_method) do
|
|
948
|
+
if condition_that_return_false
|
|
949
|
+
target_method.call
|
|
950
|
+
else
|
|
951
|
+
this_instance.print_hello
|
|
952
|
+
end
|
|
953
|
+
end
|
|
943
954
|
|
|
944
|
-
|
|
955
|
+
def print_world
|
|
956
|
+
puts "world!"
|
|
957
|
+
end
|
|
958
|
+
|
|
959
|
+
def print_hello
|
|
960
|
+
puts "hello!"
|
|
961
|
+
end
|
|
962
|
+
end
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
This will replace origianl method execution with `print_hello` if `condition_that_return_false` returns false.
|
|
945
966
|
```bash
|
|
946
967
|
hello!
|
|
947
|
-
world!
|
|
948
968
|
```
|
|
949
969
|
|
|
950
970
|
[Back to content](#content)
|