positionable 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENCE +20 -0
- data/README.rdoc +117 -0
- data/Rakefile +1 -0
- data/lib/positionable.rb +314 -0
- data/lib/positionable/version.rb +3 -0
- data/positionable.gemspec +28 -0
- data/spec/factories.rb +53 -0
- data/spec/lib/positionable_spec.rb +596 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/matchers/contiguity_matcher.rb +26 -0
- data/spec/support/models.rb +41 -0
- data/spec/support/schema.rb +33 -0
- metadata +134 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "/spec/support/"
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'factory_girl'
|
7
|
+
FactoryGirl.find_definitions
|
8
|
+
|
9
|
+
require 'positionable'
|
10
|
+
|
11
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => File.dirname(__FILE__) + "/positionable.sqlite3")
|
12
|
+
|
13
|
+
load File.dirname(__FILE__) + '/support/schema.rb'
|
14
|
+
load File.dirname(__FILE__) + '/support/models.rb'
|
15
|
+
load File.dirname(__FILE__) + '/support/matchers/contiguity_matcher.rb'
|
16
|
+
|
17
|
+
class Array
|
18
|
+
|
19
|
+
def but_last
|
20
|
+
self[0..(size - 2)]
|
21
|
+
end
|
22
|
+
|
23
|
+
def but_first
|
24
|
+
self[1..(size - 1)]
|
25
|
+
end
|
26
|
+
|
27
|
+
def before(index)
|
28
|
+
self[0..(index - 1)] if index > 0 and index < size
|
29
|
+
end
|
30
|
+
|
31
|
+
def after(index)
|
32
|
+
self[(index + 1)..(size - 1)] if index > 0 and index < size
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Usage examples:
|
2
|
+
# folder.documents.should be_contiguous
|
3
|
+
# folder.documents.should be_contiguous.starting_at(1)
|
4
|
+
RSpec::Matchers.define :be_contiguous do
|
5
|
+
|
6
|
+
match do |array|
|
7
|
+
@start ||= 0
|
8
|
+
array.each_with_index do |current, index|
|
9
|
+
current.reload.position.should == index + @start
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def starting_at(start)
|
14
|
+
@start = start
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
failure_message_for_should do |actual|
|
19
|
+
message = "expected that"
|
20
|
+
actual.each do |current|
|
21
|
+
message << " [#{current.id}, #{current.position}]"
|
22
|
+
end
|
23
|
+
message << " would be contiguous"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Folder < ActiveRecord::Base
|
2
|
+
has_many :documents
|
3
|
+
end
|
4
|
+
|
5
|
+
class Document < ActiveRecord::Base
|
6
|
+
belongs_to :folder
|
7
|
+
is_positionable :scope => :folder
|
8
|
+
attr_accessible :position, :folder_id
|
9
|
+
end
|
10
|
+
|
11
|
+
class Item < ActiveRecord::Base
|
12
|
+
end
|
13
|
+
|
14
|
+
class DefaultItem < Item
|
15
|
+
is_positionable
|
16
|
+
end
|
17
|
+
|
18
|
+
class StartingAtOneItem < Item
|
19
|
+
is_positionable :start => 1
|
20
|
+
end
|
21
|
+
|
22
|
+
class AscItem < Item
|
23
|
+
is_positionable :order => :asc
|
24
|
+
end
|
25
|
+
|
26
|
+
class DescItem < Item
|
27
|
+
is_positionable :order => :desc
|
28
|
+
end
|
29
|
+
|
30
|
+
class Group < ActiveRecord::Base
|
31
|
+
has_many :complex_items
|
32
|
+
end
|
33
|
+
|
34
|
+
class ComplexItem < Item
|
35
|
+
belongs_to :group
|
36
|
+
is_positionable :scope => :group, :order => :desc, :start => 1
|
37
|
+
attr_accessible :position, :group_id
|
38
|
+
end
|
39
|
+
|
40
|
+
class Dummy < ActiveRecord::Base
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = false
|
3
|
+
|
4
|
+
create_table :folders, :force => true do |t|
|
5
|
+
t.string :title
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :documents, :force => true do |t|
|
10
|
+
t.integer :folder_id
|
11
|
+
t.string :title
|
12
|
+
t.integer :position
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :groups, :force => true do |t|
|
17
|
+
t.string :title
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :items, :force => true do |t|
|
22
|
+
t.integer :group_id # Only fot MixedItem
|
23
|
+
t.string :title
|
24
|
+
t.integer :position
|
25
|
+
t.string :type
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :dummies, :force => true do |t|
|
30
|
+
t.string :title
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: positionable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Philippe Guégan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: &70179937886680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70179937886680
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70179937881120 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.3'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70179937881120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sqlite3-ruby
|
38
|
+
requirement: &70179937879780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70179937879780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simplecov
|
49
|
+
requirement: &70179937877820 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70179937877820
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: factory_girl
|
60
|
+
requirement: &70179937875280 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70179937875280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: &70179937867440 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.1'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70179937867440
|
80
|
+
description: This extension provides contiguous positionning capabilities to you ActiveRecord
|
81
|
+
models.
|
82
|
+
email:
|
83
|
+
- philippe.guegan@gmail.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- .travis.yml
|
90
|
+
- Gemfile
|
91
|
+
- LICENCE
|
92
|
+
- README.rdoc
|
93
|
+
- Rakefile
|
94
|
+
- lib/positionable.rb
|
95
|
+
- lib/positionable/version.rb
|
96
|
+
- positionable.gemspec
|
97
|
+
- spec/factories.rb
|
98
|
+
- spec/lib/positionable_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/support/matchers/contiguity_matcher.rb
|
101
|
+
- spec/support/models.rb
|
102
|
+
- spec/support/schema.rb
|
103
|
+
homepage: https://github.com/pguegan/positionable
|
104
|
+
licenses: []
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project: positionable
|
123
|
+
rubygems_version: 1.8.16
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: A gem for positionning your ActiveRecord models.
|
127
|
+
test_files:
|
128
|
+
- spec/factories.rb
|
129
|
+
- spec/lib/positionable_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/matchers/contiguity_matcher.rb
|
132
|
+
- spec/support/models.rb
|
133
|
+
- spec/support/schema.rb
|
134
|
+
has_rdoc:
|