cmis-ruby 0.3.4 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c5f9d4df93396fe4735ee09d4d97db95c48df45
4
- data.tar.gz: 8938574723b4af67c631415610fcf4f71c4a1987
3
+ metadata.gz: dc97717108219ab5cccfdc7ebbcebdae3e49459f
4
+ data.tar.gz: 7f6f2d04fdf02fdd4e903024f90cf208a3b0fbc0
5
5
  SHA512:
6
- metadata.gz: db9eec57e4879bcd1ef91cac2f717754e3ac376995cc11fe4f4c3af91dba94b3f777af086447e785eeb4d3887e3ae0247daea4be8f0fbd44e45737b3f42db71a
7
- data.tar.gz: d8e06feb0c924488abe759cf1b7525f7d3e1ee33dde2e77e5bee374164d4542bda06b057705dcc974eb806a3f39998db52e0a640a071bdbf3d4ca59ce19f8f2f
6
+ metadata.gz: b85d9befb1c62a5f7077040094c7100d4dd14d1f09712d831b5e8f2362f46186923e03b236c7bfb3330c5c2795e26a17b73cfb34faa97b55da60d8756d6fb07b
7
+ data.tar.gz: 8f82470e491ee50316dc856f5ef454749a5118ae542991f89ddbdee16e3b4726681ff892c3016f3b099e44e3c271d7c5b49e77a0d49e3b1b703fe720d07851b5
@@ -1,6 +1,16 @@
1
- require 'cmis/core_ext/array'
2
- require 'cmis/core_ext/hash'
1
+ # ruby
2
+ require 'bigdecimal'
3
+ require 'json'
3
4
 
5
+ # core extensions
6
+ require 'active_support/core_ext'
7
+ require 'core_ext'
8
+
9
+ # HTTP
10
+ require 'typhoeus'
11
+ require 'net/http/post/multipart'
12
+
13
+ # cmis-ruby
4
14
  require 'cmis/connection'
5
15
  require 'cmis/exceptions'
6
16
  require 'cmis/server'
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/hash/slice'
2
-
3
1
  module CMIS
4
2
  class Children
5
3
  # Options: from, page_size
@@ -66,6 +64,8 @@ module CMIS
66
64
  @max_items = @options['page_size'] || 10
67
65
  @skip_count = @options['from'] || 0
68
66
  @order_by = @options['order_by']
67
+ @filter = @options['filter']
68
+ @include_relationships = @options['include_relationships']
69
69
  @has_next = true
70
70
 
71
71
  @opts = @options.slice('query', 'headers')
@@ -80,18 +80,44 @@ module CMIS
80
80
  end
81
81
 
82
82
  def do_get_children
83
- result = @folder.connection.execute!({ cmisselector: 'children',
84
- repositoryId: @folder.repository.id,
85
- objectId: @folder.cmis_object_id,
86
- maxItems: @max_items,
87
- skipCount: @skip_count,
88
- orderBy: @order_by }, @opts)
89
-
90
- results = result['objects'].map do |r|
91
- ObjectFactory.create(r['object'], @folder.repository)
83
+ repository = @folder.repository
84
+ result = repository.connection.execute!({ cmisselector: 'children',
85
+ repositoryId: @folder.repository.id,
86
+ objectId: @folder.cmis_object_id,
87
+ maxItems: @max_items,
88
+ skipCount: @skip_count,
89
+ orderBy: @order_by,
90
+ includeRelationships: @include_relationships,
91
+ filter: @filter}, @opts)
92
+
93
+ results = result['objects'].map { |o| build_object_with_relationships(o) }
94
+ QueryResult.new(results, result['numItems'], result['hasMoreItems'])
95
+ end
96
+
97
+ def build_object_with_relationships(json)
98
+ object = ObjectFactory.create(json['object'], @folder.repository)
99
+
100
+ # If relationships are included, override the object method...
101
+ if relationships = build_relationships(json)
102
+ metaclass = class << object; self; end
103
+ metaclass.send(:define_method, :relationships) do
104
+ # ...and make the Array respond to `each_relationship`
105
+ def relationships.each_relationship(args, &blck)
106
+ each(&blck)
107
+ end
108
+ relationships
109
+ end
92
110
  end
93
111
 
94
- QueryResult.new(results, result['numItems'], result['hasMoreItems'])
112
+ object
113
+ end
114
+
115
+ def build_relationships(json)
116
+ if json['object']['relationships']
117
+ json['object']['relationships'].map do |r|
118
+ ObjectFactory.create(r, @folder.repository)
119
+ end
120
+ end
95
121
  end
96
122
  end
97
123
  end
@@ -1,8 +1,3 @@
1
- require 'active_support'
2
- require 'json'
3
- require 'typhoeus'
4
- require 'net/http/post/multipart'
5
-
6
1
  module CMIS
7
2
  class Connection
8
3
  def initialize(service_url, username, password, headers)
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext'
2
-
3
1
  module CMIS
4
2
  module Helpers
5
3
  def initialize_properties(raw)
@@ -24,6 +22,22 @@ module CMIS
24
22
  end
25
23
  end
26
24
 
25
+ def self.respond_to?(name, include_private = false)
26
+ if @properties.has_key?(name.to_s)
27
+ true
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def method_missing(name, *args, &block)
34
+ if @properties.has_key?(name.to_s)
35
+ @properties[name.to_s]
36
+ else
37
+ super
38
+ end
39
+ end
40
+
27
41
  private
28
42
 
29
43
  def method_name(property_name)
@@ -2,7 +2,6 @@ module CMIS
2
2
  class Object
3
3
  include Helpers
4
4
 
5
- attr_reader :connection
6
5
  attr_reader :repository
