ru.Bee 1.9.14 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5259ec5377cfbd7a49693fa00e3d472725a7c95ee573dad1cc76ac883fe2e276
4
- data.tar.gz: 1e81a561bcd800bbced87c9efc0ff1d7795e248d52f37463d054c7bd19445157
3
+ metadata.gz: 4309600ffa9a5cff66e752b2068805b1b5a0f16471b6be7a5ac00c7e1326c75a
4
+ data.tar.gz: f8fd1a0ac518e24eb9c03885e39448a7f1f94bfce6f5a5bdfd5e99ea35987bf2
5
5
  SHA512:
6
- metadata.gz: b745d2eb4ff623ab0c16cd6c972a656f981691afbfb6daeebc774cf2a0e2989f904cc00ccd277485599e64f6aa273663176e2dc36993067815f25059269b1d64
7
- data.tar.gz: 6e9a8cb3555237fd765e8a8e0eb5ffe959bbd3f075ab6e67b0b91093491ee2203d05f15b4c4308c8800196b2bdbe07f593d7fed8cd9fd15c739455328f05639e
6
+ metadata.gz: ed3f43069f1b6c7e9dd3633e54ca9eb76b5fe8ed11c944690959f8c971623a33b688e156a8996477c49ce177f5702f2a6a87196299b881bb1f8c6d8a42ee725c
7
+ data.tar.gz: d560d5c3272d758b1f082c1a036e092f95e86d8cbb6243ff44fff39b1872b46cea410e96d31b6317ac6a916619ce6dd539e5054f3998af0712d5d86c4f029b6a
@@ -2,5 +2,5 @@
2
2
  # If you remove or modify it, make sure all changes are inlined
3
3
  # with AuthTokenMiddleware and AuthTokenable modules
4
4
  class User < Rubee::SequelObject
5
- attr_accessor :id, :email, :password
5
+ attr_accessor :id, :email, :password, :created, :updated
6
6
  end
@@ -0,0 +1 @@
1
+ <h1>s_ View</h1>
@@ -6,6 +6,9 @@ class CreateAccounts
6
6
  primary_key(:id)
7
7
  String(:addres)
8
8
  foreign_key(:user_id, :users)
9
+ # timestamps
10
+ datetime(:created)
11
+ datetime(:updated)
9
12
  end
10
13
 
11
14
  Account.create(addres: '13th Ave, NY', user_id: User.all.first.id)
@@ -10,6 +10,9 @@ class CreateAddresses
10
10
  String(:street)
11
11
  String(:apt)
12
12
  foreign_key(:user_id, :users)
13
+ # timestamps
14
+ datetime(:created)
15
+ datetime(:updated)
13
16
  end
14
17
 
15
18
  # Address.create(street: '13th Ave', city: 'NY', state: 'NY', zip: '55555', user_id: User.all.first.id)
@@ -6,6 +6,10 @@ class CreateComments
6
6
  primary_key(:id)
7
7
  String(:text)
8
8
  Integer(:user_id)
9
+ # timestamps
10
+ datetime(:created)
11
+ datetime(:updated)
12
+
9
13
  end
10
14
 
11
15
  User.create(email: 'ok@ok.com', password: 'password')
@@ -6,6 +6,9 @@ class CreatePosts
6
6
  primary_key(:id)
7
7
  foreign_key(:user_id, :users)
8
8
  foreign_key(:comment_id, :comments)
9
+ # timestamps
10
+ datetime(:created)
11
+ datetime(:updated)
9
12
  end
10
13
 
11
14
  Post.create(user_id: User.all.first.id, comment_id: Comment.all.first.id)
@@ -9,6 +9,9 @@ class CreateUsers
9
9
  String(:email)
10
10
  String(:password)
11
11
  index(:email)
12
+ # timestamps
13
+ datetime(:created)
14
+ datetime(:updated)
12
15
  end
13
16
 
14
17
  User.create(email: 'ok@ok.com', password: 'password')
@@ -7,8 +7,18 @@ 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
+
10
20
  methods.each do |method|
11
- hooks = Module.new do
21
+ hook = Module.new do
12
22
  define_method(method) do |*args, &block|
13
23
  if conditions_met?(options[:if], options[:unless])
14
24
  handler.respond_to?(:call) ? handler.call : send(handler)
@@ -17,13 +27,24 @@ module Rubee
17
27
  super(*args, &block)
18
28
  end
19
29
  end
20
- prepend(hooks)
30
+
31
+ prepend(hook)
21
32
  end
22
33
  end
23
34
 
24
35
  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
+
25
46
  methods.each do |method|
26
- hooks = Module.new do
47
+ hook = Module.new do
27
48
  define_method(method) do |*args, &block|
28
49
  result = super(*args, &block)
29
50
 
@@ -34,13 +55,24 @@ module Rubee
34
55
  result
35
56
  end
36
57
  end
37
- prepend(hooks)
58
+
59
+ prepend(hook)
38
60
  end
39
61
  end
40
62
 
41
63
  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
+
42
74
  methods.each do |method|
