naranya_ecm-sdk 0.0.14 → 0.0.15

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/naranya_ecm/behaviors/localizable.rb +27 -31
  3. data/lib/naranya_ecm/behaviors/mediable.rb +25 -0
  4. data/lib/naranya_ecm/behaviors/timestampable.rb +18 -15
  5. data/lib/naranya_ecm/cache/key.rb +32 -56
  6. data/lib/naranya_ecm/cache/methods.rb +50 -63
  7. data/lib/naranya_ecm/lifecycles/content_lifecycle.rb +39 -16
  8. data/lib/naranya_ecm/models/category.rb +11 -30
  9. data/lib/naranya_ecm/models/content.rb +73 -73
  10. data/lib/naranya_ecm/models/content_version.rb +50 -29
  11. data/lib/naranya_ecm/models/download_authorization.rb +22 -26
  12. data/lib/naranya_ecm/models/media_resource.rb +49 -15
  13. data/lib/naranya_ecm/rest/associations.rb +156 -0
  14. data/lib/naranya_ecm/rest/client.rb +4 -0
  15. data/lib/naranya_ecm/rest/errors.rb +53 -0
  16. data/lib/naranya_ecm/rest/finder_methods.rb +50 -0
  17. data/lib/naranya_ecm/rest/model.rb +215 -0
  18. data/lib/naranya_ecm/rest/persistence.rb +122 -0
  19. data/lib/naranya_ecm/rest/relation.rb +54 -0
  20. data/lib/naranya_ecm/search/hit.rb +19 -14
  21. data/lib/naranya_ecm/search/methods.rb +18 -20
  22. data/lib/naranya_ecm/search/query.rb +229 -230
  23. data/lib/naranya_ecm/search/results.rb +136 -139
  24. data/lib/naranya_ecm-sdk/version.rb +1 -1
  25. data/lib/naranya_ecm-sdk.rb +54 -13
  26. data/naranya_ecm-sdk.gemspec +1 -1
  27. data/spec/models/category_spec.rb +7 -2
  28. data/spec/models/content_spec.rb +11 -2
  29. data/spec/models/media_spec.rb +1 -1
  30. data/spec/spec_helper.rb +1 -1
  31. data/spec/support/naranya_ecms_shared_specs.rb +0 -12
  32. metadata +15 -19
  33. data/lib/naranya_ecm/behaviors/resourceable.rb +0 -22
  34. data/lib/naranya_ecm/behaviors.rb +0 -10
  35. data/lib/naranya_ecm/cache.rb +0 -9
  36. data/lib/naranya_ecm/has_many_patch.rb +0 -105
  37. data/lib/naranya_ecm/lifecycles/lifecycleable.rb +0 -43
  38. data/lib/naranya_ecm/lifecycles/version_lifecycle.rb +0 -75
  39. data/lib/naranya_ecm/lifecycles.rb +0 -10
  40. data/lib/naranya_ecm/models/embedded_hash.rb +0 -10
  41. data/lib/naranya_ecm/models/embedded_localized_hash.rb +0 -38
  42. data/lib/naranya_ecm/models/lifecycle.rb +0 -34
  43. data/lib/naranya_ecm/models.rb +0 -15
  44. data/lib/naranya_ecm/search.rb +0 -14
