martinemde-active_collection 0.2.2 → 0.2.3
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.
- data/VERSION.yml +1 -1
- data/active_collection.gemspec +64 -0
- data/lib/active_collection.rb +1 -0
- data/lib/active_collection/base.rb +1 -31
- data/lib/active_collection/pagination.rb +8 -2
- data/lib/active_collection/serialization.rb +34 -0
- data/spec/pagination_spec.rb +8 -0
- metadata +6 -3
data/VERSION.yml
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{active_collection}
|
|
8
|
+
s.version = "0.2.3"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Martin Emde"]
|
|
12
|
+
s.date = %q{2009-09-16}
|
|
13
|
+
s.description = %q{A lazy-loading, Array-like collection proxy for ActiveRecord that understands conditions and paging.}
|
|
14
|
+
s.email = %q{martin.emde@gmail.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".gitignore",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.rdoc",
|
|
24
|
+
"Rakefile",
|
|
25
|
+
"VERSION.yml",
|
|
26
|
+
"active_collection.gemspec",
|
|
27
|
+
"lib/active_collection.rb",
|
|
28
|
+
"lib/active_collection/base.rb",
|
|
29
|
+
"lib/active_collection/includes.rb",
|
|
30
|
+
"lib/active_collection/member_class.rb",
|
|
31
|
+
"lib/active_collection/order.rb",
|
|
32
|
+
"lib/active_collection/pagination.rb",
|
|
33
|
+
"lib/active_collection/scope.rb",
|
|
34
|
+
"lib/active_collection/serialization.rb",
|
|
35
|
+
"spec/active_collection_spec.rb",
|
|
36
|
+
"spec/pagination_spec.rb",
|
|
37
|
+
"spec/spec.opts",
|
|
38
|
+
"spec/spec_helper.rb"
|
|
39
|
+
]
|
|
40
|
+
s.homepage = %q{http://github.com/martinemde/active_collection}
|
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
42
|
+
s.require_paths = ["lib"]
|
|
43
|
+
s.rubyforge_project = %q{collection}
|
|
44
|
+
s.rubygems_version = %q{1.3.5}
|
|
45
|
+
s.summary = %q{A lazy-loading, Array-like collection proxy for ActiveRecord that understands conditions and paging.}
|
|
46
|
+
s.test_files = [
|
|
47
|
+
"spec/active_collection_spec.rb",
|
|
48
|
+
"spec/pagination_spec.rb",
|
|
49
|
+
"spec/spec_helper.rb"
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
if s.respond_to? :specification_version then
|
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
54
|
+
s.specification_version = 3
|
|
55
|
+
|
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
57
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
|
58
|
+
else
|
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/active_collection.rb
CHANGED
|
@@ -51,36 +51,6 @@ module ActiveCollection
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
# Turn the params into a hash suitable for passing the collection directly as an arg to a named path.
|
|
55
|
-
def to_param
|
|
56
|
-
params.empty?? nil : params.to_param
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def as_data_hash
|
|
60
|
-
data_hash = { "collection" => collection.as_json }
|
|
61
|
-
data_hash["total_entries"] = total_entries
|
|
62
|
-
data_hash
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def to_xml(options = {})
|
|
66
|
-
collect
|
|
67
|
-
options[:indent] ||= 2
|
|
68
|
-
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
|
69
|
-
xml.instruct! unless options[:skip_instruct]
|
|
70
|
-
xml.tag!(table_name) do
|
|
71
|
-
xml.total_entries(total_entries, :type => "integer")
|
|
72
|
-
xml.collection(:type => "array") do
|
|
73
|
-
collection.each do |item|
|
|
74
|
-
item.to_xml(:indent => options[:indent], :builder => xml, :skip_instruct => true)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def as_json(options = nil)
|
|
81
|
-
{table_name => as_data_hash}.as_json(options)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
54
|
# Implements Enumerable
|
|
85
55
|
def each(&block)
|
|
86
56
|
collection.each(&block)
|
|
@@ -172,6 +142,6 @@ module ActiveCollection
|
|
|
172
142
|
Base.class_eval do
|
|
173
143
|
include MemberClass
|
|
174
144
|
include Scope
|
|
175
|
-
include Includes, Order, Pagination
|
|
145
|
+
include Includes, Order, Pagination, Serialization
|
|
176
146
|
end
|
|
177
147
|
end
|
|
@@ -31,7 +31,13 @@ module ActiveCollection
|
|
|
31
31
|
# Loads total entries and calculates the size from that.
|
|
32
32
|
def size_with_pagination
|
|
33
33
|
if paginated?
|
|
34
|
-
|
|
34
|
+
if out_of_bounds?
|
|
35
|
+
0
|
|
36
|
+
elsif last_page?
|
|
37
|
+
size_without_pagination % per_page
|
|
38
|
+
else
|
|
39
|
+
per_page
|
|
40
|
+
end
|
|
35
41
|
else
|
|
36
42
|
size_without_pagination
|
|
37
43
|
end
|
|
@@ -92,7 +98,7 @@ module ActiveCollection
|
|
|
92
98
|
#
|
|
93
99
|
# may load total_entries if not already loaded.
|
|
94
100
|
def last_page?
|
|
95
|
-
next_page.nil?
|
|
101
|
+
!out_of_bounds? && next_page.nil?
|
|
96
102
|
end
|
|
97
103
|
|
|
98
104
|
# New Collection for current_page - 1 or nil.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module ActiveCollection
|
|
2
|
+
module Serialization
|
|
3
|
+
# Turn the params into a hash suitable such that passing the collection
|
|
4
|
+
# directly to a named path generates the path for the current collection.
|
|
5
|
+
def to_param
|
|
6
|
+
params.empty?? nil : params.to_param
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def as_data_hash
|
|
10
|
+
data_hash = { table_name => collection.as_json }
|
|
11
|
+
data_hash["total_entries"] = total_entries
|
|
12
|
+
data_hash
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_xml(options = {})
|
|
16
|
+
collect
|
|
17
|
+
options[:indent] ||= 2
|
|
18
|
+
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
|
19
|
+
xml.instruct! unless options[:skip_instruct]
|
|
20
|
+
xml.collection do
|
|
21
|
+
xml.total_entries(total_entries, :type => "integer")
|
|
22
|
+
xml.tag!(table_name, :type => "array") do
|
|
23
|
+
collection.each do |item|
|
|
24
|
+
item.to_xml(:indent => options[:indent], :builder => xml, :skip_instruct => true)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def as_json(options = nil)
|
|
31
|
+
{"collection" => as_data_hash}.as_json(options)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/spec/pagination_spec.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: martinemde-active_collection
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martin Emde
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-09-
|
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -38,6 +38,7 @@ files:
|
|
|
38
38
|
- README.rdoc
|
|
39
39
|
- Rakefile
|
|
40
40
|
- VERSION.yml
|
|
41
|
+
- active_collection.gemspec
|
|
41
42
|
- lib/active_collection.rb
|
|
42
43
|
- lib/active_collection/base.rb
|
|
43
44
|
- lib/active_collection/includes.rb
|
|
@@ -45,12 +46,14 @@ files:
|
|
|
45
46
|
- lib/active_collection/order.rb
|
|
46
47
|
- lib/active_collection/pagination.rb
|
|
47
48
|
- lib/active_collection/scope.rb
|
|
49
|
+
- lib/active_collection/serialization.rb
|
|
48
50
|
- spec/active_collection_spec.rb
|
|
49
51
|
- spec/pagination_spec.rb
|
|
50
52
|
- spec/spec.opts
|
|
51
53
|
- spec/spec_helper.rb
|
|
52
54
|
has_rdoc: false
|
|
53
55
|
homepage: http://github.com/martinemde/active_collection
|
|
56
|
+
licenses:
|
|
54
57
|
post_install_message:
|
|
55
58
|
rdoc_options:
|
|
56
59
|
- --charset=UTF-8
|
|
@@ -71,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
71
74
|
requirements: []
|
|
72
75
|
|
|
73
76
|
rubyforge_project: collection
|
|
74
|
-
rubygems_version: 1.
|
|
77
|
+
rubygems_version: 1.3.5
|
|
75
78
|
signing_key:
|
|
76
79
|
specification_version: 3
|
|
77
80
|
summary: A lazy-loading, Array-like collection proxy for ActiveRecord that understands conditions and paging.
|