43
- hooks = Module.new do
75
+ hook = Module.new do
44
76
  define_method(method) do |*args, &block|
45
77
  if conditions_met?(options[:if], options[:unless])
46
78
  if handler.respond_to?(:call)
@@ -60,7 +92,8 @@ module Rubee
60
92
  end
61
93
  end
62
94
  end
63
- prepend(hooks)
95
+
96
+ prepend(hook)
64
97
  end
65
98
  end
66
99
  end
@@ -68,6 +101,10 @@ module Rubee
68
101
  module InstanceMethods
69
102
  private
70
103
 
104
+ def handle_class_method
105
+ self.class.send(name, *args, &block)
106
+ end
107
+
71
108
  def conditions_met?(if_condition = nil, unless_condition = nil)
72
109
  return true if if_condition.nil? && unless_condition.nil?
73
110
 
@@ -4,6 +4,8 @@ module Rubee
4
4
  using ChargedString
5
5
  using ChargedHash
6
6
 
7
+ before :save, :update, :set_timestamps
8
+
7
9
  def destroy(cascade: false, **_options)
8
10
  if cascade
9
11
  # find all tables with foreign key
@@ -41,14 +43,15 @@ module Rubee
41
43
  true
42
44
  end
43
45
 
44
- def assign_attributes(args = {})
45
- to_h.each_key do |attr|
46
+ def assign_attributes(args={})
47
+ self.class.dataset.columns do |attr|
46
48
  send("#{attr}=", args[attr.to_sym]) if args[attr.to_sym]
47
49
  end
48
50
  end
49
51
 
50
- def update(args = {})
52
+ def update(args={})
51
53
  assign_attributes(args)
54
+ args.merge!(updated:)
52
55
  found_hash = self.class.dataset.where(id:)
53
56
  return self.class.find(id) if Rubee::DBTools.with_retry { found_hash&.update(**args) }
54
57
 
@@ -63,6 +66,15 @@ module Rubee
63
66
  self.class.find(id)
64
67
  end
65
68
 
69
+ private
70
+
71
+ def set_timestamps
72
+ return unless respond_to?(:created) && respond_to?(:updated)
73
+
74
+ self.created ||= Time.now
75
+ self.updated = Time.now
76
+ end
77
+
66
78
  class << self
67
79
  def last
68
80
  found_hash = dataset.order(:id).last
@@ -191,6 +203,10 @@ module Rubee
191
203
  end
192
204
 
193
205
  def create(attrs)
206
+ if dataset.columns.include?(:created) && dataset.columns.include?(:updated)
207
+ attrs.merge!(created: Time.now, updated: Time.now)
208
+ end
209
+
194
210
  out_id = Rubee::DBTools.with_retry { dataset.insert(**attrs) }
195
211
  new(**attrs.merge(id: out_id))
196
212
  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.14'
19
+ VERSION = '1.10.0'
20
20
 
21
21
  require_relative 'rubee/router'
22
22
  require_relative 'rubee/logger'
@@ -1,5 +1,5 @@
1
1
  class Account < Rubee::SequelObject
2
- attr_accessor :id, :addres, :user_id
2
+ attr_accessor :id, :addres, :user_id, :created, :updated
3
3
 
4
4
  holds :user
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Address < Rubee::SequelObject
2
- attr_accessor :id, :street, :apt, :city, :state, :zip, :user_id
2
+ attr_accessor :id, :street, :apt, :city, :state, :zip, :user_id, :created, :updated
3
3
 
4
4
  holds :user
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Comment < Rubee::SequelObject
2
- attr_accessor :id, :text, :user_id
2
+ attr_accessor :id, :text, :user_id, :created, :updated
3
3
 
4
4
  owns_many :users, over: :posts
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Post < Rubee::SequelObject
2
- attr_accessor :id, :user_id, :comment_id
2
+ attr_accessor :id, :user_id, :comment_id, :created, :updated
3
3
 
4
4
  holds :comment
5
5
  holds :user
@@ -1,5 +1,5 @@
1
1
  class User < Rubee::SequelObject
2
- attr_accessor :id, :email, :password
2
+ attr_accessor :id, :email, :password, :created, :updated
3
3
 
4
4
  owns_many :accounts, cascade: true
5
5
  owns_one :address, cascade: true
@@ -1,4 +1,5 @@
1
1
  require_relative '../test_helper'
2
+
2
3
  describe 'User model' do
3
4
  describe '.create' do
4
5
  after do
@@ -11,6 +12,18 @@ describe 'User model' do
11
12
 
12
13
  _(user.persisted?).must_equal(true)
13
14
  end
15
+
16
+ it 'set created field' do
17
+ user = User.create(email: 'ok-test@test.com', password: '123')
18
+
19
+ _(user.created.is_a?(Time)).must_equal(true)
20
+ end
21
+
22
+ it 'set updated field' do
23
+ user = User.create(email: 'ok-test@test.com', password: '123')
24
+
25
+ _(user.updated.is_a?(Time)).must_equal(true)
26
+ end
14
27
  end
15
28
 
16
29
  describe 'when data is invalid' do
