mongoid_param 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -94,6 +94,12 @@ In your controller:
94
94
  ...
95
95
  end
96
96
 
97
+ You can also chain criteria with param_is:
98
+
99
+ ...
100
+ @user = User.param_is(params[:id]).active
101
+ ...
102
+
97
103
  In your view:
98
104
 
99
105
  link_to @user.username, @user # => /users/bob
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -14,6 +14,7 @@ module Mongoid
14
14
  self.param_fields = on_fields
15
15
  field :_param, :type => String
16
16
  index :_param, :unique => true
17
+ scope :param_is, lambda {|p| where(:_param => p) }
17
18
  validates :_param, :presence => true, :uniqueness => true,
18
19
  :format => { :with => /[-a-z0-9_]+/ },
19
20
  :exclusion => { :in => %w[index show new create edit update destroy delete] }
@@ -35,7 +36,7 @@ module Mongoid
35
36
  end
36
37
 
37
38
  def to_param
38
- _param
39
+ _param_was || _param
39
40
  end
40
41
  end
41
42
 
@@ -6,6 +6,11 @@ class Post
6
6
  field :month
7
7
  field :day
8
8
  field :title
9
+ field :active, :type => Boolean, :default => true
9
10
 
10
11
  param :year, :month, :day, :title
12
+
13
+ scope :active, where(:active => true)
14
+ scope :inactive, where(:active => false)
15
+
11
16
  end
@@ -68,6 +68,11 @@ describe Mongoid::Param do
68
68
  p.blank?.should eql false
69
69
  end
70
70
 
71
+ it "finds by scope" do
72
+ p = Post.param_is('2010_6_21_big_announcement').active.first
73
+ p.blank?.should eql false
74
+ end
75
+
71
76
  it "does not find nonexistent things" do
72
77
  p = Post.find_by_param('2010_5_3_some_post')
73
78
  p.blank?.should eql true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_param
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Coene
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-09 00:00:00 -04:00
18
+ date: 2010-07-12 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency