ru.Bee 1.9.11 → 1.9.13

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: 6943917dd749518abbf2713483ef1ef969717235159cabf67f5f59b868691c35
4
- data.tar.gz: 065ee4dc8c293bb742e7a3c08efbc37999a5750ca2bfd55b66701c062447c3c5
3
+ metadata.gz: 67b4b7a2e0717e400e958cabecbab8ad3fd47725015ba3ef1ee9245fe1ea9e12
4
+ data.tar.gz: 51de37c21accea30e09def16555077af3a6076110c69746a6245e2a79e242f94
5
5
  SHA512:
6
- metadata.gz: 9bf232de88ee04cbf5efa697a04b6af0c8ad952f4141c55e49e9572d0daf3ff72834cd2de39a24d5482d7d4927e8835534e2b900974f5dd9b89722c38148a5be
7
- data.tar.gz: a5f250547b602fbd94e0d283e325a4409e923c2c0d8afd2d74f031138aaa3fb49839655c46f060aac30f652a812297d93cf302075b70d7de2782c28484229f1a
6
+ metadata.gz: 9453e184e417bd47d87729d307c171cdf35d1f482f0a326432dd5a4d740ea007995420f4d9163b3c82b1d0e297bfcc133479ec4127d9b0520b1a7fc81969c8a9
7
+ data.tar.gz: e45a5a0ac96acb7306788bd95d760231494b1db18ebc4439fed99bd6571876c83579187b3836a54f869afcef1be9383af88d1d7d89766063c22b19c729fbc061
@@ -29,7 +29,7 @@ module Rubee
29
29
 
30
30
  def authentificated_user
31
31
  # User model must be created with email and password properties at least
32
- if !@request.cookies['jwt'] && params[:email] && params[:password]
32
+ if params[:email] && params[:password]
33
33
  @authentificated_user ||= ::User.where(email: params[:email], password: params[:password]).first
34
34
  elsif @request.cookies['jwt'] && valid_token?
35
35
  token = @request.cookies['jwt']
@@ -6,56 +6,62 @@ module Rubee
6
6
  end
7
7
 
8
8
  module ClassMethods
9
- def before(method, handler, **options)
10
- hooks = Module.new do
11
- define_method(method) do |*args, &block|
12
- if conditions_met?(options[:if], options[:unless])
13
- handler.respond_to?(:call) ? handler.call : send(handler)
14
- end
9
+ def before(*methods, handler, **options)
10
+ methods.each do |method|
11
+ hooks = Module.new do
12
+ define_method(method) do |*args, &block|
13
+ if conditions_met?(options[:if], options[:unless])
14
+ handler.respond_to?(:call) ? handler.call : send(handler)
15
+ end
15
16
 
16
- super(*args, &block)
17
+ super(*args, &block)
18
+ end
17
19
  end
20
+ prepend(hooks)
18
21
  end
19
- prepend(hooks)
20
22
  end
21
23
 
22
- def after(method, handler, **options)
23
- hooks = Module.new do
24
- define_method(method) do |*args, &block|
25
- result = super(*args, &block)
24
+ def after(*methods, handler, **options)
25
+ methods.each do |method|
26
+ hooks = Module.new do
27
+ define_method(method) do |*args, &block|
28
+ result = super(*args, &block)
26
29
 
27
- if conditions_met?(options[:if], options[:unless])
28
- handler.respond_to?(:call) ? handler.call : send(handler)
29
- end
30
+ if conditions_met?(options[:if], options[:unless])
31
+ handler.respond_to?(:call) ? handler.call : send(handler)
32
+ end
30
33
 
31
- result
34
+ result
35
+ end
32
36
  end
37
+ prepend(hooks)
33
38
  end
34
- prepend(hooks)
35
39
  end
36
40
 
37
- def around(method, handler, **options)
38
- hooks = Module.new do
39
- define_method(method) do |*args, &block|
40
- if conditions_met?(options[:if], options[:unless])
41
- if handler.respond_to?(:call)
42
- result = nil
43
- handler.call do
44
- result = super(*args, &block)
45
- end
41
+ def around(*methods, handler, **options)
42
+ methods.each do |method|
43
+ hooks = Module.new do
44
+ define_method(method) do |*args, &block|
45
+ if conditions_met?(options[:if], options[:unless])
46
+ if handler.respond_to?(:call)
47
+ result = nil
48
+ handler.call do
49
+ result = super(*args, &block)
50
+ end
46
51
 
