Skip to content

Commit

Permalink
Merge pull request #18164 from kbrock/new_ancestry
Browse files Browse the repository at this point in the history
Update ancestry to latest 3.0.x
  • Loading branch information
jrafanie committed Nov 6, 2018
2 parents d952e08 + 0c062db commit d5fc0a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
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

0 comments on commit d5fc0a9

Please sign in to comment.