@@ -39,6 +52,15 @@ describe 'User model' do
39
52
 
40
53
  _(user.persisted?).must_equal(true)
41
54
  end
55
+
56
+ it 'updates updated field' do
57
+ user = User.create(email: 'ok-test@test.com', password: '123')
58
+ after_create_updated = user.updated
59
+
60
+ user.email = 'ok-test2@test.com'
61
+ user.save
62
+ _(user.updated > after_create_updated).must_equal(true)
63
+ end
42
64
  end
43
65
 
44
66
  describe 'when save existing user' do
@@ -108,6 +130,25 @@ describe 'User model' do
108
130
 
109
131
  _(user.reload.password).must_equal('1234')
110
132
  end
133
+
134
+ it 'updates updated field' do
135
+ user = User.create(email: 'ok-test@test.com', password: '123')
136
+ after_create_updated = user.updated
137
+
138
+ user.update(email: 'ok-test2@test.com')
139
+ _(user.updated > after_create_updated).must_equal(true)
140
+ end
141
+ end
142
+
143
+ describe 'when udpate existing user with no argumants' do
144
+ it 'update updated field' do
145
+ user = User.new(email: 'ok-test@test.com', password: '123')
146
+ user.save
147
+ updated_field_before_update = user.updated
148
+
149
+ user.update
150
+ _(user.updated > updated_field_before_update).must_equal(true)
151
+ end
111
152
  end
112
153
  end
113
154
 
data/lib/tests/test.db CHANGED
Binary file
data/readme.md CHANGED
@@ -18,7 +18,7 @@ Want to get a quick API server up and runing? You can do it for real quick!
18
18
 
19
19
  ## Production ready
20
20
 
21
- Take a look on the rubee demo site with all documentation stored in there: https://rubee.duckdns.org
21
+ Take a look on the rubee demo site with all documentation stored in there: https://rubee.dedyn.io/
22
22
  Want to explore how it built? https://github.com/nucleom42/rubee-site
23
23
 
24
24
  ## Stress tested
@@ -44,7 +44,6 @@ Transfer/sec: 140.07KB
44
44
 
45
45
  This demonstrates RUBEE’s efficient architecture and suitability for lightweight deployments — even on low-power hardware.
46
46
 
47
-
48
47
  ## Content
49
48
 
50
49
  - [Installation](#installation)
@@ -65,10 +64,10 @@ This demonstrates RUBEE’s efficient architecture and suitability for lightweig
65
64
  - [Modular](#modualar-application)
66
65
  - [Logger](#logger)
67
66
 
68
- <details>
69
- <summary id="content">📚 Documentation Content — Click to expand!</summary>
67
+ You can read it on the demo [site](https://rubee.dedyn.io/)
70
68
 
71
- You can read it on the demo [site](https://rubee.duckdns.org/docs).
69
+ 🚧 The doc site is on uodate mode now. We are working on it.
70
+ Please refer to downbelow documentation.
72
71
 
73
72
  ## Features
74
73
 
@@ -698,6 +697,9 @@ So that will ensure all cahnges applying instantly.
698
697
 
699
698
  6. You can generate react view from the route by indicating the view name explicitly
700
699
 
700
+ 7. Do not forget to rebuild react app in production by running `rubee react build`. This is unnecessary in development,
701
+ when you use `rubee react watch` tho. So it does rebuild automatically.
702
+
701
703
  ```ruby
702
704
  # config/routes.rb
703
705
  Rubee::Router.draw do |router|
@@ -1025,15 +1027,16 @@ When you trigger the controller action, the logs will look like this:
1025
1027
 
1026
1028
  [Back to content](#content)
1027
1029
 
1028
- </details>
1029
-
1030
1030
  ### Contributing
1031
1031
 
1032
1032
  If you are interested in contributing to RUBEE,
1033
- please read the [Contributing](https://github.com/nucleom42/rubee/blob/main/CONTRIBUTING.md) guide.
1033
+ please read the [Contributing]()https://github.com/nucleom42/rubee/blob/main/contribution.md) guide.
1034
1034
  Also feel free to open an [issue](https://github.com/nucleom42/rubee/issues) if you apot one.
1035
1035
  Have an idea or you wnat to discuss something?
1036
1036
  Please open a [discussion](https://github.com/nucleom42/rubee/discussions)
1037
1037
 
1038
+ ## Roadmap
1039
+ Please refer the [Roadmap](https://github.com/nucleom42/rubee/blob/main/roadmap.md)
1040
+
1038
1041
  ## License
1039
1042
  This project is released under the [MIT License](https://github.com/nucleom42/rubee/blob/main/LICENSE).
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.14
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
@@ -47,6 +47,7 @@ files:
47
47
  - lib/app/views/apples_.erb
48
48
  - lib/app/views/index.html
49
49
  - lib/app/views/layout.erb
50
+ - lib/app/views/s_.erb
50
51
  - lib/app/views/utils/redirectToBackend.tsx
51
52
  - lib/app/views/welcome_header.erb
52
53
  - lib/app/views/welcome_show.erb