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) ⇒ Object


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

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:


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

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

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

:nodoc:


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

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


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

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

#extending_values=(values) ⇒ Object

Raises:

  • (ImmutableRelation)

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

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


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

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

#limit!(value) ⇒ Object


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

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

#limit_valueObject


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

def limit_value
  @values[:limit]
end

#limit_value=(value) ⇒ Object

Raises:

  • (ImmutableRelation)

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

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

#none!Object

:nodoc:


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

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


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

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

#offset!(value) ⇒ Object


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

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

#offset_valueObject


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

def offset_value
  @values[:offset]
end

#offset_value=(value) ⇒ Object

Raises:

  • (ImmutableRelation)

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

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


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

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

#order!(*args) ⇒ Object


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

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

#order_valuesObject


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

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

#order_values=(values) ⇒ Object

Raises:

  • (ImmutableRelation)

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

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

#selectObject


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

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


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

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

#where!(values) ⇒ Object


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

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

#where_valuesObject


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

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

#where_values=(values) ⇒ Object

Raises:

  • (ImmutableRelation)

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

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