acts_as_nosql 0.1.1 → 0.2.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/acts_as_nosql/attribute.rb +5 -1
- data/lib/acts_as_nosql/attributes.rb +16 -6
- data/lib/acts_as_nosql/querying.rb +2 -1
- data/lib/acts_as_nosql/version.rb +3 -1
- data/lib/acts_as_nosql.rb +9 -1
- data/spec/acts_as_nosql/inheritance_spec.rb +22 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/schema.rb +9 -0
- metadata +16 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3639ed28eafd5aecdebebca1c762df9a46d977718bb0a564c9b503eaa3150189
|
4
|
+
data.tar.gz: 0fd6362417e18df5719d06d6aae9bf40be7506315246495a937789a241d81dd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6683970d3197abcceb812746b20eb9376d4fd9c8a20628ccfe1d91b0330e7fc5a542984357a154148d7edcc70b5736a825169a060c79fffb5780d887be8223af
|
7
|
+
data.tar.gz: 95fc00a7c92311c15a89499384e76f6b435c919289ecfa5ccc63eb7d4b54cadf169ee82ed12ce423708282cb9d64dc8d3e5c1fb90a79d7a48be748f6342f796f
|
@@ -3,11 +3,15 @@ module ActsAsNosql
|
|
3
3
|
class Attribute
|
4
4
|
attr_reader :name, :type, :default, :path, :type_caster
|
5
5
|
|
6
|
+
# @param [String, Symbol] name
|
7
|
+
# @param [String, Symbol, nil] type
|
8
|
+
# @param [Object, nil] default
|
9
|
+
# @param [Array<String, Symbol>, nil] path
|
6
10
|
def initialize(name, type: nil, default: nil, path: nil)
|
7
11
|
@name = name.to_s
|
8
12
|
@type = type
|
9
13
|
@default = default
|
10
|
-
@path = path&.map
|
14
|
+
@path = path&.map(&:to_s)
|
11
15
|
@type_caster = type ? "ActiveRecord::Type::#{type}".safe_constantize : nil
|
12
16
|
end
|
13
17
|
|
@@ -29,16 +29,26 @@ module ActsAsNosql
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def inherited(subclass)
|
33
|
+
subclass._acts_as_nosql_options = self._acts_as_nosql_options.deep_dup
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
32
37
|
def nosql_attributes
|
33
38
|
self._acts_as_nosql_options[:attributes] ||= {}
|
34
39
|
end
|
35
40
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def load_schema
|
42
|
+
result = super
|
43
|
+
acts_as_nosql_check_conflicts_when_needed!
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def acts_as_nosql_check_conflicts_when_needed!
|
48
|
+
return if acts_as_nosql_conflicts_checked?
|
49
|
+
|
50
|
+
@acts_as_nosql_conflicts_checked = true
|
51
|
+
acts_as_nosql_check_conflicts!
|
42
52
|
end
|
43
53
|
|
44
54
|
def acts_as_nosql_conflicts_checked?
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module ActsAsNosql
|
3
4
|
module Querying
|
@@ -78,7 +79,7 @@ module ActsAsNosql
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def quote_full_column(field_name)
|
81
|
-
connection.quote_table_name(arel_table.table_alias || arel_table.
|
82
|
+
connection.quote_table_name(arel_table.table_alias || arel_table.name) +
|
82
83
|
'.' +
|
83
84
|
connection.quote_column_name(field_name)
|
84
85
|
end
|
data/lib/acts_as_nosql.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record'
|
2
4
|
|
5
|
+
# ActsAsNosql
|
6
|
+
#
|
7
|
+
# This gem allows to handle JSON and JSONB fields as if they are proper
|
8
|
+
# database columns, handling default values, type casting and simplifying
|
9
|
+
# validation.
|
10
|
+
# This module is the main entry point for the gem.
|
3
11
|
module ActsAsNosql
|
4
12
|
extend ActiveSupport::Concern
|
5
13
|
extend ActiveSupport::Autoload
|
6
14
|
|
7
15
|
class_methods do
|
8
16
|
attr_accessor :_acts_as_nosql_options
|
9
|
-
|
17
|
+
|
10
18
|
def acts_as_nosql(field_name: nil)
|
11
19
|
@_acts_as_nosql_options = { field_name: field_name }
|
12
20
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Inheritance' do
|
4
|
+
subject { InheritedSetting.new }
|
5
|
+
it 'inherits all methods from Settings' do
|
6
|
+
expect(subject).to respond_to(:user_auth_token)
|
7
|
+
expect(subject).to respond_to(:user_auth_token=)
|
8
|
+
|
9
|
+
subject.user_auth_token = '3'
|
10
|
+
expect(subject.user_auth_token).to eq('3')
|
11
|
+
subject.save!
|
12
|
+
expect do
|
13
|
+
expect(InheritedSetting.where(user_auth_token: '3')).to eq([subject])
|
14
|
+
end.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can be estended without affecting the parent' do
|
18
|
+
InheritedSetting.nosql_attrs :hello, type: :String
|
19
|
+
expect(subject).to respond_to(:hello)
|
20
|
+
expect(Setting.new).not_to respond_to(:hello)
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/schema.rb
CHANGED
@@ -44,6 +44,9 @@ class Setting < ActiveRecord::Base
|
|
44
44
|
nosql_attrs :user_auth_providers, type: Array, default: [], path: [:user, :auth, :providers]
|
45
45
|
end
|
46
46
|
|
47
|
+
class InheritedSetting < Setting
|
48
|
+
end
|
49
|
+
|
47
50
|
module Schema
|
48
51
|
def self.create
|
49
52
|
ActiveRecord::Migration.verbose = false
|
@@ -60,6 +63,12 @@ module Schema
|
|
60
63
|
t.json :config
|
61
64
|
t.timestamps null: false
|
62
65
|
end
|
66
|
+
|
67
|
+
create_table :inherited_settings, force: true do |t|
|
68
|
+
t.string :title
|
69
|
+
t.json :config
|
70
|
+
t.timestamps null: false
|
71
|
+
end
|
63
72
|
end
|
64
73
|
end
|
65
74
|
end
|
metadata
CHANGED
@@ -1,75 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_nosql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mònade
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2022-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '9'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '9'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '8'
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '5'
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '8'
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: activerecord
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '5'
|
39
|
+
version: '6'
|
60
40
|
- - "<"
|
61
41
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
42
|
+
version: '9'
|
63
43
|
type: :runtime
|
64
44
|
prerelease: false
|
65
45
|
version_requirements: !ruby/object:Gem::Requirement
|
66
46
|
requirements:
|
67
47
|
- - ">="
|
68
48
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
49
|
+
version: '6'
|
70
50
|
- - "<"
|
71
51
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
52
|
+
version: '9'
|
73
53
|
- !ruby/object:Gem::Dependency
|
74
54
|
name: rspec
|
75
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +90,7 @@ files:
|
|
110
90
|
- lib/acts_as_nosql/attributes.rb
|
111
91
|
- lib/acts_as_nosql/querying.rb
|
112
92
|
- lib/acts_as_nosql/version.rb
|
93
|
+
- spec/acts_as_nosql/inheritance_spec.rb
|
113
94
|
- spec/acts_as_nosql/model_spec.rb
|
114
95
|
- spec/acts_as_nosql/nested_spec.rb
|
115
96
|
- spec/acts_as_nosql/querying_spec.rb
|
@@ -119,7 +100,7 @@ homepage: https://rubygems.org/gems/acts_as_nosql
|
|
119
100
|
licenses:
|
120
101
|
- MIT
|
121
102
|
metadata: {}
|
122
|
-
post_install_message:
|
103
|
+
post_install_message:
|
123
104
|
rdoc_options: []
|
124
105
|
require_paths:
|
125
106
|
- lib
|
@@ -134,11 +115,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
115
|
- !ruby/object:Gem::Version
|
135
116
|
version: '0'
|
136
117
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
118
|
+
rubygems_version: 3.4.6
|
119
|
+
signing_key:
|
139
120
|
specification_version: 4
|
140
121
|
summary: Use JSON columns as real activerecord attributes
|
141
122
|
test_files:
|
123
|
+
- spec/acts_as_nosql/inheritance_spec.rb
|
142
124
|
- spec/acts_as_nosql/model_spec.rb
|
143
125
|
- spec/acts_as_nosql/nested_spec.rb
|
144
126
|
- spec/acts_as_nosql/querying_spec.rb
|