acts_as_nested_interval 0.1.0 → 0.1.1
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.
- checksums.yaml +7 -0
- data/README.md +1 -2
- data/lib/acts_as_nested_interval/instance_methods.rb +17 -7
- data/lib/acts_as_nested_interval/version.rb +1 -1
- data/lib/acts_as_nested_interval.rb +15 -13
- metadata +72 -82
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81cfddc984871f10b119eb476a7e8a36a8f7ab33
|
4
|
+
data.tar.gz: 0a9723da4673631ba6b4fcd1e78fa2b0948c2b8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 433a11bb304a05b91948bb0f141fd48bd0d4015fb44f2475002f56d4a1effa4e8d7508f4b979eabddd674f859c9fd40ee8c4ac0fd386153b59522380bebb9914
|
7
|
+
data.tar.gz: 6c9a2a6025120e23f451228eedba0b7b72008d759409b433bbb822d21d7d3490fd275c99afd4f1aee643e626e8c228112697352eb5b6605458cf624604eab653
|
data/README.md
CHANGED
@@ -7,8 +7,7 @@ You can find all descendants or all ancestors with just one select query.
|
|
7
7
|
You can insert and delete records without
|
8
8
|
a full table update (compared to nested set, where at insert, half the table is updated on average).
|
9
9
|
|
10
|
-
|
11
|
-
If you don't need that give a look to https://github.com/stefankroes/ancestry ,
|
10
|
+
Make sure you really need this, otherwise give a look to https://github.com/stefankroes/ancestry ,
|
12
11
|
that implements a simpler encoding model (variant of materialized path).
|
13
12
|
|
14
13
|
If your database supports recursive queryes (`WITH RECURSIVE`) or specific custom extensions
|
@@ -111,7 +111,9 @@ module ActsAsNestedInterval
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
# Rewrite method
|
114
115
|
def update_nested_interval_move
|
116
|
+
return if self.class.readonly_attributes.include?(nested_interval_foreign_key.to_sym) # Fix issue #9
|
115
117
|
begin
|
116
118
|
db_self = self.class.find(id)
|
117
119
|
db_parent = self.class.find(read_attribute(nested_interval_foreign_key))
|
@@ -176,14 +178,22 @@ module ActsAsNestedInterval
|
|
176
178
|
|
177
179
|
# Returns depth by counting ancestors up to 0 / 1.
|
178
180
|
def depth
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
if new_record?
|
182
|
+
if parent_id.nil?
|
183
|
+
return 0
|
184
|
+
else
|
185
|
+
return parent.depth + 1
|
186
|
+
end
|
187
|
+
else
|
188
|
+
n = 0
|
189
|
+
p, q = lftp, lftq
|
190
|
+
while p != 0
|
191
|
+
x = p.inverse(q)
|
192
|
+
p, q = (x * p - 1) / q, x
|
193
|
+
n += 1
|
194
|
+
end
|
195
|
+
return n
|
185
196
|
end
|
186
|
-
n
|
187
197
|
end
|
188
198
|
|
189
199
|
def lft; 1.0 * lftp / lftq end
|
@@ -39,20 +39,22 @@ module ActsAsNestedInterval
|
|
39
39
|
dependent: nested_interval_dependent
|
40
40
|
scope :roots, -> { where(nested_interval_foreign_key => nil) }
|
41
41
|
|
42
|
-
if
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
if self.table_exists? # Fix problem with migrating without table
|
43
|
+
if columns_hash["rgt"]
|
44
|
+
scope :preorder, -> { order('rgt DESC, lftp ASC') }
|
45
|
+
elsif columns_hash["rgtp"] && columns_hash["rgtq"]
|
46
|
+
scope :preorder, -> { order('1.0 * rgtp / rgtq DESC, lftp ASC') }
|
47
|
+
else
|
48
|
+
scope :preorder, -> { order('nested_interval_rgt(lftp, lftq) DESC, lftp ASC') }
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
before_create :create_nested_interval
|
52
|
+
before_destroy :destroy_nested_interval
|
53
|
+
before_update :update_nested_interval
|
54
|
+
|
55
|
+
include ActsAsNestedInterval::InstanceMethods
|
56
|
+
extend ActsAsNestedInterval::ClassMethods
|
57
|
+
end
|
56
58
|
end
|
57
59
|
|
58
60
|
end
|
metadata
CHANGED
@@ -1,199 +1,189 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_nested_interval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nicolae Claudius
|
9
8
|
- Pythonic
|
9
|
+
- Grzegorz Łuszczek
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
18
|
requirements:
|
20
|
-
- -
|
19
|
+
- - ">="
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 3.2.1
|
23
|
-
- - <
|
22
|
+
- - "<"
|
24
23
|
- !ruby/object:Gem::Version
|
25
24
|
version: '5'
|
26
25
|
type: :runtime
|
27
26
|
prerelease: false
|
28
27
|
version_requirements: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
28
|
requirements:
|
31
|
-
- -
|
29
|
+
- - ">="
|
32
30
|
- !ruby/object:Gem::Version
|
33
31
|
version: 3.2.1
|
34
|
-
- - <
|
32
|
+
- - "<"
|
35
33
|
- !ruby/object:Gem::Version
|
36
34
|
version: '5'
|
37
35
|
- !ruby/object:Gem::Dependency
|
38
36
|
name: sqlite3
|
39
37
|
requirement: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
38
|
requirements:
|
42
|
-
- -
|
39
|
+
- - ">="
|
43
40
|
- !ruby/object:Gem::Version
|
44
41
|
version: '0'
|
45
42
|
type: :development
|
46
43
|
prerelease: false
|
47
44
|
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
45
|
requirements:
|
50
|
-
- -
|
46
|
+
- - ">="
|
51
47
|
- !ruby/object:Gem::Version
|
52
48
|
version: '0'
|
53
49
|
- !ruby/object:Gem::Dependency
|
54
50
|
name: mysql2
|
55
51
|
requirement: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
52
|
requirements:
|
58
|
-
- -
|
53
|
+
- - ">="
|
59
54
|
- !ruby/object:Gem::Version
|
60
55
|
version: '0'
|
61
56
|
type: :development
|
62
57
|
prerelease: false
|
63
58
|
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
59
|
requirements:
|
66
|
-
- -
|
60
|
+
- - ">="
|
67
61
|
- !ruby/object:Gem::Version
|
68
62
|
version: '0'
|
69
63
|
- !ruby/object:Gem::Dependency
|
70
64
|
name: pg
|
71
65
|
requirement: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
66
|
requirements:
|
74
|
-
- -
|
67
|
+
- - ">="
|
75
68
|
- !ruby/object:Gem::Version
|
76
69
|
version: '0'
|
77
70
|
type: :development
|
78
71
|
prerelease: false
|
79
72
|
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
73
|
requirements:
|
82
|
-
- -
|
74
|
+
- - ">="
|
83
75
|
- !ruby/object:Gem::Version
|
84
76
|
version: '0'
|
85
77
|
description: Encode Trees in RDBMS using nested interval method for powerful querying
|
86
78
|
and speedy inserts.
|
87
79
|
email:
|
88
|
-
-
|
80
|
+
- grzegorz@piklus.pl
|
89
81
|
executables: []
|
90
82
|
extensions: []
|
91
83
|
extra_rdoc_files: []
|
92
84
|
files:
|
85
|
+
- MIT-LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- lib/acts_as_nested_interval.rb
|
93
89
|
- lib/acts_as_nested_interval/class_methods.rb
|
94
|
-
- lib/acts_as_nested_interval/instance_methods.rb
|
95
90
|
- lib/acts_as_nested_interval/core_ext/integer.rb
|
91
|
+
- lib/acts_as_nested_interval/instance_methods.rb
|
96
92
|
- lib/acts_as_nested_interval/version.rb
|
97
|
-
- lib/acts_as_nested_interval.rb
|
98
93
|
- lib/tasks/acts_as_nested_interval_tasks.rake
|
99
|
-
-
|
100
|
-
-
|
101
|
-
-
|
102
|
-
- test/dummy/script/rails
|
94
|
+
- test/acts_as_nested_interval_test.rb
|
95
|
+
- test/dummy/README.rdoc
|
96
|
+
- test/dummy/Rakefile
|
103
97
|
- test/dummy/app/assets/javascripts/application.js
|
104
98
|
- test/dummy/app/assets/stylesheets/application.css
|
105
|
-
- test/dummy/app/models/region.rb
|
106
|
-
- test/dummy/app/views/layouts/application.html.erb
|
107
99
|
- test/dummy/app/controllers/application_controller.rb
|
108
100
|
- test/dummy/app/helpers/application_helper.rb
|
109
|
-
- test/dummy/
|
110
|
-
- test/dummy/
|
111
|
-
- test/dummy/db/schema.rb
|
112
|
-
- test/dummy/Rakefile
|
101
|
+
- test/dummy/app/models/region.rb
|
102
|
+
- test/dummy/app/views/layouts/application.html.erb
|
113
103
|
- test/dummy/config.ru
|
114
|
-
- test/dummy/
|
115
|
-
- test/dummy/
|
104
|
+
- test/dummy/config/application.rb
|
105
|
+
- test/dummy/config/boot.rb
|
116
106
|
- test/dummy/config/database.yml
|
107
|
+
- test/dummy/config/environment.rb
|
108
|
+
- test/dummy/config/environments/development.rb
|
109
|
+
- test/dummy/config/environments/production.rb
|
110
|
+
- test/dummy/config/environments/test.rb
|
111
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
117
112
|
- test/dummy/config/initializers/inflections.rb
|
118
|
-
- test/dummy/config/initializers/session_store.rb
|
119
113
|
- test/dummy/config/initializers/mime_types.rb
|
120
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
121
114
|
- test/dummy/config/initializers/secret_token.rb
|
122
|
-
- test/dummy/config/initializers/
|
123
|
-
- test/dummy/config/
|
115
|
+
- test/dummy/config/initializers/session_store.rb
|
116
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
124
117
|
- test/dummy/config/locales/en.yml
|
125
|
-
- test/dummy/config/environments/test.rb
|
126
|
-
- test/dummy/config/environments/development.rb
|
127
|
-
- test/dummy/config/environments/production.rb
|
128
|
-
- test/dummy/config/environment.rb
|
129
|
-
- test/dummy/config/application.rb
|
130
118
|
- test/dummy/config/routes.rb
|
131
|
-
- test/dummy/
|
132
|
-
- test/dummy/
|
119
|
+
- test/dummy/db/migrate/20120302143528_create_regions.rb
|
120
|
+
- test/dummy/db/migrate/20121004204252_change_interval_precision.rb
|
121
|
+
- test/dummy/db/schema.rb
|
122
|
+
- test/dummy/public/404.html
|
133
123
|
- test/dummy/public/422.html
|
134
124
|
- test/dummy/public/500.html
|
135
|
-
- test/dummy/public/
|
125
|
+
- test/dummy/public/favicon.ico
|
126
|
+
- test/dummy/script/rails
|
127
|
+
- test/dummy/test/fixtures/regions.yml
|
128
|
+
- test/dummy/test/unit/region_test.rb
|
136
129
|
- test/test_helper.rb
|
137
|
-
|
138
|
-
homepage: https://github.com/clyfe/acts_as_nested_interval
|
130
|
+
homepage: https://github.com/grzlus/acts_as_nested_interval
|
139
131
|
licenses: []
|
132
|
+
metadata: {}
|
140
133
|
post_install_message:
|
141
134
|
rdoc_options: []
|
142
135
|
require_paths:
|
143
136
|
- lib
|
144
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
138
|
requirements:
|
147
|
-
- -
|
139
|
+
- - ">="
|
148
140
|
- !ruby/object:Gem::Version
|
149
141
|
version: '0'
|
150
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
143
|
requirements:
|
153
|
-
- -
|
144
|
+
- - ">="
|
154
145
|
- !ruby/object:Gem::Version
|
155
146
|
version: '0'
|
156
147
|
requirements: []
|
157
148
|
rubyforge_project:
|
158
|
-
rubygems_version:
|
149
|
+
rubygems_version: 2.2.2
|
159
150
|
signing_key:
|
160
|
-
specification_version:
|
151
|
+
specification_version: 4
|
161
152
|
summary: Encode Trees in RDBMS using nested interval method.
|
162
153
|
test_files:
|
163
|
-
- test/
|
164
|
-
- test/dummy/app/assets/javascripts/application.js
|
165
|
-
- test/dummy/app/assets/stylesheets/application.css
|
166
|
-
- test/dummy/app/models/region.rb
|
167
|
-
- test/dummy/app/views/layouts/application.html.erb
|
168
|
-
- test/dummy/app/controllers/application_controller.rb
|
169
|
-
- test/dummy/app/helpers/application_helper.rb
|
170
|
-
- test/dummy/db/migrate/20120302143528_create_regions.rb
|
171
|
-
- test/dummy/db/migrate/20121004204252_change_interval_precision.rb
|
172
|
-
- test/dummy/db/schema.rb
|
173
|
-
- test/dummy/Rakefile
|
154
|
+
- test/test_helper.rb
|
174
155
|
- test/dummy/config.ru
|
175
|
-
- test/dummy/
|
156
|
+
- test/dummy/script/rails
|
176
157
|
- test/dummy/test/fixtures/regions.yml
|
177
|
-
- test/dummy/
|
178
|
-
- test/dummy/config/
|
158
|
+
- test/dummy/test/unit/region_test.rb
|
159
|
+
- test/dummy/config/routes.rb
|
179
160
|
- test/dummy/config/initializers/session_store.rb
|
180
161
|
- test/dummy/config/initializers/mime_types.rb
|
162
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
163
|
+
- test/dummy/config/initializers/inflections.rb
|
181
164
|
- test/dummy/config/initializers/wrap_parameters.rb
|
182
165
|
- test/dummy/config/initializers/secret_token.rb
|
183
|
-
- test/dummy/config/
|
166
|
+
- test/dummy/config/application.rb
|
167
|
+
- test/dummy/config/environment.rb
|
184
168
|
- test/dummy/config/boot.rb
|
185
|
-
- test/dummy/config/locales/en.yml
|
186
|
-
- test/dummy/config/environments/test.rb
|
187
|
-
- test/dummy/config/environments/development.rb
|
188
169
|
- test/dummy/config/environments/production.rb
|
189
|
-
- test/dummy/config/
|
190
|
-
- test/dummy/config/
|
191
|
-
- test/dummy/config/
|
192
|
-
- test/dummy/
|
193
|
-
- test/dummy/public/favicon.ico
|
194
|
-
- test/dummy/public/422.html
|
170
|
+
- test/dummy/config/environments/development.rb
|
171
|
+
- test/dummy/config/environments/test.rb
|
172
|
+
- test/dummy/config/locales/en.yml
|
173
|
+
- test/dummy/config/database.yml
|
195
174
|
- test/dummy/public/500.html
|
196
175
|
- test/dummy/public/404.html
|
197
|
-
- test/
|
176
|
+
- test/dummy/public/favicon.ico
|
177
|
+
- test/dummy/public/422.html
|
178
|
+
- test/dummy/db/migrate/20120302143528_create_regions.rb
|
179
|
+
- test/dummy/db/migrate/20121004204252_change_interval_precision.rb
|
180
|
+
- test/dummy/db/schema.rb
|
181
|
+
- test/dummy/README.rdoc
|
182
|
+
- test/dummy/Rakefile
|
183
|
+
- test/dummy/app/assets/stylesheets/application.css
|
184
|
+
- test/dummy/app/assets/javascripts/application.js
|
185
|
+
- test/dummy/app/views/layouts/application.html.erb
|
186
|
+
- test/dummy/app/helpers/application_helper.rb
|
187
|
+
- test/dummy/app/models/region.rb
|
188
|
+
- test/dummy/app/controllers/application_controller.rb
|
198
189
|
- test/acts_as_nested_interval_test.rb
|
199
|
-
has_rdoc:
|