dolly 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dolly/connection.rb +8 -1
- data/lib/dolly/document.rb +8 -1
- data/lib/dolly/document_creation.rb +9 -2
- data/lib/dolly/framework_helper.rb +7 -0
- data/lib/dolly/properties.rb +1 -1
- data/lib/dolly/property.rb +21 -2
- data/lib/dolly/property_manager.rb +4 -4
- data/lib/dolly/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4a7f73673dc9600d2451b6ae0dd1ed5ca8c792f671f1a115405b751610b9077
|
4
|
+
data.tar.gz: 7765f1a58d5515aebce77a79fdde6e0aad8e8928867e39c45a26ac5321ef7cb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9430a6c2bc2b951442751b3192778a7d73985d6cb3fa0864f5a9529695d20fec13cd4b451d8232f06dfc0a27cc6897acae734eb979c52b63a60d81aa7c5061c6
|
7
|
+
data.tar.gz: a46dd510d441efffe1b7998e64b5806fba6fee10470dc3c38d78a4be49bd18d48b50ad9d84b630ef0c04895934214821162a46e3bc3888a71c02171623bffdb6
|
data/lib/dolly/connection.rb
CHANGED
@@ -6,10 +6,12 @@ require 'dolly/request_header'
|
|
6
6
|
require 'dolly/exceptions'
|
7
7
|
require 'dolly/configuration'
|
8
8
|
require 'refinements/string_refinements'
|
9
|
+
require 'dolly/framework_helper'
|
9
10
|
|
10
11
|
module Dolly
|
11
12
|
class Connection
|
12
13
|
include Dolly::Configuration
|
14
|
+
include Dolly::FrameworkHelper
|
13
15
|
attr_reader :db, :app_env
|
14
16
|
|
15
17
|
DEFAULT_HEADER = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
@@ -92,7 +94,12 @@ module Dolly
|
|
92
94
|
raise Dolly::ResourceNotFound if res.status.to_i == 404
|
93
95
|
raise Dolly::ServerError.new(res.status.to_i) if (400..600).include? res.status.to_i
|
94
96
|
return res.header_str if method == :head
|
95
|
-
|
97
|
+
|
98
|
+
data = Oj.load(res.body_str, symbol_keys: true)
|
99
|
+
return data unless rails?
|
100
|
+
data.with_indifferent_access
|
101
|
+
rescue Oj::ParseError
|
102
|
+
res.body_str
|
96
103
|
end
|
97
104
|
|
98
105
|
def values_to_json hash
|
data/lib/dolly/document.rb
CHANGED
@@ -15,6 +15,7 @@ require 'dolly/timestamp'
|
|
15
15
|
require 'dolly/query_arguments'
|
16
16
|
require 'dolly/document_creation'
|
17
17
|
require 'dolly/class_methods_delegation'
|
18
|
+
require 'dolly/framework_helper'
|
18
19
|
require 'refinements/string_refinements'
|
19
20
|
|
20
21
|
module Dolly
|
@@ -35,6 +36,7 @@ module Dolly
|
|
35
36
|
include Attachment
|
36
37
|
include QueryArguments
|
37
38
|
include ClassMethodsDelegation
|
39
|
+
include FrameworkHelper
|
38
40
|
|
39
41
|
attr_writer :doc
|
40
42
|
|
@@ -46,7 +48,7 @@ module Dolly
|
|
46
48
|
protected
|
47
49
|
|
48
50
|
def doc
|
49
|
-
@doc ||=
|
51
|
+
@doc ||= doc_for_framework
|
50
52
|
end
|
51
53
|
|
52
54
|
def init_ancestor_properties
|
@@ -59,5 +61,10 @@ module Dolly
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
64
|
+
|
65
|
+
def doc_for_framework
|
66
|
+
return {} unless rails?
|
67
|
+
{}.with_indifferent_access
|
68
|
+
end
|
62
69
|
end
|
63
70
|
end
|
@@ -1,16 +1,23 @@
|
|
1
1
|
require 'dolly/properties'
|
2
|
+
require 'dolly/framework_helper'
|
2
3
|
|
3
4
|
module Dolly
|
4
5
|
module DocumentCreation
|
5
6
|
include Properties
|
7
|
+
include FrameworkHelper
|
6
8
|
|
7
9
|
def from_doc(doc)
|
8
10
|
attributes = property_clean_doc(doc)
|
9
|
-
|
11
|
+
|
12
|
+
new(attributes).tap do |model|
|
13
|
+
model.send(:doc).merge!(doc)
|
14
|
+
end
|
10
15
|
end
|
11
16
|
|
12
17
|
def from_json(json)
|
13
|
-
|
18
|
+
raw_data = Oj.load(json, symbol_keys: true)
|
19
|
+
data = rails? ? data.with_indifferent_access : raw_data
|
20
|
+
from_doc(data)
|
14
21
|
end
|
15
22
|
|
16
23
|
def create(attributes)
|
data/lib/dolly/properties.rb
CHANGED
data/lib/dolly/property.rb
CHANGED
@@ -16,10 +16,15 @@ module Dolly
|
|
16
16
|
def cast_value(value)
|
17
17
|
return set_default if value.nil?
|
18
18
|
return value unless class_name
|
19
|
-
return
|
19
|
+
return custom_class(value) unless respond_to?(klass_sym)
|
20
20
|
send(klass_sym, value)
|
21
21
|
end
|
22
22
|
|
23
|
+
def custom_class(value)
|
24
|
+
value = value.is_a?(Hash) ? value.symbolize_keys : value
|
25
|
+
self_klass.new(value)
|
26
|
+
end
|
27
|
+
|
23
28
|
def boolean?
|
24
29
|
[TrueClass, FalseClass].include?(class_name)
|
25
30
|
end
|
@@ -32,6 +37,14 @@ module Dolly
|
|
32
37
|
value.to_h
|
33
38
|
end
|
34
39
|
|
40
|
+
def hash_with_indifferent_access_value(value)
|
41
|
+
if defined?(Rails)
|
42
|
+
value.to_h.with_indifferent_access
|
43
|
+
else
|
44
|
+
value.to_h
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
35
48
|
def integer_value(value)
|
36
49
|
value.to_i
|
37
50
|
end
|
@@ -70,7 +83,13 @@ module Dolly
|
|
70
83
|
end
|
71
84
|
|
72
85
|
def klass_sym
|
73
|
-
|
86
|
+
klass_name = self_klass.
|
87
|
+
name.
|
88
|
+
split('::').
|
89
|
+
last.
|
90
|
+
underscore
|
91
|
+
|
92
|
+
:"#{klass_name}_value"
|
74
93
|
end
|
75
94
|
|
76
95
|
def self_klass
|
@@ -5,7 +5,7 @@ module Dolly
|
|
5
5
|
assign_rev_properties(attributes)
|
6
6
|
|
7
7
|
lambda do |property|
|
8
|
-
name = property.key
|
8
|
+
name = property.key
|
9
9
|
next unless doc[name].nil?
|
10
10
|
write_attribute(name, attributes[name])
|
11
11
|
end
|
@@ -19,9 +19,9 @@ module Dolly
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def write_attribute(key, value)
|
22
|
-
|
23
|
-
instance_variable_set(:"@#{key}",
|
24
|
-
update_doc(key,
|
22
|
+
casted_value = set_property_value(key, value)
|
23
|
+
instance_variable_set(:"@#{key}", casted_value)
|
24
|
+
update_doc(key, casted_value)
|
25
25
|
end
|
26
26
|
|
27
27
|
def valid_property?(name)
|
data/lib/dolly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dolly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- javierg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/dolly/document_state.rb
|
130
130
|
- lib/dolly/document_type.rb
|
131
131
|
- lib/dolly/exceptions.rb
|
132
|
+
- lib/dolly/framework_helper.rb
|
132
133
|
- lib/dolly/identity_properties.rb
|
133
134
|
- lib/dolly/mango.rb
|
134
135
|
- lib/dolly/mango_index.rb
|