acts_as_nosql 0.1.1 → 0.1.3
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 +5 -0
- 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/support/schema.rb +9 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00fb5f260f1d2ff40dc4adcb5d2dc868c45fc909753f229b60fcf878164fb933
|
4
|
+
data.tar.gz: a597101125686d651b810ba3da7a84ba1cb743eeba42e3019c6bde573999adc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b66ae32d0e756a14bf54c22d755281660cba0c907ab4435447cff643eed28b10bdfec2fb260ec19d896b9425f6c0acac1059c8efa1f85ee9720a577293d1fce5
|
7
|
+
data.tar.gz: 443123f7c7026ff6678d40650be1246cc47623f3c534ca2c679f84d6d6dbbc9bb245cc26677111c18c68a1081570c342f2bad0068d902c6780b37ae79237c36d
|
@@ -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
|
|
@@ -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/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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_nosql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mònade
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: activerecord
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '8'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: activesupport
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/acts_as_nosql/attributes.rb
|
111
111
|
- lib/acts_as_nosql/querying.rb
|
112
112
|
- lib/acts_as_nosql/version.rb
|
113
|
+
- spec/acts_as_nosql/inheritance_spec.rb
|
113
114
|
- spec/acts_as_nosql/model_spec.rb
|
114
115
|
- spec/acts_as_nosql/nested_spec.rb
|
115
116
|
- spec/acts_as_nosql/querying_spec.rb
|
@@ -134,11 +135,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
+
rubygems_version: 3.4.6
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Use JSON columns as real activerecord attributes
|
141
142
|
test_files:
|
143
|
+
- spec/acts_as_nosql/inheritance_spec.rb
|
142
144
|
- spec/acts_as_nosql/model_spec.rb
|
143
145
|
- spec/acts_as_nosql/nested_spec.rb
|
144
146
|
- spec/acts_as_nosql/querying_spec.rb
|