active-fedora 7.0.3 → 7.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3901cc3cf493df96f7126b87a79a397cdf8a6e89
4
- data.tar.gz: b9135e235d4748bdf1d0fdaa10674ee35bc5bf41
3
+ metadata.gz: 9e75a0408125225a3ef0ae91e7de53d0560d10a6
4
+ data.tar.gz: 56de97df291d2239583e16c500f99ab26df355af
5
5
  SHA512:
6
- metadata.gz: 23029a9d98b89725f27191a61ca3418e9e94e61553679ced67d660f3e7a8de916e7f68e7ac4f0173cf9e67463329f4abf4cdb9588a71f0b4cc0bf8b87af3a1c9
7
- data.tar.gz: a6d0708788d1ef3f6781f077b0aba9dab06adcb2a4144f9b4df09e63ff2c4e501ec1ad1986498e68fe49903033b4d2acf2775c76ab32429d26be9abe8e05051b
6
+ metadata.gz: 3df7b3a6fd7aab417e3c10d589e0fc06bba37cbee05400ea9d4983314cdaf191239b54ed9202a38f75ce1d1e5dbf1b03ec74b60a0ded41856ac3f68c140fdf31
7
+ data.tar.gz: d43e9f106e4b6f2c59eb12e36fe62c03d0e1b0040f60af2d373247aa25143499c1ce163ae39b75b3de353301a10abcc6535a01ad9e26c2085c0726dff4bd4c9e
@@ -130,6 +130,14 @@ module ActiveFedora
130
130
  end
131
131
  end
132
132
 
133
+ def any?
134
+ if block_given?
135
+ load_target.any? { |*block_args| yield(*block_args) }
136
+ else
137
+ !empty?
138
+ end
139
+ end
140
+
133
141
  def to_ary
134
142
  load_target.dup
135
143
  end
@@ -3,7 +3,7 @@ module ActiveFedora
3
3
  extend Deprecation
4
4
  self.deprecation_horizon = 'active-fedora version 8.0.0'
5
5
 
6
- delegate :find, :first, :exists?, :where, :limit, :order, :delete_all,
6
+ delegate :find, :first, :exists?, :where, :limit, :offset, :order, :delete_all,
7
7
  :destroy_all, :count, :last, :find_with_conditions, :find_in_batches, :find_each, :to=>:all
8
8
 
9
9
  def self.extended(base)
@@ -54,6 +54,7 @@ module ActiveFedora
54
54
  return @records if loaded?
55
55
  args = @klass == ActiveFedora::Base ? {:cast=>true} : {}
56
56
  args[:rows] = limit_value if limit_value
57
+ args[:start] = offset_value if offset_value
57
58
  args[:sort] = order_values if order_values
58
59
 
59
60
  @records = to_enum(:find_each, where_values, args).to_a
@@ -121,7 +122,7 @@ module ActiveFedora
121
122
 
122
123
  private
123
124
 
124
- VALID_FIND_OPTIONS = [:order, :limit, :conditions, :cast]
125
+ VALID_FIND_OPTIONS = [:order, :limit, :start, :conditions, :cast]
125
126
 
126
127
  def apply_finder_options(options)
127
128
  relation = clone
@@ -131,7 +132,7 @@ module ActiveFedora
131
132
  finders = options.dup
132
133
  finders.delete_if { |key, value| value.nil? && key != :limit }
133
134
 
134
- ([:order,:limit] & finders.keys).each do |finder|
135
+ ([:order,:limit,:start] & finders.keys).each do |finder|
135
136
  relation = relation.send(finder, finders[finder])
136
137
  end
137
138
 
@@ -37,6 +37,15 @@ module ActiveFedora
37
37
  @values[:limit] = value
38
38
  end
39
39
 
40
+ def offset_value
41
+ @values[:offset]
42
+ end
43
+
44
+ def offset_value=(value)
45
+ raise ImmutableRelation if loaded?
46
+ @values[:offset] = value
47
+ end
48
+
40
49
  # Limits the returned records to those that match the provided search conditions
41
50
  #
42
51
  # @option [Hash] opts a hash of solr conditions
@@ -97,6 +106,23 @@ module ActiveFedora
97
106
  self
98
107
  end
99
108
 
109
+ # Start the returned records at an offset position.
110
+ # Useful for paginated results
111
+ #
112
+ # @option [Integer] value the number of records offset
113
+ #
114
+ # @example
115
+ # Person.where(name_t: 'Jones').offset(1000)
116
+ # => [#<Person @id="foo:123" @name='Jones'>, #<Person @id="foo:125" @name='Jones'>, ...]
117
+ def offset(value)
118
+ spawn.offset!(value)
119
+ end
120
+
121
+ def offset!(value)
122
+ self.offset_value = value
123
+ self
124
+ end
125
+
100
126
  def none! # :nodoc:
101
127
  extending!(NullRelation)
102
128
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "7.0.3"
2
+ VERSION = "7.0.4"
3
3
  end
@@ -21,6 +21,7 @@ describe "Collection members" do
21
21
  expect(library.books).not_to be_loaded
22
22
  expect(library.books.size).to eq(0)
23
23
  expect(library.books).to be_loaded
24
+ expect(library.books.any?).to be_false
24
25
  end
25
26
  end
26
27
  end
@@ -50,6 +51,11 @@ describe "Collection members" do
50
51
  it "should load from solr with options" do
51
52
  expect(library.books.load_from_solr(rows: 0).size).to eq(0)
52
53
  end
54
+ it "should respond to #any?" do
55
+ expect(library.books.any?).to be_true
56
+ expect(library.books.any? {|book| book.library == nil}).to be_false
57
+ expect(library.books.any? {|book| book.library == library}).to be_true
58
+ end
53
59
  end
54
60
  end
55
61
 
@@ -76,6 +76,9 @@ describe "scoped queries" do
76
76
  it "should limit" do
77
77
  ModelIntegrationSpec::Basic.limit(1).should == [test_instance1]
78
78
  end
79
+ it "should offset" do
80
+ ModelIntegrationSpec::Basic.offset(1).should == [test_instance2, test_instance3]
81
+ end
79
82
 
80
83
  it "should chain queries" do
81
84
  ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc').limit(1).should == [test_instance2]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.3
4
+ version: 7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-13 00:00:00.000000000 Z
13
+ date: 2014-06-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr