ru.Bee 2.3.2 → 2.4.0
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/autoload.rb +7 -0
- data/lib/rubee/configuration.rb +13 -0
- data/lib/rubee/models/sequel_object.rb +1 -1
- data/lib/rubee/support/hash.rb +62 -0
- data/lib/rubee/support/string.rb +59 -0
- data/lib/rubee.rb +4 -1
- data/lib/tests/configuration_test.rb +23 -0
- data/lib/tests/models/comment_model_test.rb +1 -1
- data/readme.md +41 -2
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 066655ef03cfa0f000d95d634a06a9f1d40259ec45ea21d86e0ee85f74bf17ed
|
|
4
|
+
data.tar.gz: 45d04a51041408d8bdd2e690618e92f288e73fda5cb4447515319cc6f498918b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 468195453447949e93d0ea7b18e5fea7384bbf80ecc07447df37b70731f698113a8e27d8015afcef1366cb6a463860ea67c4006519bc4315f5a0e72a73bbfc48
|
|
7
|
+
data.tar.gz: 33e8dac0437cec2fd495d5fe17af96daf786696a3061a392fff6b31e352bea3025f29c8a8e2db131a2c6e781727648403e998cec24a327a0b41b76c208108ded
|
data/lib/db/test.db
CHANGED
|
Binary file
|
data/lib/rubee/autoload.rb
CHANGED
|
@@ -7,6 +7,7 @@ module Rubee
|
|
|
7
7
|
# autoload all rbs
|
|
8
8
|
root_directory = File.join(Rubee::ROOT_PATH, '/lib')
|
|
9
9
|
priority_order_require(root_directory, black_list)
|
|
10
|
+
load_support(root_directory, black_list)
|
|
10
11
|
load_inits(root_directory, black_list)
|
|
11
12
|
# ensure sequel object is connected
|
|
12
13
|
Rubee::SequelObject.reconnect!
|
|
@@ -38,6 +39,12 @@ module Rubee
|
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
42
|
+
def load_support(root_directory, black_list)
|
|
43
|
+
Dir[File.join(Rubee::ROOT_PATH, '/lib', '/rubee/support/**', '*.rb')].each do |file|
|
|
44
|
+
require_relative file unless black_list.include?("#{file}.rb")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
41
48
|
def priority_order_require(root_directory, black_list)
|
|
42
49
|
# rubee pub sub
|
|
43
50
|
Dir[File.join(root_directory, 'rubee/pubsub/**', '*.rb')].each do |file|
|
data/lib/rubee/configuration.rb
CHANGED
|
@@ -32,6 +32,19 @@ module Rubee
|
|
|
32
32
|
yield(self)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
def rubee_support=(value)
|
|
36
|
+
all = value.fetch(:all, false)
|
|
37
|
+
classes = value.fetch(:classes, [])
|
|
38
|
+
if all
|
|
39
|
+
Rubee::RUBEE_SUPPORT.each do |support_string, klass|
|
|
40
|
+
support_klass = Object.const_get(support_string)
|
|
41
|
+
klass.include(support_klass)
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
classes.each { |klass| Rubee::RUBEE_SUPPORT[klass.to_s].include(klass) }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
35
48
|
def database_url=(args)
|
|
36
49
|
args[:app] ||= :app
|
|
37
50
|
@configuraiton[args[:app].to_sym][args[:env].to_sym][:database_url] = args[:url].gsub("//", "//#{Rubee::LIB}")
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Rubee
|
|
2
|
+
module Support
|
|
3
|
+
module Hash
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
base.prepend(InstanceMethods)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module ClassMethods
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module InstanceMethods
|
|
13
|
+
def [](key)
|
|
14
|
+
return wrap(super(key)) if key?(key)
|
|
15
|
+
|
|
16
|
+
alt_key =
|
|
17
|
+
case key
|
|
18
|
+
when ::Symbol then key.to_s
|
|
19
|
+
when ::String then key.to_sym
|
|
20
|
+
else key
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
wrap(super(alt_key))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def wrap(value)
|
|
29
|
+
value.is_a?(::Hash) ? value.extend(Rubee::Support::Hash::InstanceMethods) : value
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def keys_to_string!
|
|
33
|
+
keys_to(:string, self)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def keys_to_sym!
|
|
37
|
+
keys_to(:symbol, self)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def keys_to(type, obj)
|
|
41
|
+
case obj
|
|
42
|
+
when ::Hash
|
|
43
|
+
obj.each_with_object({}) do |(k, v), result|
|
|
44
|
+
key =
|
|
45
|
+
case type
|
|
46
|
+
when :string then k.to_s
|
|
47
|
+
when :symbol then k.to_sym
|
|
48
|
+
else k
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
result[key] = keys_to(type, v)
|
|
52
|
+
end
|
|
53
|
+
when ::Array
|
|
54
|
+
obj.map { |v| keys_to(type, v) }
|
|
55
|
+
else
|
|
56
|
+
obj
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Rubee
|
|
2
|
+
module Support
|
|
3
|
+
module String
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
base.include(InstanceMethods)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module ClassMethods
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module InstanceMethods
|
|
13
|
+
def pluralize
|
|
14
|
+
if end_with?('y') && !%w[a e i o u].include?(self[-2])
|
|
15
|
+
"#{self[0..-2]}ies" # Replace "y" with "ies"
|
|
16
|
+
elsif end_with?('s', 'x', 'z', 'ch', 'sh')
|
|
17
|
+
"#{self}es" # Add "es" for certain endings
|
|
18
|
+
else
|
|
19
|
+
"#{self}s" # Default to adding "s"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def plural?
|
|
24
|
+
return true if end_with?('s') && !end_with?('ss')
|
|
25
|
+
|
|
26
|
+
false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def singular?
|
|
30
|
+
!plural?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def camelize
|
|
34
|
+
split('_').map { _1.capitalize }.join
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def snakeize
|
|
38
|
+
gsub(/::/, '_')
|
|
39
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
40
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
41
|
+
.tr('-', '_')
|
|
42
|
+
.downcase
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def singularize
|
|
46
|
+
if end_with?('ies') && length > 3
|
|
47
|
+
"#{self[0..-4]}y" # Convert "ies" to "y"
|
|
48
|
+
elsif end_with?('es') && %w[s x z ch sh].any? { |ending| self[-(ending.length + 2)..-3] == ending }
|
|
49
|
+
self[0..-3] # Remove "es" for selfs like "foxes", "buses"
|
|
50
|
+
elsif end_with?('s') && length > 1
|
|
51
|
+
self[0..-2] # Remove "s" for regular plurals
|
|
52
|
+
else
|
|
53
|
+
self # Return as-is if no plural form is detected
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/lib/rubee.rb
CHANGED
|
@@ -16,8 +16,11 @@ 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
|
+
unless defined?(RUBEE_SUPPORT)
|
|
20
|
+
RUBEE_SUPPORT = { "Rubee::Support::Hash" => Hash, "Rubee::Support::String" => String }
|
|
21
|
+
end
|
|
19
22
|
|
|
20
|
-
VERSION = '2.
|
|
23
|
+
VERSION = '2.4.0'
|
|
21
24
|
|
|
22
25
|
require_relative 'rubee/router'
|
|
23
26
|
require_relative 'rubee/logger'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Configuration' do
|
|
4
|
+
describe 'rubee_support Hash only' do
|
|
5
|
+
it 'patches Hash only' do
|
|
6
|
+
String.send(:undef_method, :plural?) if "".respond_to?(:plural?)
|
|
7
|
+
Rubee::Configuration.setup(env = :test) do
|
|
8
|
+
_1.rubee_support = { classes: [Rubee::Support::Hash] }
|
|
9
|
+
end
|
|
10
|
+
_({ one: 1 }['one']).must_equal(1)
|
|
11
|
+
|
|
12
|
+
_(raise_error { "apples".plural? }.is_a?(NoMethodError)).must_equal(true)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'rubee_support all' do
|
|
17
|
+
it 'patches Hash and String' do
|
|
18
|
+
Rubee::Configuration.setup(env = :test) { _1.rubee_support = { all: true } }
|
|
19
|
+
_({ one: 1 }['one']).must_equal(1)
|
|
20
|
+
_("apples".plural?).must_equal(true)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -96,7 +96,7 @@ describe 'Comment model' do
|
|
|
96
96
|
comment = Comment.new(user_id: 1)
|
|
97
97
|
|
|
98
98
|
_(comment.valid?).must_equal(true)
|
|
99
|
-
_(comment.errors[:test]).must_equal(
|
|
99
|
+
_(comment.errors[:test].nil?).must_equal(true)
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
it 'text is a number should be invalid' do
|
data/readme.md
CHANGED
|
@@ -84,6 +84,7 @@ The comparison is based on a very generic and subjective information open in the
|
|
|
84
84
|
- [Generate commands](#generate-commands)
|
|
85
85
|
- [Migration commands](#migration-commands)
|
|
86
86
|
- [Rubee console](#rubee-console)
|
|
87
|
+
- [Rubee::Support](#rubee-support)
|
|
87
88
|
- [Testing](#testing)
|
|
88
89
|
- [Background jobs](#background-jobs)
|
|
89
90
|
- [Modular](#modualar-application)
|
|
@@ -979,7 +980,7 @@ Model example
|
|
|
979
980
|
```ruby
|
|
980
981
|
class User < Rubee::SequelObject
|
|
981
982
|
attr_accessor :id, :email, :password, :created
|
|
982
|
-
|
|
983
|
+
|
|
983
984
|
validate_after_setters # This will run validation after each setter.
|
|
984
985
|
validate_before_persist! # This will validate and raise error in case invalid before saving to DB
|
|
985
986
|
validate do
|
|
@@ -1019,7 +1020,7 @@ irb(main):081> user
|
|
|
1019
1020
|
```
|
|
1020
1021
|
If you want to apply validation_before_persist! and validation_after_setters globally,
|
|
1021
1022
|
add init/sequle_object_preloader.rb(you can chose any name)
|
|
1022
|
-
file withing set up those methods
|
|
1023
|
+
file withing set up those methods
|
|
1023
1024
|
for Rubee::SequelObject parent class by adding:
|
|
1024
1025
|
```
|
|
1025
1026
|
Rubee::SequelObject.validate_befor_persist!
|
|
@@ -1028,6 +1029,44 @@ Rubee::SequelObject.validate_after_setters
|
|
|
1028
1029
|
So you shouldn't add it to each model again and again.
|
|
1029
1030
|
[Back to content](#content)
|
|
1030
1031
|
|
|
1032
|
+
## Rubee support
|
|
1033
|
+
|
|
1034
|
+
In Rubee you have an optional way to charge your code with usefull methods that added to base Ruby classes.
|
|
1035
|
+
You can add them to your project globally by setting up it in configuration.
|
|
1036
|
+
|
|
1037
|
+
```ruby
|
|
1038
|
+
# To include all support methods
|
|
1039
|
+
Rubee::Configuration.setup do |config|
|
|
1040
|
+
config.rubee_support = { all: true }
|
|
1041
|
+
end
|
|
1042
|
+
|
|
1043
|
+
# To include only those who belong to a indicated class
|
|
1044
|
+
Rubee::Configuration.setup do |config|
|
|
1045
|
+
config.rubee_support = { classes: [Rubee::Support::String] }
|
|
1046
|
+
# So only String will be charged with support methods
|
|
1047
|
+
end
|
|
1048
|
+
```
|
|
1049
|
+
Here are list of additionl APIs extended for:
|
|
1050
|
+
|
|
1051
|
+
```ruby
|
|
1052
|
+
# By adding to configuration Rubee::Suport::Hash class or just applying all, Hash will tollerate string or symbol keys.
|
|
1053
|
+
{one: 1}[:one] # => 1
|
|
1054
|
+
{one: 1}["one"] # => 1
|
|
1055
|
+
|
|
1056
|
+
# By adding to configuration Rubee::Support::String or just applying all, String will be enriched with handy helper methods.
|
|
1057
|
+
```ruby
|
|
1058
|
+
"test".pluralize # => "tests"
|
|
1059
|
+
"test".singularize # => "test"
|
|
1060
|
+
"test".camelize # => "Test"
|
|
1061
|
+
"TestMe".snakeize # => "test_mei"
|
|
1062
|
+
"test".singular? # => true
|
|
1063
|
+
"test".plural? # => false
|
|
1064
|
+
```
|
|
1065
|
+
|
|
1066
|
+
[Back to content](#content)
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
|
|
1031
1070
|
## JWT based authentification
|
|
1032
1071
|
|
|
1033
1072
|
Charge you rpoject with token based authentification system and customize it for your needs.
|
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.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleg Saltykov
|
|
@@ -273,11 +273,14 @@ files:
|
|
|
273
273
|
- lib/rubee/pubsub/subscriber.rb
|
|
274
274
|
- lib/rubee/pubsub/test_one.rb
|
|
275
275
|
- lib/rubee/router.rb
|
|
276
|
+
- lib/rubee/support/hash.rb
|
|
277
|
+
- lib/rubee/support/string.rb
|
|
276
278
|
- lib/rubee/websocket/websocket.rb
|
|
277
279
|
- lib/rubee/websocket/websocket_connections.rb
|
|
278
280
|
- lib/tests/async/thread_async_test.rb
|
|
279
281
|
- lib/tests/cli/attach_test.rb
|
|
280
282
|
- lib/tests/cli/db_test.rb
|
|
283
|
+
- lib/tests/configuration_test.rb
|
|
281
284
|
- lib/tests/controllers/auth_tokenable_test.rb
|
|
282
285
|
- lib/tests/controllers/base_controller_test.rb
|
|
283
286
|
- lib/tests/controllers/hookable_test.rb
|