7
6
  attr_accessor :properties
8
7
 
@@ -14,7 +13,6 @@ module CMIS
14
13
  cmis:lastModificationDate cmis:changeToken )
15
14
 
16
15
  @repository = repository
17
- @connection = repository.connection
18
16
  end
19
17
 
20
18
  def object_type(opts = {})
@@ -109,5 +107,11 @@ module CMIS
109
107
  def detached?
110
108
  cmis_object_id.nil?
111
109
  end
110
+
111
+ private
112
+
113
+ def connection
114
+ repository.connection if repository
115
+ end
112
116
  end
113
117
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/string/inflections'
2
-
3
1
  module CMIS
4
2
  class PropertyDefinition
5
3
  def initialize(hash = {})
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/hash/slice'
2
-
3
1
  module CMIS
4
2
  class Query
5
3
  # Options: from, page_size
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/hash/slice'
2
-
3
1
  module CMIS
4
2
  class Relationships
5
3
  # Options: from, page_size
@@ -82,14 +80,15 @@ module CMIS
82
80
  end
83
81
 
84
82
  def do_get_relationships
85
- result = @object.connection.execute!({ cmisselector: 'relationships',
86
- repositoryId: @object.repository.id,
87
- objectId: @object.cmis_object_id,
88
- maxItems: @max_items,
89
- skipCount: @skip_count,
90
- relationshipDirection: @direction,
91
- includeSubRelationshipTypes: @include_subtypes,
92
- typeId: @type_id }, @opts)
83
+ connection = @object.repository.connection
84
+ result = connection.execute!({ cmisselector: 'relationships',
85
+ repositoryId: @object.repository.id,
86
+ objectId: @object.cmis_object_id,
87
+ maxItems: @max_items,
88
+ skipCount: @skip_count,
89
+ relationshipDirection: @direction,
90
+ includeSubRelationshipTypes: @include_subtypes,
91
+ typeId: @type_id }, @opts)
93
92
 
94
93
  results = result['objects'].map do |r|
95
94
  ObjectFactory.create(r, @object.repository)
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/hash/indifferent_access'
2
-
3
1
  module CMIS
4
2
  class Server
5
3
  attr_reader :connection
@@ -1,14 +1,9 @@
1
- require 'active_support/core_ext/string/inflections'
2
-
3
1
  module CMIS
4
2
  class Type
5
- attr_accessor :connection
6
3
  attr_accessor :repository
7
4
 
8
5
  def initialize(hash, repository)
9
6
  @repository = repository
10
- @connection = repository.connection if repository
11
-
12
7
  @hash = hash.with_indifferent_access
13
8
 
14
9
  properties = %w( id localName localNamespace queryName displayName baseId
@@ -100,5 +95,11 @@ module CMIS
100
95
  def to_hash
101
96
  @hash
102
97
  end
98
+
99
+ private
100
+
101
+ def connection
102
+ repository.connection if repository
103
+ end
103
104
  end
104
105
  end
@@ -1,3 +1,3 @@
1
1
  module CMIS
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
@@ -0,0 +1,3 @@
1
+ Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].each do |path|
2
+ require path
3
+ end
@@ -0,0 +1 @@
1
+ require 'core_ext/array/indifferent_access'
@@ -0,0 +1 @@
1
+ require 'core_ext/hash/compact'
@@ -0,0 +1,22 @@
1
+ # Added in active_support 4.1
2
+
3
+ class Hash
4
+ # Returns a hash with non +nil+ values.
5
+ #
6
+ # hash = { a: true, b: false, c: nil}
7
+ # hash.compact # => { a: true, b: false}
8
+ # hash # => { a: true, b: false, c: nil}
9
+ # { c: nil }.compact # => {}
10
+ def compact
11
+ self.select { |_, value| !value.nil? }
12
+ end
13
+
14
+ # Replaces current hash with non +nil+ values.
15
+ #
16
+ # hash = { a: true, b: false, c: nil}
17
+ # hash.compact! # => { a: true, b: false}
18
+ # hash # => { a: true, b: false}
19
+ def compact!
20
+ self.reject! { |_, value| value.nil? }
21
+ end
22
+ end
data/readme.md CHANGED
@@ -10,7 +10,7 @@ Running the tests requires a running CMIS server.
10
10
 
11
11
  ## TODO
12
12
 
13
- * cleanup Connection class
13
+ * use Faraday for HTTP
14
14
  * facilitate copy between servers (make a flow)
15
15
  * caching
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmis-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Geerts
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-03 00:00:00.000000000 Z
12
+ date: 2014-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -69,8 +69,6 @@ files:
69
69
  - lib/cmis-ruby.rb
70
70
  - lib/cmis/children.rb
71
71
  - lib/cmis/connection.rb
72
- - lib/cmis/core_ext/array.rb
73
- - lib/cmis/core_ext/hash.rb
74
72
  - lib/cmis/document.rb
75
73
  - lib/cmis/exceptions.rb
76
74
  - lib/cmis/folder.rb
@@ -88,6 +86,11 @@ files:
88
86
  - lib/cmis/server.rb
89
87
  - lib/cmis/type.rb
90
88
  - lib/cmis/version.rb
89
+ - lib/core_ext.rb
90
+ - lib/core_ext/array.rb
91
+ - lib/core_ext/array/indifferent_access.rb
92
+ - lib/core_ext/hash.rb
93
+ - lib/core_ext/hash/compact.rb
91
94
  - readme.md
92
95
  - spec/document_spec.rb
93
96
  - spec/folder_spec.rb
@@ -1,5 +0,0 @@
1
- class Hash
2
- def compact
3
- delete_if { |_, v| v.nil? }
4
- end
5
- end