@@ -1,105 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- module NaranyaEcm
4
-
5
- # Aplica de manera dinámica el patch visto en:
6
- # https://github.com/kenips/activeresource/commit/720c06a5a4a2d1cfd7319accb649b7aececa1ca2
7
- module HasManyPatch
8
-
9
- extend ActiveSupport::Concern
10
-
11
- included do
12
- class << self
13
- alias_method_chain :element_path, :has_many_patch
14
-
15
- unless method_defined? :element_base_path
16
- alias_method :element_base_path, :element_base_path_with_has_many_patch
17
- end
18
-
19
- alias_method_chain :defines_has_many_finder_method, :has_many_patch
20
- end
21
- end
22
-
23
- def element_base_path(options = nil)
24
- self.class.element_base_path(to_param, options || prefix_options)
25
- end
26
-
27
- module ClassMethods
28
-
29
- # Gets the element path for the given ID in +id+. If the +query_options+ parameter is omitted, Rails
30
- # will split from the \prefix options.
31
- #
32
- # ==== Options
33
- # +prefix_options+ - A \hash to add a \prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
34
- # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
35
- #
36
- # +query_options+ - A \hash to add items to the query string for the request.
37
- #
38
- # ==== Examples
39
- # Post.element_path(1)
40
- # # => /posts/1.json
41
- #
42
- # class Comment < ActiveResource::Base
43
- # self.site = "https://37s.sunrise.com/posts/:post_id"
44
- # end
45
- #
46
- # Comment.element_path(1, :post_id => 5)
47
- # # => /posts/5/comments/1.json
48
- #
49
- # Comment.element_path(1, :post_id => 5, :active => 1)
50
- # # => /posts/5/comments/1.json?active=1
51
- #
52
- # Comment.element_path(1, {:post_id => 5}, {:active => 1})
53
- # # => /posts/5/comments/1.json?active=1
54
- #
55
- def element_path_with_has_many_patch(id, prefix_options = {}, query_options = nil)
56
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
57
- "#{element_base_path(id, prefix_options)}#{format_extension}#{query_string(query_options)}"
58
- end
59
-
60
- # Gets the element base path for the given ID in +id+. This will never return a format extension or params,
61
- # it is useful for building prefix paths. See <tt>element_path</tt> if you need format extensions and params.
62
- #
63
- # ==== Options
64
- # +prefix_options+ - A \hash to add a \prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
65
- # would yield a URL like <tt>/accounts/19</tt>).
66
- #
67
- # ==== Examples
68
- # Class Post < ActiveResource::Base
69
- # self.site = "https://37s.sunrise.com/api"
70
- # end
71
- #
72
- # Post.element_base_path(1)
73
- # # => /api/posts/1
74
- #
75
- # class Comment < ActiveResource::Base
76
- # self.site = "https://37s.sunrise.com/api/posts/:post_id"
77
- # end
78
- #
79
- # Comment.element_base_path(1, :post_id => 5)
80
- # # => /api/posts/5/comments/1
81
- #
82
- def element_base_path_with_has_many_patch(id, prefix_options = {})
83
- check_prefix_options(prefix_options)
84
- "#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}"
85
- end
86
-
87
- # Patches the definition of the has_many finder method
88
- def defines_has_many_finder_method_with_has_many_patch(method_name, association_model)
89
- ivar_name = :"@#{method_name}"
90
-
91
- define_method(method_name) do
92
- if instance_variable_defined?(ivar_name)
93
- instance_variable_get(ivar_name)
94
- elsif attributes.include?(method_name)
95
- attributes[method_name]
96
- else
97
- instance_variable_set(ivar_name, association_model.find(:all, :from => "#{element_base_path}/#{method_name}.#{association_model.format.extension}"))
98
- end
99
- end
100
- end
101
-
102
- end
103
-
104
- end
105
- end
@@ -1,43 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- module NaranyaEcm
4
- module Lifecycles
5
-
6
- module Lifecycleable
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- attr_accessor :lifecycle_name, :lifecycle_state
11
- end
12
-
13
- def lifecycle_name
14
- @attributes['lifecycle_name'] ||= NaranyaEcm::Lifecycle.new(@attributes['lifecycle_name'])
15
- end
16
-
17
- def lifecycle_name=(given_lifecycle_name)
18
- @attributes['lifecycle_name'] = NaranyaEcm::Lifecycle.new(given_lifecycle_name)
19
- @lifecycle_name = @attributes['lifecycle_name']
20
- end
21
-
22
- def lifecycle_state
23
- @attributes['lifecycle_state']
24
- end
25
-
26
- def lifecycle_state=(given_lifecycle_state)
27
- @attributes['lifecycle_state']= given_lifecycle_state.to_s
28
- end
29
-
30
- def method_missing(method_name, *args, &block)
31
- if method_name.to_s =~ /^(\w+)_lifecycle\?$/
32
- self.lifecycle_name.is_lifecycle?($1)
33
- else
34
- super # You *must* call super if you don't handle the
35
- # method, otherwise you'll mess up Ruby's method
36
- # lookup.
37
- end
38
- end
39
-
40
- end
41
-
42
- end
43
- end
@@ -1,75 +0,0 @@
1
- require 'active_support/concern'
2
- require 'state_machine'
3
-
4
- module NaranyaEcm
5
- module Lifecycles
6
-
7
- module VersionLifecycle
8
- extend ActiveSupport::Concern
9
-
10
- included do
11
-
12
- include NaranyaEcm::Lifecycles::Lifecycleable
13
-
14
- ##################################################################
15
- # StateMachine:
16
- state_machine :lifecycle_state, initial: :draft do
17
-
18
- # # Not working...
19
- # #after_transition :on => :publish, :do => :supercede_the_content_current_version_if_published
20
-
21
- # #########################################
22
- # # Eventos:
23
-
24
- # event :request_validation do
25
- # # Iniciar la transición de :draft a :awaiting_validation,
26
- # # si el lifecycle es sencillo:
27
- # transition :draft => :awaiting_validation, :unless => :simple_lifecycle?
28
- # end
29
-
30
- # event :validate do
31
- # # Iniciar la transición de :awaiting_validation a :validated:
32
- # transition :awaiting_validation => :validated
33
- # end
34
-
35
- # event :reject do
36
- # # Iniciar la transición de :awaiting_validation a :rejected:
37
- # transition :awaiting_validation => :rejected
38
- # end
39
-
40
- # event :publish do
41
- # # Iniciar la transición de :draft a :published,
42
- # # si el lifecycle es sencillo:
43
- # transition :draft => :published, :if => :simple_lifecycle?
44
- # transition :validated => :published
45
- # end
46
-
47
- # event :supersede do
48
- # # Iniciar la transición de :published a :superseded:
49
- # transition :published => :superseded
50
- # end
51
-
52
- # event :deactivate do
53
- # # Iniciar la transición de :published a :deactivated:
54
- # transition :published => :deactivated
55
- # end
56
-
57
- state :awaiting_validation
58
-
59
- state :rejected
60
-
61
- state :validated
62
-
63
- state :published
64
-
65
- state :superseded
66
-
67
- state :deactivated
68
-
69
- end
70
- end
71
-
72
- end
73
-
74
- end
75
- end
@@ -1,10 +0,0 @@
1
- require 'active_support/dependencies/autoload'
2
-
3
- module NaranyaEcm
4
- module Lifecycles
5
- extend ActiveSupport::Autoload
6
- autoload :Lifecycleable
7
- autoload :ContentLifecycle
8
- autoload :VersionLifecycle
9
- end
10
- end
@@ -1,10 +0,0 @@
1
-
2
- module NaranyaEcm::Models
3
- class EmbeddedHash < HashWithIndifferentAccess
4
- def initialize(*args)
5
- super()
6
- given_attrs = args.shift
7
- given_attrs.each { |k,v| self[k] = v } unless given_attrs.nil?
8
- end
9
- end
10
- end
@@ -1,38 +0,0 @@
1
-
2
- module NaranyaEcm::Models
3
- class EmbeddedLocalizedHash < EmbeddedHash
4
-
5
- alias_method :locales, :keys
6
- alias_method :available_locales, :locales
7
-
8
- def lookup
9
- locale = ::I18n.locale
10
- if ::I18n.respond_to?(:fallbacks)
11
- lookup_result = self[::I18n.fallbacks[locale].map(&:to_s).find{ |loc| self.has_key?(loc) }]
12
- else
13
- lookup_result = self[locale.to_s]
14
- end
15
- lookup_result || self.present? ? self.first[1] : nil
16
- end
17
-
18
- def method_missing(method_name, *args, &block)
19
- if method_name == self.class.aliased_lookup_name
20
- # El nombre del método debe ser un alias de lookup.
21
- # Agregar el alias:
22
- self.class.send :alias_method, self.class.aliased_lookup_name, :lookup
23
- # llamar el método de lookup. La siguiente ocación no caerá aqui:
24
- lookup
25
- else
26
- super # You *must* call super if you don't handle the
27
- # method, otherwise you'll mess up Ruby's method
28
- # lookup.
29
- end
30
- end
31
-
32
- class << self
33
- def aliased_lookup_name
34
- @lookup_alias ||= self.name.demodulize[0..-("Translations".length+1)].underscore.to_sym
35
- end
36
- end
37
- end
38
- end
@@ -1,34 +0,0 @@
1
-
2
- module NaranyaEcm::Models
3
-
4
- # Value Object de Lifecycle de documentos / versiones / media / etc.
5
- class Lifecycle < String
6
- include Comparable
7
-
8
- KNOWN_LIFECYCLES = %w(simple validatable)
9
- .map { |m| m.to_sym }
10
- .freeze
11
-
12
- def is_lifecycle?(given_lifecycle)
13
- given_lifecycle.to_s == self
14
- end
15
-
16
- KNOWN_LIFECYCLES.each do |lifecycle_name|
17
- define_method("is_#{lifecycle_name}?") do
18
- is_lifecycle?(lifecycle_name)
19
- end
20
- end
21
-
22
- def method_missing(method_name, *args, &block)
23
- if method_name.to_s =~ /^is_(\w+)\?$/
24
- is_lifecycle?($1)
25
- else
26
- super # You *must* call super if you don't handle the
27
- # method, otherwise you'll mess up Ruby's method
28
- # lookup.
29
- end
30
- end
31
-
32
- end
33
-
34
- end
@@ -1,15 +0,0 @@
1
- require 'active_support/dependencies/autoload'
2
-
3
- module NaranyaEcm
4
- module Models
5
- extend ActiveSupport::Autoload
6
- autoload :Category
7
- autoload :Content
8
- autoload :ContentVersion
9
- autoload :Lifecycle
10
- autoload :DownloadAuthorization
11
- autoload :MediaResource
12
- autoload :EmbeddedHash
13
- autoload :EmbeddedLocalizedHash
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- require 'active_support/dependencies/autoload'
2
-
3
- module NaranyaEcm
4
- module Search
5
-
6
- extend ActiveSupport::Autoload
7
-
8
- autoload :Hit
9
- autoload :Methods
10
- autoload :Query
11
- autoload :Results
12
-
13
- end
14
- end