martinemde-active_collection 0.2.1 → 0.2.2

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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :minor: 2
@@ -4,6 +4,7 @@ require 'active_support'
4
4
 
5
5
  module ActiveCollection
6
6
  autoload :Base, 'active_collection/base'
7
+ autoload :MemberClass, 'active_collection/member_class'
7
8
  autoload :Scope, 'active_collection/scope'
8
9
  autoload :Order, 'active_collection/order'
9
10
  autoload :Includes, 'active_collection/includes'
@@ -37,30 +37,6 @@ module ActiveCollection
37
37
  proxy_respond_to?(*args) || collection.respond_to?(*args)
38
38
  end
39
39
 
40
- def self.model_class
41
- @model_class ||= name.sub(/Collection$/,'').constantize
42
- end
43
-
44
- def model_class
45
- self.class.model_class
46
- end
47
-
48
- def self.table_name
49
- model_class.table_name
50
- end
51
-
52
- def table_name
53
- self.class.table_name
54
- end
55
-
56
- def self.human_name
57
- table_name.gsub(/_/,' ')
58
- end
59
-
60
- def human_name
61
- self.class.human_name
62
- end
63
-
64
40
  # Forwards <tt>===</tt> explicitly to the collection because the instance method
65
41
  # removal above doesn't catch it. Loads the collection if needed.
66
42
  def ===(other)
@@ -191,22 +167,10 @@ module ActiveCollection
191
167
  def raise_if_loaded
192
168
  raise AlreadyLoadedError, "Cannot modify a collection that has already been loaded." if loaded?
193
169
  end
194
-
195
- # Extracted from AR:B
196
- # Object#to_a is deprecated, though it does have the desired behavior
197
- def safe_to_array(o)
198
- case o
199
- when NilClass
200
- []
201
- when Array
202
- o
203
- else
204
- [o]
205
- end
206
- end
207
170
  end
208
171
 
209
172
  Base.class_eval do
173
+ include MemberClass
210
174
  include Scope
211
175
  include Includes, Order, Pagination
212
176
  end
@@ -0,0 +1,33 @@
1
+ module ActiveCollection
2
+ module MemberClass
3
+ def self.included(mod)
4
+ mod.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def model_class
9
+ @model_class ||= name.sub(/Collection$/,'').constantize
10
+ end
11
+
12
+ def table_name
13
+ model_class.table_name
14
+ end
15
+
16
+ def human_name(*args)
17
+ model_class.human_name(*args).pluralize
18
+ end
19
+ end
20
+
21
+ def model_class
22
+ self.class.model_class
23
+ end
24
+
25
+ def table_name
26
+ self.class.table_name
27
+ end
28
+
29
+ def human_name(*args)
30
+ self.class.human_name(*args)
31
+ end
32
+ end
33
+ end
@@ -4,11 +4,18 @@ class BeerCollection < ActiveCollection::Base
4
4
  end
5
5
 
6
6
  class Beer
7
+ def self.human_name(*args)
8
+ "Beer"
9
+ end
7
10
  end
8
11
 
9
12
  describe ActiveCollection do
10
13
  subject { BeerCollection.new }
11
14
 
15
+ it "passes human_name to the member class and then pluralizes" do
16
+ subject.human_name(:locale => 'en-us').should == "Beers"
17
+ end
18
+
12
19
  context "(empty)" do
13
20
  describe "(count methods)" do
14
21
  before do
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Emde
@@ -38,10 +38,10 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION.yml
41
- - active_collection.gemspec
42
41
  - lib/active_collection.rb
43
42
  - lib/active_collection/base.rb
44
43
  - lib/active_collection/includes.rb
44
+ - lib/active_collection/member_class.rb
45
45
  - lib/active_collection/order.rb
46
46
  - lib/active_collection/pagination.rb
47
47
  - lib/active_collection/scope.rb
@@ -51,7 +51,6 @@ files:
51
51
  - spec/spec_helper.rb
52
52
  has_rdoc: false
53
53
  homepage: http://github.com/martinemde/active_collection
54
- licenses:
55
54
  post_install_message:
56
55
  rdoc_options:
57
56
  - --charset=UTF-8
@@ -72,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
71
  requirements: []
73
72
 
74
73
  rubyforge_project: collection
75
- rubygems_version: 1.3.5
74
+ rubygems_version: 1.2.0
76
75
  signing_key:
77
76
  specification_version: 3
78
77
  summary: A lazy-loading, Array-like collection proxy for ActiveRecord that understands conditions and paging.
@@ -1,62 +0,0 @@
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.1"
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-14}
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/order.rb",
31
- "lib/active_collection/pagination.rb",
32
- "lib/active_collection/scope.rb",
33
- "spec/active_collection_spec.rb",
34
- "spec/pagination_spec.rb",
35
- "spec/spec.opts",
36
- "spec/spec_helper.rb"
37
- ]
38
- s.homepage = %q{http://github.com/martinemde/active_collection}
39
- s.rdoc_options = ["--charset=UTF-8"]
40
- s.require_paths = ["lib"]
41
- s.rubyforge_project = %q{collection}
42
- s.rubygems_version = %q{1.3.5}
43
- s.summary = %q{A lazy-loading, Array-like collection proxy for ActiveRecord that understands conditions and paging.}
44
- s.test_files = [
45
- "spec/active_collection_spec.rb",
46
- "spec/pagination_spec.rb",
47
- "spec/spec_helper.rb"
48
- ]
49
-
50
- if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
- s.add_development_dependency(%q<rspec>, [">= 0"])
56
- else
57
- s.add_dependency(%q<rspec>, [">= 0"])
58
- end
59
- else
60
- s.add_dependency(%q<rspec>, [">= 0"])
61
- end
62
- end