Module: ActiveFedora::QueryMethods

Included in:
Relation
Defined in:
lib/active_fedora/relation/query_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#build_where(values) ⇒ Array<String>

Returns list of solr hashes.

Parameters:

  • values (Hash, String)

Returns:

  • (Array<String>)

    list of solr hashes



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/active_fedora/relation/query_methods.rb', line 66

def build_where(values)
  return [] if values.blank?
  case values
  when Hash
    create_query_from_hash(values)
  when String
    ["(#{values})"]
  else
    [values]
  end
end

#create_with_valueObject

:nodoc:



145
146
147
# File 'lib/active_fedora/relation/query_methods.rb', line 145

def create_with_value # :nodoc:
  @values[:create_with] || {}
end

#extending!(*modules, &block) ⇒ Object

:nodoc:



131
132
133
134
135
136
137
138
139
# File 'lib/active_fedora/relation/query_methods.rb', line 131

def extending!(*modules, &block) # :nodoc:
  modules << Module.new(&block) if block
  modules.flatten!

  self.extending_values += modules
  extend(*extending_values) if extending_values.any?

  self
end

#extending_valuesObject



3
4
5
# File 'lib/active_fedora/relation/query_methods.rb', line 3

def extending_values
  @values[:extending] || []
end

#extending_values=(values) ⇒ Object

Raises:

  • (ImmutableRelation)


7
8
9
10
# File 'lib/active_fedora/relation/query_methods.rb', line 7

def extending_values=(values)
  raise ImmutableRelation if @loaded
  @values[:extending] = values
end

#limit(value) ⇒ Object

Limits the number of returned records to the value specified

Examples:

Person.where(name_t: 'Jones').limit(10)
  => [#<Person @id="foo:123" @name='Jones'>, #<Person @id="foo:125" @name='Jones'>, ...]

Parameters:

  • [Integer] (Hash)

    a customizable set of options



101
102
103
# File 'lib/active_fedora/relation/query_methods.rb', line 101

def limit(value)
  spawn.limit!(value)
end

#limit!(value) ⇒ Object



105
106
107
108
# File 'lib/active_fedora/relation/query_methods.rb', line 105

def limit!(value)
  self.limit_value = value
  self
end

#limit_valueObject



30
31
32
# File 'lib/active_fedora/relation/query_methods.rb', line 30

def limit_value
  @values[:limit]
end

#limit_value=(value) ⇒ Object

Raises:

  • (ImmutableRelation)


34
35
36
37
# File 'lib/active_fedora/relation/query_methods.rb', line 34

def limit_value=(value)
  raise ImmutableRelation if @loaded
  @values[:limit] = value
end

#none!Object

:nodoc:



127
128
129
# File 'lib/active_fedora/relation/query_methods.rb', line 127

def none! # :nodoc:
  extending!(NullRelation)
end

#offset(value) ⇒ Object

Start the returned records at an offset position. Useful for paginated results

Examples:

Person.where(name_t: 'Jones').offset(1000)
  => [#<Person @id="foo:123" @name='Jones'>, #<Person @id="foo:125" @name='Jones'>, ...]

Parameters:

  • [Integer] (Hash)

    a customizable set of options



118
119
120
# File 'lib/active_fedora/relation/query_methods.rb', line 118

def offset(value)
  spawn.offset!(value)
end

#offset!(value) ⇒ Object



122
123
124
125
# File 'lib/active_fedora/relation/query_methods.rb', line 122

def offset!(value)
  self.offset_value = value
  self
end

#offset_valueObject



39
40
41
# File 'lib/active_fedora/relation/query_methods.rb', line 39

def offset_value
  @values[:offset]
end

#offset_value=(value) ⇒ Object

Raises:

  • (ImmutableRelation)


43
44
45
46
# File 'lib/active_fedora/relation/query_methods.rb', line 43

def offset_value=(value)
  raise ImmutableRelation if loaded?
  @values[:offset] = value
end

#order(*args) ⇒ Object

Order the returned records by the field and direction provided

Examples:

Person.where(occupation_s: 'Plumber').order('name_t desc', 'color_t asc')
  => [#<Person @id="foo:123" @name='Luigi'>, #<Person @id="foo:125" @name='Mario'>, ...]

Parameters:

  • [Array<String>] (Hash)

    a customizable set of options



85
86
87
# File 'lib/active_fedora/relation/query_methods.rb', line 85

def order(*args)
  spawn.order!(args)
end

#order!(*args) ⇒ Object



89
90
91
92
# File 'lib/active_fedora/relation/query_methods.rb', line 89

def order!(*args)
  self.order_values += args.flatten
  self
end

#order_valuesObject



21
22
23
# File 'lib/active_fedora/relation/query_methods.rb', line 21

def order_values
  @values[:order] || []
end

#order_values=(values) ⇒ Object

Raises:

  • (ImmutableRelation)


25
26
27
28
# File 'lib/active_fedora/relation/query_methods.rb', line 25

def order_values=(values)
  raise ImmutableRelation if @loaded
  @values[:order] = values
end

#selectObject



141
142
143
# File 'lib/active_fedora/relation/query_methods.rb', line 141

def select
  to_a.select { |*block_args| yield(*block_args) }
end

#where(values) ⇒ Object

Limits the returned records to those that match the provided search conditions

Examples:

Person.where(name_t: 'Mario', occupation_s: 'Plumber')
  => [#<Person @id="foo:123" @name='Mario'>, #<Person @id="foo:125" @name='Mario'>, ...]

Parameters:

  • [Hash] (Hash)

    a customizable set of options



55
56
57
# File 'lib/active_fedora/relation/query_methods.rb', line 55

def where(values)
  spawn.where!(values)
end

#where!(values) ⇒ Object



59
60
61
62
# File 'lib/active_fedora/relation/query_methods.rb', line 59

def where!(values)
  self.where_values += build_where(values)
  self
end

#where_valuesObject



12
13
14
# File 'lib/active_fedora/relation/query_methods.rb', line 12

def where_values
  @values[:where] ||= []
end

#where_values=(values) ⇒ Object

Raises:

  • (ImmutableRelation)


16
17
18
19
# File 'lib/active_fedora/relation/query_methods.rb', line 16

def where_values=(values)
  raise ImmutableRelation if @loaded
  @values[:where] = values
end