naranya_ecm-sdk 0.0.15 → 0.0.17
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/naranya_ecm/behaviors/{mediable.rb → media_methods.rb} +1 -1
- data/lib/naranya_ecm/models/category.rb +1 -2
- data/lib/naranya_ecm/models/content.rb +1 -2
- data/lib/naranya_ecm/models/content_version.rb +1 -2
- data/lib/naranya_ecm/models/download_authorization.rb +0 -1
- data/lib/naranya_ecm/models/media_resource.rb +0 -1
- data/lib/naranya_ecm/rest/finder_methods.rb +6 -20
- data/lib/naranya_ecm/rest/persistence.rb +13 -0
- data/lib/naranya_ecm/search/hit.rb +1 -4
- data/lib/naranya_ecm/search/results.rb +0 -17
- data/lib/naranya_ecm-sdk/version.rb +1 -1
- data/lib/naranya_ecm-sdk.rb +4 -24
- metadata +3 -5
- data/lib/naranya_ecm/cache/key.rb +0 -49
- data/lib/naranya_ecm/cache/methods.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb455d97321126300a191b589db3204014254115
|
4
|
+
data.tar.gz: 912aa46d7321a71136aa42568927e0749715a955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2b38a2edaa91ee6782e19843eba65f3809014c176daa18f495058f2210894277300f6ab9e7aacd98c1781a4e2fa616a84242dfc209084b09ee4bfcb5d0a20a
|
7
|
+
data.tar.gz: a4f1363812dc63eceb161577aa450a6dcef942a1badb92043790a24c28bc4a5715920b87398f4bf83d78c3bf7b1475effbfb631e52667d5cae38f6f4549fa673
|
@@ -4,9 +4,8 @@ module NaranyaEcm
|
|
4
4
|
|
5
5
|
include NaranyaEcm.document_module
|
6
6
|
include NaranyaEcm::Behaviors::Timestampable
|
7
|
-
include NaranyaEcm::Cache::Methods
|
8
7
|
include NaranyaEcm::Search::Methods
|
9
|
-
include NaranyaEcm::Behaviors::
|
8
|
+
include NaranyaEcm::Behaviors::MediaMethods
|
10
9
|
|
11
10
|
field :code, type: String
|
12
11
|
validates :code, presence: true
|
@@ -4,9 +4,8 @@ module NaranyaEcm
|
|
4
4
|
|
5
5
|
include NaranyaEcm.document_module
|
6
6
|
include NaranyaEcm::Behaviors::Timestampable
|
7
|
-
include NaranyaEcm::Cache::Methods
|
8
7
|
include NaranyaEcm::Search::Methods
|
9
|
-
include NaranyaEcm::Behaviors::
|
8
|
+
include NaranyaEcm::Behaviors::MediaMethods
|
10
9
|
|
11
10
|
# Type:
|
12
11
|
# Describes the main type of the content - App, Note, etc.
|
@@ -4,8 +4,7 @@ module NaranyaEcm
|
|
4
4
|
|
5
5
|
include NaranyaEcm.document_module
|
6
6
|
include NaranyaEcm::Behaviors::Timestampable
|
7
|
-
include NaranyaEcm::
|
8
|
-
include NaranyaEcm::Behaviors::Mediable
|
7
|
+
include NaranyaEcm::Behaviors::MediaMethods
|
9
8
|
|
10
9
|
# Description (localized):
|
11
10
|
# A localized string that describes an overview of the significant changes
|
@@ -4,32 +4,18 @@ module NaranyaEcm::Rest
|
|
4
4
|
module FinderMethods
|
5
5
|
|
6
6
|
def find(*args)
|
7
|
-
|
8
|
-
|
7
|
+
case args.length
|
8
|
+
when 0
|
9
|
+
raise ResourceNotFound, "Couldn't find #{self.name} without an ID"
|
10
|
+
when 1
|
11
|
+
find_one(args.first)
|
9
12
|
else
|
10
|
-
|
13
|
+
self.where(id: args)
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
17
|
protected
|
15
18
|
|
16
|
-
def find_with_ids(*ids)
|
17
|
-
expects_array = ids.first.kind_of?(Array)
|
18
|
-
return ids.first if expects_array && ids.first.empty?
|
19
|
-
|
20
|
-
ids = ids.flatten.compact.uniq
|
21
|
-
|
22
|
-
case ids.size
|
23
|
-
when 0
|
24
|
-
raise ResourceNotFound, "Couldn't find #{self.name} without an ID"
|
25
|
-
when 1
|
26
|
-
result = find_one(ids.first)
|
27
|
-
expects_array ? [ result ] : result
|
28
|
-
else
|
29
|
-
find_some(ids)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
19
|
def find_one(id)
|
34
20
|
self.load fetch_one(id)
|
35
21
|
end
|
@@ -94,6 +94,7 @@ module NaranyaEcm::Rest
|
|
94
94
|
case response.code
|
95
95
|
when 204
|
96
96
|
self.reload!
|
97
|
+
off_band_changes.clear if off_band_changes.present?
|
97
98
|
true
|
98
99
|
when 422 # Unprocessable Entity
|
99
100
|
self.load_server_errors(response.to_hash)
|
@@ -110,11 +111,23 @@ module NaranyaEcm::Rest
|
|
110
111
|
object_to_create.save
|
111
112
|
object_to_create
|
112
113
|
end
|
114
|
+
|
113
115
|
def create!(attributes={})
|
114
116
|
created_object = create(attributes)
|
115
117
|
raise "ValidationError" unless created_object.persisted?
|
116
118
|
created_object
|
117
119
|
end
|
120
|
+
|
121
|
+
def delete(id, options={})
|
122
|
+
response = HTTParty.delete("#{NaranyaEcm.options[:site]}#{self.path}/#{id}.json")
|
123
|
+
case response.code
|
124
|
+
when 204
|
125
|
+
true
|
126
|
+
else
|
127
|
+
false
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
118
131
|
end
|
119
132
|
|
120
133
|
end
|
@@ -12,17 +12,6 @@ module NaranyaEcm::Search
|
|
12
12
|
# resource:
|
13
13
|
result_elements = search_results.hits.dup
|
14
14
|
|
15
|
-
# Load from cache any matching element caching_key:
|
16
|
-
result_elements.each_index do |index|
|
17
|
-
hit_data = result_elements[index].dup
|
18
|
-
fetched_data = result_elements[index].cache_key.read
|
19
|
-
if fetched_data.present?
|
20
|
-
puts "===== Cache READ: '#{result_elements[index].cache_key}'"
|
21
|
-
result_elements[index] = hit_data.klass.load(fetched_data)
|
22
|
-
result_elements[index].merge_search_hit_data(hit_data)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
15
|
# Load from server all elements yet to materialize:
|
27
16
|
pending_hits = result_elements.select { |e| e.is_a? NaranyaEcm::Search::Hit }
|
28
17
|
pending_hits.map(&:klass).uniq.each do |hit_klass|
|
@@ -36,8 +25,6 @@ module NaranyaEcm::Search
|
|
36
25
|
hit_data = result_elements.detect { |e| e.is_a?(NaranyaEcm::Search::Hit) && e.klass == r.class && e.id == r.id }
|
37
26
|
hit_index = result_elements.find_index hit_data
|
38
27
|
|
39
|
-
puts "===== Cache WRITE: '#{r.cache_key}'"
|
40
|
-
r.cache_key.write fetched_data
|
41
28
|
r.merge_search_hit_data hit_data
|
42
29
|
result_elements[hit_index] = r
|
43
30
|
end
|
@@ -63,10 +50,6 @@ module NaranyaEcm::Search
|
|
63
50
|
]
|
64
51
|
end
|
65
52
|
|
66
|
-
def cache_keys
|
67
|
-
hits.map(&:cache_key)
|
68
|
-
end
|
69
|
-
|
70
53
|
def hits
|
71
54
|
do_search! unless @hits
|
72
55
|
@hits
|
data/lib/naranya_ecm-sdk.rb
CHANGED
@@ -39,13 +39,7 @@ module NaranyaEcm
|
|
39
39
|
extend ActiveSupport::Autoload
|
40
40
|
autoload :Localizable
|
41
41
|
autoload :Timestampable
|
42
|
-
autoload :
|
43
|
-
end
|
44
|
-
|
45
|
-
module Cache
|
46
|
-
extend ActiveSupport::Autoload
|
47
|
-
autoload :Key
|
48
|
-
autoload :Methods
|
42
|
+
autoload :MediaMethods
|
49
43
|
end
|
50
44
|
|
51
45
|
autoload_under 'lifecycles' do
|
@@ -60,8 +54,6 @@ module NaranyaEcm
|
|
60
54
|
autoload :Results
|
61
55
|
end
|
62
56
|
|
63
|
-
autoload :ActiveResourceBasePatch
|
64
|
-
|
65
57
|
include ActiveSupport::Configurable
|
66
58
|
|
67
59
|
DEFAULT_CONFIG = {
|
@@ -78,13 +70,9 @@ module NaranyaEcm
|
|
78
70
|
@root_directory ||= storage.directories.get(options[:storage][:root_directory])
|
79
71
|
end
|
80
72
|
|
81
|
-
def setup
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
def document_module
|
86
|
-
NaranyaEcm::Rest::Model
|
87
|
-
end
|
73
|
+
def setup; yield config; end
|
74
|
+
def document_module; NaranyaEcm::Rest::Model; end
|
75
|
+
def timestamp_module; NaranyaEcm::Behaviors::Timestampable; end
|
88
76
|
|
89
77
|
def options
|
90
78
|
auto_conf unless config.present?
|
@@ -97,11 +85,6 @@ module NaranyaEcm
|
|
97
85
|
.with_indifferent_access
|
98
86
|
setup { |config| yml_config.each { |key, val| config.send "#{key}=".to_sym, val } }
|
99
87
|
end
|
100
|
-
|
101
|
-
def cache
|
102
|
-
auto_conf unless config.present?
|
103
|
-
@cache ||= ActiveSupport::Cache.lookup_store *options[:cache]
|
104
|
-
end
|
105
88
|
|
106
89
|
protected
|
107
90
|
|
@@ -110,9 +93,6 @@ module NaranyaEcm
|
|
110
93
|
if defined?(Rails)
|
111
94
|
yml_path = File.join(Rails.root, 'config', 'naranya_ecm.yml')
|
112
95
|
load_config_from_yml(yml_path, Rails.env)
|
113
|
-
|
114
|
-
# Use the Rails cache:
|
115
|
-
@cache = Rails.cache
|
116
96
|
elsif File.exists?('./naranya_ecm.yml')
|
117
97
|
load_config_from_yml('./naranya_ecm.yml')
|
118
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naranya_ecm-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -169,10 +169,8 @@ files:
|
|
169
169
|
- lib/naranya_ecm-sdk.rb
|
170
170
|
- lib/naranya_ecm-sdk/version.rb
|
171
171
|
- lib/naranya_ecm/behaviors/localizable.rb
|
172
|
-
- lib/naranya_ecm/behaviors/
|
172
|
+
- lib/naranya_ecm/behaviors/media_methods.rb
|
173
173
|
- lib/naranya_ecm/behaviors/timestampable.rb
|
174
|
-
- lib/naranya_ecm/cache/key.rb
|
175
|
-
- lib/naranya_ecm/cache/methods.rb
|
176
174
|
- lib/naranya_ecm/lifecycles/content_lifecycle.rb
|
177
175
|
- lib/naranya_ecm/models/category.rb
|
178
176
|
- lib/naranya_ecm/models/content.rb
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'active_support/hash_with_indifferent_access'
|
2
|
-
|
3
|
-
module NaranyaEcm::Cache
|
4
|
-
class Key < String
|
5
|
-
|
6
|
-
TIMESTAMP_FORMAT = '%Y%m%d%H%M%S'.freeze
|
7
|
-
|
8
|
-
attr_reader :klass, :id, :timestamp
|
9
|
-
|
10
|
-
def initialize(given_class, given_id, given_timestamp = nil)
|
11
|
-
@klass, @id = given_class, given_id
|
12
|
-
|
13
|
-
unless given_timestamp.blank?
|
14
|
-
@timestamp = if given_timestamp.is_a? String
|
15
|
-
given_timestamp.to_datetime
|
16
|
-
elsif given_timestamp.respond_to? :strftime
|
17
|
-
given_timestamp
|
18
|
-
else
|
19
|
-
raise ArgumentError, "Given timestamp is not a Date|Time like object"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
super join_segments
|
24
|
-
end
|
25
|
-
|
26
|
-
def timestamped?
|
27
|
-
timestamp.present?
|
28
|
-
end
|
29
|
-
|
30
|
-
def exist?
|
31
|
-
NaranyaEcm.cache.exist? self
|
32
|
-
end
|
33
|
-
|
34
|
-
def read
|
35
|
-
NaranyaEcm.cache.read self
|
36
|
-
end
|
37
|
-
|
38
|
-
def write(data)
|
39
|
-
NaranyaEcm.cache.write self, data
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
def join_segments
|
44
|
-
key = "#{klass.name.tableize}/#{id}"
|
45
|
-
timestamped? ? "#{key}-#{timestamp.strftime(TIMESTAMP_FORMAT)}" : key
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module NaranyaEcm::Cache
|
4
|
-
module Methods
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
class << self
|
10
|
-
alias_method_chain :find, :caching
|
11
|
-
alias_method_chain :find_one, :caching
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def cache_key
|
16
|
-
self.new_resource? ? nil : self.class.cache_key_for(self.id, self.updated_at)
|
17
|
-
end
|
18
|
-
|
19
|
-
module ClassMethods
|
20
|
-
|
21
|
-
def cache
|
22
|
-
NaranyaEcm.cache
|
23
|
-
end
|
24
|
-
|
25
|
-
def cache_key_for(id, timestamp=nil)
|
26
|
-
Key.new self, id, timestamp
|
27
|
-
end
|
28
|
-
|
29
|
-
def find_with_caching(id, cache_options = {})
|
30
|
-
find_one_with_caching(id, cache_options)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
# Find a single resource from the default URL
|
36
|
-
def find_one_with_caching(id, cache_options = {})
|
37
|
-
fetched_data = nil
|
38
|
-
missed = true
|
39
|
-
|
40
|
-
# Ver primero si lo podemos obtener del cache:
|
41
|
-
cache_timestamp = cache_options.delete(:timestamp)
|
42
|
-
if cache_timestamp.present?
|
43
|
-
# Try to load the record from cache:
|
44
|
-
cache_key = cache_key_for(id, cache_timestamp)
|
45
|
-
missed = (fetched_data = cache_key.read).nil?
|
46
|
-
puts "===== CACHE #{(missed ? 'MISS: ' : 'HIT: ')} '#{cache_key}'"
|
47
|
-
end
|
48
|
-
|
49
|
-
# Si no lo obtuvimos del caché, traer uno del server:
|
50
|
-
|
51
|
-
unless fetched_data.present?
|
52
|
-
fetched_data = fetch_one(id)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Inicializar el recurso con los datos obtenidos:
|
56
|
-
resource = self.load fetched_data
|
57
|
-
|
58
|
-
# Write unless data exists:
|
59
|
-
if missed
|
60
|
-
puts "===== Cache WRITE: '#{resource.cache_key}'"
|
61
|
-
cache.write(resource.cache_key, fetched_data)
|
62
|
-
end
|
63
|
-
|
64
|
-
resource
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|