Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ancestry to latest 3.0.x #18164

Merged
merged 1 commit into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ manageiq_plugin "manageiq-schema"
gem "activerecord-id_regions", "~>0.2.0"
gem "activerecord-session_store", "~>1.1"
gem "acts_as_tree", "~>2.7" # acts_as_tree needs to be required so that it loads before ancestry
gem "ancestry", "~>2.2.1", :require => false
gem "ancestry", "~>3.0.4", :require => false
gem "bcrypt", "~> 3.1.10", :require => false
gem "bundler", ">=1.11.1", :require => false
gem "color", "~>1.8"
Expand Down
13 changes: 2 additions & 11 deletions lib/patches/ancestry_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ module Ancestry
module InstanceMethods
prepend AncestryInstanceMethodsPatch

ANCESTRY_DELIMITER = '/'.freeze

def parse_ancestry_column(obj)
obj.to_s.split(ANCESTRY_DELIMITER).map! { |id| cast_primary_key(id) }
end
ANCESTRY_DELIMITER = '/'.freeze unless defined?(ANCESTRY_DELIMITER)

def ancestor_ids
@_ancestor_ids ||= parse_ancestry_column(read_attribute(ancestry_base_class.ancestry_column))
Expand Down Expand Up @@ -60,13 +56,8 @@ def depth
end
end

STRING_BASED_KEYS = %i[string uuid text].freeze
def cast_primary_key(key)
if STRING_BASED_KEYS.include?(primary_key_type)
key
else
key.to_i
end
self.class.primary_key_is_an_integer? ? key.to_i : key
end

def clear_memoized_instance_variables
Expand Down