ancestry 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,14 +6,13 @@ Ancestry is a gem/plugin that allows the records of a Ruby on Rails ActiveRecord
6
6
 
7
7
  To apply Ancestry to any ActiveRecord model, follow these simple steps:
8
8
 
9
- 1. Install gem
10
- - Install gemcutter gem: <b>sudo gem install gemcutter</b> (maybe you need: gem update --system)
11
- - Add gemcutter.org as default gem source: <b>gem tumble</b>
12
- - Add to config/environment.rb: <b>config.gem 'ancestry'</b>
13
- - Install required gems: <b>sudo rake gems:install</b>
14
- - Alternatively: sudo gem install ancestry
15
- - If you don't want gemcutter: config.gem 'ancestry', :source => 'gemcutter.org'
16
- - Alternatively: sudo gem install ancestry --source gemcutter.org
9
+ 1. Install
10
+ - <b>Rails 2</b>
11
+ - Add to config/environment.rb: <b>config.gem 'ancestry'</b>
12
+ - Install required gems: <b>sudo rake gems:install</b>
13
+ - <b>Rails 3</b>
14
+ - Add to Gemfile: <b>gem 'ancestry'</b>
15
+ - Install required gems: <b>bundle install</b>
17
16
 
18
17
  2. Add ancestry column to your table
19
18
  - Create migration: <b>./script/generate migration add_ancestry_to_[table] ancestry:string</b>
@@ -80,6 +79,8 @@ The has_ancestry methods supports the following options:
80
79
  - Migrate: add_column [table], :ancestry_depth, :integer, :default => 0
81
80
  - Build cache: TreeNode.rebuild_depth_cache!
82
81
  :depth_cache_column Pass in a symbol to store depth cache in a different column
82
+ :primary_key_format Supply a regular expression that matches the format of your primary key.
83
+ By default, primary keys only match integers ([0-9]+).
83
84
 
84
85
  = (Named) Scopes
85
86
 
@@ -229,6 +230,9 @@ The materialised path pattern requires Ancestry to use a 'like' condition in ord
229
230
 
230
231
  The latest and recommended version of ancestry is 1.2.2. The three numbers of each version numbers are respectively the major, minor and patch versions. We started with major version 1 because it looks so much better and ancestry was already quite mature and complete when it was published. The major version is only bumped when backwards compatibility is broken. The minor version is bumped when new features are added. The patch version is bumped when bugs are fixed.
231
232
 
233
+ - Version 1.2.3 (2010-10-28)
234
+ - Fixed error with determining ActiveRecord version
235
+ - Added option to specify :primary_key_format (thanks goes to rolftimmermans)
232
236
  - Version 1.2.2 (2010-10-24)
233
237
  - Fixed all deprecation warnings for rails 3.0.X
234
238
  - Added :report option to check_ancestry_integrity!
@@ -3,8 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.description = 'Organise ActiveRecord model into a tree structure'
4
4
  s.summary = 'Ancestry allows the records of a ActiveRecord model to be organised in a tree structure, using a single, intuitively formatted database column. It exposes all the standard tree structure relations (ancestors, parent, root, children, siblings, descendants) and all of them can be fetched in a single sql query. Additional features are named_scopes, integrity checking, integrity restoration, arrangement of (sub)tree into hashes and different strategies for dealing with orphaned records.'
5
5
 
6
- s.version = '1.2.2'
7
- s.date = '2010-10-24'
6
+ s.version = '1.2.3'
8
7
 
9
8
  s.author = 'Stefan Kroes'
10
9
  s.email = 's.a.kroes@gmail.com'
@@ -24,4 +23,4 @@ Gem::Specification.new do |s|
24
23
  ]
25
24
 
26
25
  s.add_dependency 'activerecord', '>= 2.2.2'
27
- end
26
+ end
@@ -7,7 +7,7 @@ class << ActiveRecord::Base
7
7
  # Check options
8
8
  raise Ancestry::AncestryException.new("Options for has_ancestry must be in a hash.") unless options.is_a? Hash
9
9
  options.each do |key, value|
10
- unless [:ancestry_column, :orphan_strategy, :cache_depth, :depth_cache_column].include? key
10
+ unless [:ancestry_column, :orphan_strategy, :cache_depth, :depth_cache_column, :primary_key_format].include? key
11
11
  raise Ancestry::AncestryException.new("Unknown option for has_ancestry: #{key.inspect} => #{value.inspect}.")
12
12
  end
13
13
  end
@@ -31,19 +31,19 @@ class << ActiveRecord::Base
31
31
  self.base_class = self
32
32
 
33
33
  # Validate format of ancestry column value
34
- validates_format_of ancestry_column, :with => /\A[0-9]+(\/[0-9]+)*\Z/, :allow_nil => true
34
+ primary_key_format = options[:primary_key_format] || /[0-9]+/
35
+ validates_format_of ancestry_column, :with => /\A#{primary_key_format.source}(\/#{primary_key_format.source})*\Z/, :allow_nil => true
35
36
 
36
37
  # Validate that the ancestor ids don't include own id
37
38
  validate :ancestry_exclude_self
38
39
 
39
40
  # Save ActiveRecord version
40
41
  self.cattr_accessor :rails_3
41
- self.rails_3 = defined?(ActiveRecord::VERSION) and ActiveRecord::VERSION::MAJOR >= 3
42
+ self.rails_3 = defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::MAJOR >= 3
42
43
 
43
44
  # Workaround to support Rails 2
44
45
  scope_method = if rails_3 then :scope else :named_scope end
45
46
 
46
-
47
47
  # Named scopes
48
48
  send scope_method, :roots, :conditions => {ancestry_column => nil}
49
49
  send scope_method, :ancestors_of, lambda { |object| {:conditions => to_node(object).ancestor_conditions} }
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ancestry
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 2
8
- - 2
9
- version: 1.2.2
9
+ - 3
10
+ version: 1.2.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Stefan Kroes
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-24 00:00:00 +02:00
18
+ date: 2010-10-28 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 2
30
32
  - 2
@@ -65,6 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
67
  requirements:
66
68
  - - ">="
67
69
  - !ruby/object:Gem::Version
70
+ hash: 3
68
71
  segments:
69
72
  - 0
70
73
  version: "0"
@@ -73,6 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  requirements:
74
77
  - - ">="
75
78
  - !ruby/object:Gem::Version
79
+ hash: 3
76
80
  segments:
77
81
  - 0
78
82
  version: "0"