active_enquo 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/active_enquo.gemspec +1 -1
- data/lib/active_enquo.rb +47 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c0103ba2927e84bdc1c6fda73e7103ffe090316fac200d7d429a95e4f4632f0
|
4
|
+
data.tar.gz: 11d5f5d66a753fe18f79f198c7b243d9fa3b194929c6e2e63c6f4a93ce25ed06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693f14e986cca46c810505664833cd4e211c170cd287d43fbbb429ba7a5ef0e830404d71597a314e97cdde4fe911edf14066f9af446510ce82c05b3e73507c6d
|
7
|
+
data.tar.gz: afba7f08679b1b45f6484f9a3bf1b870fc2a824edec9b8b33483f40b7661c940f55d8135992885011d25a4c57d6c02ecb5f069ebde0bed0d59daec85d6ad301d
|
data/active_enquo.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.required_ruby_version = ">= 2.7.0"
|
29
29
|
|
30
|
-
s.add_runtime_dependency "enquo-core", "~> 0.
|
30
|
+
s.add_runtime_dependency "enquo-core", "~> 0.6"
|
31
31
|
s.add_runtime_dependency "activerecord", ">= 6"
|
32
32
|
|
33
33
|
s.add_development_dependency "bundler"
|
data/lib/active_enquo.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require "active_record/connection_adapters/postgresql_adapter"
|
2
2
|
require "active_support/lazy_load_hooks"
|
3
3
|
|
4
|
+
require "date"
|
4
5
|
require "enquo"
|
6
|
+
require "time"
|
5
7
|
|
6
8
|
module ActiveEnquo
|
7
9
|
def self.root_key=(k)
|
@@ -85,6 +87,8 @@ module ActiveEnquo
|
|
85
87
|
module ConnectionAdapter
|
86
88
|
def initialize_type_map(m = type_map)
|
87
89
|
m.register_type "enquo_bigint", ActiveEnquo::Type::Bigint.new
|
90
|
+
m.register_type "enquo_date", ActiveEnquo::Type::Date.new
|
91
|
+
m.register_type "enquo_text", ActiveEnquo::Type::Text.new
|
88
92
|
|
89
93
|
super
|
90
94
|
end
|
@@ -105,6 +109,47 @@ module ActiveEnquo
|
|
105
109
|
field.decrypt_i64(value, context)
|
106
110
|
end
|
107
111
|
end
|
112
|
+
|
113
|
+
class Date < Type
|
114
|
+
def type
|
115
|
+
:enquo_date
|
116
|
+
end
|
117
|
+
|
118
|
+
def encrypt(value, context, field, safety: true, no_query: false)
|
119
|
+
value = cast_to_date(value)
|
120
|
+
field.encrypt_date(value, context, safety: safety, no_query: no_query)
|
121
|
+
end
|
122
|
+
|
123
|
+
def decrypt(value, context, field)
|
124
|
+
field.decrypt_date(value, context)
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def cast_to_date(value)
|
130
|
+
if Date === value
|
131
|
+
value
|
132
|
+
elsif value.respond_to?(:to_date)
|
133
|
+
value.to_date
|
134
|
+
else
|
135
|
+
Time.parse(value.to_s).to_date
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class Text < Type
|
141
|
+
def type
|
142
|
+
:enquo_text
|
143
|
+
end
|
144
|
+
|
145
|
+
def encrypt(value, context, field, safety: true, no_query: false)
|
146
|
+
field.encrypt_text(value, context, safety: safety, no_query: no_query)
|
147
|
+
end
|
148
|
+
|
149
|
+
def decrypt(value, context, field)
|
150
|
+
field.decrypt_text(value, context)
|
151
|
+
end
|
152
|
+
end
|
108
153
|
end
|
109
154
|
end
|
110
155
|
|
@@ -116,5 +161,7 @@ ActiveSupport.on_load(:active_record) do
|
|
116
161
|
|
117
162
|
unless ActiveRecord::VERSION::MAJOR == 7
|
118
163
|
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:enquo_bigint] = {}
|
164
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:enquo_date] = {}
|
165
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:enquo_text] = {}
|
119
166
|
end
|
120
167
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_enquo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: enquo-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|