ncore 2.3.1 → 3.3.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/CHANGELOG.md +63 -1
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/example/lib/my_api/api_config.rb +10 -0
- data/example/lib/my_api/rails/railtie.rb +4 -0
- data/lib/ncore.rb +31 -4
- data/lib/ncore/associations.rb +13 -13
- data/lib/ncore/attributes.rb +36 -15
- data/lib/ncore/base.rb +6 -3
- data/lib/ncore/client.rb +29 -27
- data/lib/ncore/client_cache.rb +48 -0
- data/lib/ncore/configuration.rb +16 -3
- data/lib/ncore/exceptions.rb +5 -2
- data/lib/ncore/identity.rb +27 -0
- data/lib/ncore/lifecycle.rb +3 -3
- data/lib/ncore/methods/all.rb +3 -7
- data/lib/ncore/methods/build.rb +2 -2
- data/lib/ncore/methods/count.rb +1 -1
- data/lib/ncore/methods/create.rb +4 -5
- data/lib/ncore/methods/delete.rb +6 -7
- data/lib/ncore/methods/delete_bulk.rb +4 -4
- data/lib/ncore/methods/delete_single.rb +4 -5
- data/lib/ncore/methods/find.rb +5 -6
- data/lib/ncore/methods/find_single.rb +5 -9
- data/lib/ncore/methods/update.rb +6 -7
- data/lib/ncore/methods/update_bulk.rb +26 -0
- data/lib/ncore/rails/active_model.rb +24 -14
- data/lib/ncore/singleton_base.rb +4 -3
- data/lib/ncore/util.rb +10 -2
- data/lib/ncore/version.rb +1 -1
- data/ncore.gemspec +1 -1
- metadata +7 -6
- data/lib/ncore/rails/module_fix.rb +0 -17
@@ -0,0 +1,26 @@
|
|
1
|
+
module NCore
|
2
|
+
module UpdateBulk
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def bulk_update!(ids, params={})
|
7
|
+
raise(module_parent::RecordNotFound, "ids must not be empty") if ids.blank?
|
8
|
+
params = parse_request_params(params, json_root: json_root)
|
9
|
+
params[:ids] = ids
|
10
|
+
parsed, creds = request(:put, resource_path, params)
|
11
|
+
if parsed[:errors].any?
|
12
|
+
raise module_parent::BulkActionError, parsed[:errors]
|
13
|
+
else
|
14
|
+
parsed[:metadata]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def bulk_update(ids, params={})
|
19
|
+
bulk_update!(ids, params)
|
20
|
+
rescue module_parent::RecordNotFound, module_parent::BulkActionError
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_model'
|
2
|
-
|
3
1
|
module NCore
|
4
2
|
module ActiveModel
|
5
3
|
extend ActiveSupport::Concern
|
@@ -8,12 +6,11 @@ module NCore
|
|
8
6
|
include ::ActiveModel::Conversion
|
9
7
|
extend ::ActiveModel::Naming
|
10
8
|
extend ::ActiveModel::Translation
|
11
|
-
alias :errors :errors_for_actionpack
|
12
9
|
end
|
13
10
|
|
14
|
-
if defined?(Rails)
|
11
|
+
if defined?(::Rails)
|
15
12
|
def logger
|
16
|
-
Rails.logger
|
13
|
+
::Rails.logger
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
@@ -29,17 +26,30 @@ module NCore
|
|
29
26
|
delete(*args)
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
|
30
|
+
# compatible with ActiveRecord 5.2+ default settings
|
31
|
+
# on <= 5.1, does not include version
|
32
|
+
def cache_key(*_)
|
33
|
+
if new_record?
|
34
|
+
"#{model_name.cache_key}/new"
|
35
|
+
else
|
36
|
+
"#{model_name.cache_key}/#{id}"
|
37
37
|
end
|
38
|
-
e0
|
39
38
|
end
|
40
39
|
|
41
|
-
|
40
|
+
def cache_version
|
41
|
+
if timestamp = try(:updated_at)
|
42
|
+
timestamp.utc.to_s(:usec)
|
43
|
+
end
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
46
|
+
def cache_key_with_version
|
47
|
+
if version = cache_version
|
48
|
+
"#{cache_key}-#{version}"
|
49
|
+
else
|
50
|
+
cache_key
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
45
55
|
end
|
data/lib/ncore/singleton_base.rb
CHANGED
@@ -4,6 +4,7 @@ module NCore
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
extend Associations
|
7
|
+
include ActiveModel
|
7
8
|
include Attributes
|
8
9
|
include Client
|
9
10
|
include Identity
|
@@ -20,13 +21,13 @@ module NCore
|
|
20
21
|
include Update if types.include? :update
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
+
def resource_path
|
24
25
|
class_name.underscore
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
def
|
29
|
-
self.class.
|
29
|
+
def resource_path
|
30
|
+
self.class.resource_path
|
30
31
|
end
|
31
32
|
|
32
33
|
end
|
data/lib/ncore/util.rb
CHANGED
@@ -38,10 +38,18 @@ module NCore
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def factory(parsed, api_creds)
|
42
|
+
if key = (parsed[:data] || parsed)[:object]
|
43
|
+
discover_class(key, self).new(parsed, api_creds)
|
44
|
+
else
|
45
|
+
new(parsed, api_creds)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
|
42
50
|
private
|
43
51
|
|
44
|
-
def discover_class(key, default_klass=
|
52
|
+
def discover_class(key, default_klass=module_parent::GenericObject)
|
45
53
|
klass_name = key.to_s.camelize.singularize
|
46
54
|
begin
|
47
55
|
"#{module_name}::#{klass_name}".constantize
|
@@ -54,7 +62,7 @@ module NCore
|
|
54
62
|
|
55
63
|
|
56
64
|
def inspect
|
57
|
-
"#<#{self.class}:0x#{self.object_id
|
65
|
+
"#<#{self.class}:0x#{'%016x'%self.object_id} id: #{id.inspect}, attribs: #{@attribs.except(:id).inspect}, metadata: #{metadata.inspect}>"
|
58
66
|
end
|
59
67
|
|
60
68
|
end
|
data/lib/ncore/version.rb
CHANGED
data/ncore.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency '
|
21
|
+
spec.add_dependency 'activemodel', '>= 5.2', '< 6.2'
|
22
22
|
spec.add_dependency 'excon', '~> 0.32'
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
metadata
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Notioneer Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '6.2'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '6.2'
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/ncore/base.rb
|
98
98
|
- lib/ncore/builder.rb
|
99
99
|
- lib/ncore/client.rb
|
100
|
+
- lib/ncore/client_cache.rb
|
100
101
|
- lib/ncore/collection.rb
|
101
102
|
- lib/ncore/configuration.rb
|
102
103
|
- lib/ncore/exceptions.rb
|
@@ -112,10 +113,10 @@ files:
|
|
112
113
|
- lib/ncore/methods/find.rb
|
113
114
|
- lib/ncore/methods/find_single.rb
|
114
115
|
- lib/ncore/methods/update.rb
|
116
|
+
- lib/ncore/methods/update_bulk.rb
|
115
117
|
- lib/ncore/rails/action_controller.rb
|
116
118
|
- lib/ncore/rails/active_model.rb
|
117
119
|
- lib/ncore/rails/log_subscriber.rb
|
118
|
-
- lib/ncore/rails/module_fix.rb
|
119
120
|
- lib/ncore/singleton_base.rb
|
120
121
|
- lib/ncore/util.rb
|
121
122
|
- lib/ncore/version.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# ActiveSupport 6.0 changed :parent -> :module_parent
|
2
|
-
# This eliminates deprecation messages so everything works like v5.2 and prior.
|
3
|
-
|
4
|
-
module NCore
|
5
|
-
module ModuleFix
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
alias :parent :module_parent
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
if Module.respond_to?(:module_parent)
|
16
|
-
Module.include NCore::ModuleFix
|
17
|
-
end
|