Class: CMIS::Utils::QueryStatementBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis/utils.rb

Instance Method Summary collapse

Constructor Details

#initialize(type_id, properties, queried_properties) ⇒ QueryStatementBuilder

Returns a new instance of QueryStatementBuilder


10
11
12
13
14
15
# File 'lib/cmis/utils.rb', line 10

def initialize(type_id, properties, queried_properties)
  @type_id = type_id
  @properties = properties
  @queried_properties = Array(queried_properties).join(', ')
  @queried_properties = '*' if @queried_properties.empty?
end

Instance Method Details

#buildObject


17
18
19
20
21
22
23
24
25
26
# File 'lib/cmis/utils.rb', line 17

def build
  @type_id = Array(@type_id)
  statement = "select #{@queried_properties} from #{@type_id[0]}"
  if @type_id[1]
    statement << " join #{@type_id[1]} as X on cmis:objectId = X.cmis:objectId"
  end
  clause = @properties.map { |k, v| build_predicate(k, v) }.join(' and ')
  statement << " where #{clause}" unless clause.empty?
  statement
end