mongoid_orderable 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,8 +14,7 @@ Mongoid::Orderable is a ordered list implementation for your mongoid models.
14
14
  gem 'mongoid_orderable'
15
15
  ```
16
16
 
17
- Gem has the same api as others. Just include Mongoid::Orderable into your model.
18
- Also you can initialize orderable manually and specify `:scope` or `:column` options:
17
+ Gem has the same api as others. Just include Mongoid::Orderable into your model and call `orderable` method.
19
18
 
20
19
  ```
21
20
  class Item
@@ -24,8 +23,10 @@ class Item
24
23
 
25
24
  # belongs_to :group
26
25
 
26
+ # orderable
27
27
  # orderable :scope => :group, :column => :pos
28
28
  # orderable :scope => lambda { |document| where(:group_id => document.group_id) }
29
+ # orderable :index => false # this one if you want specify indexes manually
29
30
  end
30
31
  ```
31
32
 
data/Rakefile CHANGED
@@ -1 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -1,23 +1,20 @@
1
1
  module Mongoid::Orderable
2
2
  extend ActiveSupport::Concern
3
3
 
4
- included do
5
- orderable
6
- end
7
-
8
4
  module ClassMethods
9
5
  def orderable options = {}
10
6
  configuration = {
11
7
  :column => :position,
8
+ :index => true,
12
9
  :scope => nil
13
10
  }
14
11
 
15
- configuration.update options if options.is_a?(Hash)
16
- field configuration[:column], :type => Integer
17
- index configuration[:column]
18
-
12
+ configuration.merge! options if options.is_a?(Hash)
19
13
  configuration[:scope] = "#{configuration[:scope]}_id".to_sym if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/
20
14
 
15
+ field configuration[:column], :type => Integer
16
+ index configuration[:column] if configuration[:index]
17
+
21
18
  case configuration[:scope]
22
19
  when Symbol then
23
20
  scope :orderable_scope, lambda { |document| where(configuration[:scope] => document.send(configuration[:scope])) }
@@ -1,3 +1,3 @@
1
1
  module MongoidOrderable
2
- VERSION = "0.9.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -4,6 +4,8 @@ describe Mongoid::Orderable do
4
4
  class SimpleOrderable
5
5
  include Mongoid::Document
6
6
  include Mongoid::Orderable
7
+
8
+ orderable
7
9
  end
8
10
 
9
11
  class ScopedGroup
@@ -21,8 +23,6 @@ describe Mongoid::Orderable do
21
23
  orderable :scope => :group
22
24
  end
23
25
 
24
-
25
-
26
26
  class EmbedsOrderable
27
27
  include Mongoid::Document
28
28
 
@@ -34,6 +34,8 @@ describe Mongoid::Orderable do
34
34
  include Mongoid::Orderable
35
35
 
36
36
  embedded_in :embeds_orderable
37
+
38
+ orderable
37
39
  end
38
40
 
39
41
  class CustomizedOrderable
@@ -43,6 +45,13 @@ describe Mongoid::Orderable do
43
45
  orderable :column => :pos
44
46
  end
45
47
 
48
+ class NoIndexOrderable
49
+ include Mongoid::Document
50
+ include Mongoid::Orderable
51
+
52
+ orderable :index => false
53
+ end
54
+
46
55
  describe SimpleOrderable do
47
56
  before :each do
48
57
  SimpleOrderable.delete_all
@@ -60,6 +69,10 @@ describe Mongoid::Orderable do
60
69
  SimpleOrderable.fields['position'].options[:type].should == Integer
61
70
  end
62
71
 
72
+ it 'should have index on position column' do
73
+ SimpleOrderable.index_options[:position].should_not be_nil
74
+ end
75
+
63
76
  it 'should set proper position while creation' do
64
77
  positions.should == [1, 2, 3, 4, 5]
65
78
  end
@@ -267,4 +280,10 @@ describe Mongoid::Orderable do
267
280
  end
268
281
  end
269
282
 
283
+ describe NoIndexOrderable do
284
+ it 'should not have index on position column' do
285
+ NoIndexOrderable.index_options[:position].should be_nil
286
+ end
287
+ end
288
+
270
289
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_orderable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-03 00:00:00.000000000Z
12
+ date: 2012-02-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &69828211577180 !ruby/object:Gem::Requirement
16
+ requirement: &70092185456800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *69828211577180
24
+ version_requirements: *70092185456800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &69828211576700 !ruby/object:Gem::Requirement
27
+ requirement: &70092185456320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *69828211576700
35
+ version_requirements: *70092185456320
36
36
  description: Gem allows mongoid model behave as orderable list
37
37
  email:
38
38
  - kinwizard@gmail.com