Skip to content

Commit

Permalink
Extract format module extract
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Oct 22, 2024
1 parent 7176d19 commit fe8c2ce
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/ancestry/has_ancestry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ def has_ancestry options = {}

# Include dynamic class methods
extend Ancestry::ClassMethods

if ancestry_format == :materialized_path2
extend Ancestry::MaterializedPath2
else
extend Ancestry::MaterializedPath
end
extend Ancestry::HasAncestry.ancestry_format_module(ancestry_format)

attribute self.ancestry_column, default: self.ancestry_root

Expand Down Expand Up @@ -124,6 +119,15 @@ def acts_as_tree(*args)
return super if defined?(super)
has_ancestry(*args)
end

def self.ancestry_format_module(ancestry_format)
ancestry_format ||= Ancestry.default_ancestry_format
if ancestry_format == :materialized_path2
Ancestry::MaterializedPath2
else
Ancestry::MaterializedPath
end
end
end
end

Expand Down

0 comments on commit fe8c2ce

Please sign in to comment.