47
- result
48
- else
49
- return send(handler) do
50
- super(*args, &block)
52
+ result
53
+ else
54
+ send(handler) do
55
+ super(*args, &block)
56
+ end
51
57
  end
58
+ else
59
+ super(*args, &block)
52
60
  end
53
- else
54
- super(*args, &block)
55
61
  end
56
62
  end
63
+ prepend(hooks)
57
64
  end
58
- prepend(hooks)
59
65
  end
60
66
  end
61
67
 
@@ -86,15 +86,21 @@ module Rubee
86
86
  # owns_many :comments
87
87
  # > user.comments
88
88
  # > [<comment1>, <comment2>]
89
- def owns_many(assoc, fk_name: nil, over: nil, **_options)
89
+ def owns_many(assoc, fk_name: nil, over: nil, **options)
90
90
  singularized_assoc_name = assoc.to_s.singularize
91
91
  fk_name ||= "#{name.to_s.downcase}_id"
92
+ namespace = options[:namespace]
92
93
 
93
94
  define_method(assoc) do
94
- klass = Object.const_get(singularized_assoc_name.capitalize)
95
+ assoc = if namespace
96
+ "::#{namespace.to_s.camelize}::#{singularized_assoc_name.camelize}"
97
+ else
98
+ singularized_assoc_name.camelize
99
+ end
100
+ klass = Object.const_get(assoc)
95
101
  if over
96
102
  sequel_dataset = klass
97
- .join(over.to_sym, "#{singularized_assoc_name}_id".to_sym => :id)
103
+ .join(over.to_sym, "#{singularized_assoc_name.snakeize}_id".to_sym => :id)
98
104
  .where(fk_name.to_sym => id)
99
105
  self.class.serialize(sequel_dataset, klass)
100
106
  else
@@ -107,10 +113,16 @@ module Rubee
107
113
  # owns_one :user
108
114
  # > comment.user
109
115
  # > <user>
110
- def owns_one(assoc, options = {})
116
+ def owns_one(assoc, fk_name: nil, **options)
111
117
  fk_name ||= "#{name.to_s.downcase}_id"
118
+ namespace = options[:namespace]
112
119
  define_method(assoc) do
113
- Object.const_get(assoc.capitalize).where(fk_name.to_sym => id)&.first
120
+ assoc = if namespace
121
+ "::#{namespace.to_s.camelize}::#{assoc.to_s.camelize}"
122
+ else
123
+ assoc.to_s.camelize
124
+ end
125
+ Object.const_get(assoc).where(fk_name.to_sym => id)&.first
114
126
  end
115
127
  end
116
128
 
@@ -118,10 +130,16 @@ module Rubee
118
130
  # holds :user
119
131
  # > account.user
120
132
  # > <user>
121
- def holds(assoc, fk_name: nil, **_options)
133
+ def holds(assoc, fk_name: nil, **options)
134
+ namespace = options[:namespace]
122
135
  fk_name ||= "#{assoc.to_s.downcase}_id"
123
136
  define_method(assoc) do
124
- target_klass = Object.const_get(assoc.capitalize)
137
+ klass_string = if namespace
138
+ "::#{namespace.to_s.camelize}::#{assoc.to_s.camelize}"
139
+ else
140
+ assoc.to_s.camelize
141
+ end
142
+ target_klass = Object.const_get(klass_string)
125
143
  target_klass.find(send(fk_name))
126
144
  end
127
145
  end
@@ -184,7 +202,7 @@ module Rubee
184
202
  def serialize(suquel_dataset, klass = nil)
185
203
  klass ||= self
186
204
  suquel_dataset.map do |record_hash|
187
- target_klass_fields = DB[klass.name.pluralize.downcase.camelize.to_sym].columns
205
+ target_klass_fields = DB[klass.name.pluralize.downcase.to_s.camelize.to_sym].columns
188
206
  klass_attributes = record_hash.filter { target_klass_fields.include?(_1) }
189
207
  klass.new(**klass_attributes)
190
208
  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.9.11'
19
+ VERSION = '1.9.13'
20
20
 
21
21
  require_relative 'rubee/router'
22
22
  require_relative 'rubee/logger'
data/lib/tests/test.db CHANGED
Binary file
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: 1.9.11
4
+ version: 1.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
@@ -300,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
300
  - !ruby/object:Gem::Version
301
301
  version: '0'
302
302
  requirements: []
303
- rubygems_version: 3.6.8
303
+ rubygems_version: 3.6.9
304
304
  specification_version: 4
305
305
  summary: Fast and lightweight Ruby application server designed for minimalism and
306
306
  flexibility