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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b96c111963e69a5ad1fb05d5b1b4e226122015a51a34ceb69ee93f1fe23a2426
4
- data.tar.gz: f210ad9397a97e65b36fa924dd1c65ea8bc5b88a5bcf7d4643cb4408c6ce0706
3
+ metadata.gz: 6fda6033bcea8b06d6c16acb8a311890bffff185065180d34e9251dd4dfde2ad
4
+ data.tar.gz: ad9be6f289ca514edc1f0a773bafde9d5f46205304e8752b139c665f1a792956
5
5
  SHA512:
6
- metadata.gz: b30676699627fcc0f65bf02462ca12138f4226004d5927e6bbb64ad8caa37fc9f6da1ed7c26f40e577392b164bd696d62f89104fa1223347635f0a4fefb11b3c
7
- data.tar.gz: 8ef41f6739a0c1771c7fab2e484fa1485e38f9a46e1a7fa8509ec40b95630c243008b92d9fa46299aa434480f62da0d6726fc08d9b08b44f4326fe4cc472c660
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
@@ -20,7 +20,7 @@ module Rubee
20
20
  RUBEE_SUPPORT = { "Rubee::Support::Hash" => Hash, "Rubee::Support::String" => String }
21
21
  end
22
22
 
23
- VERSION = '2.7.7'
23
+ VERSION = '2.7.8'
24
24
 
25
25
  require_relative 'rubee/router'
26
26
  require_relative 'rubee/logger'
@@ -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
- Output:
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru.Bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.7
4
+ version: 2.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov