Skip to content

Commit

Permalink
feat: remove unused code (#432)
Browse files Browse the repository at this point in the history
chore: cleanup schema.rb
  • Loading branch information
seuros authored Jan 19, 2024
1 parent f9cbff0 commit 149d59c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 47 deletions.
17 changes: 3 additions & 14 deletions lib/closure_tree/active_record_support.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
module ClosureTree
module ActiveRecordSupport
delegate :quote, to: :connection

def quote(field)
connection.quote(field)
end

def ensure_fixed_table_name(table_name)
[
ActiveRecord::Base.table_name_prefix,
remove_prefix_and_suffix(table_name),
ActiveRecord::Base.table_name_suffix
].compact.join
end

def remove_prefix_and_suffix(table_name)
pre, suff = ActiveRecord::Base.table_name_prefix, ActiveRecord::Base.table_name_suffix
def remove_prefix_and_suffix(table_name, model = ActiveRecord::Base)
pre, suff = model.table_name_prefix, model.table_name_suffix
if table_name.start_with?(pre) && table_name.end_with?(suff)
table_name[pre.size..-(suff.size + 1)]
else
Expand Down
4 changes: 2 additions & 2 deletions lib/closure_tree/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def hierarchy_table_name
# because they may have overridden the table name, which is what we want to be consistent with
# in order for the schema to make sense.
tablename = options[:hierarchy_table_name] ||
remove_prefix_and_suffix(table_name).singularize + "_hierarchies"
remove_prefix_and_suffix(table_name, model_class).singularize + "_hierarchies"

ActiveRecord::Base.table_name_prefix + tablename + ActiveRecord::Base.table_name_suffix
[model_class.table_name_prefix, tablename, model_class.table_name_suffix].join
end

def with_order_option(opts)
Expand Down
14 changes: 7 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
require 'active_support/core_ext/array'


# Start Simplecov
if RUBY_ENGINE == 'ruby'
require 'simplecov'
SimpleCov.start do
add_filter '/spec/'
end
end
# # Start Simplecov
# if RUBY_ENGINE == 'ruby'
# require 'simplecov'
# SimpleCov.start do
# add_filter '/spec/'
# end
# end

ActiveRecord::Base.configurations = {
default_env: {
Expand Down
48 changes: 24 additions & 24 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# frozen_string_literal: true

ActiveRecord::Schema.define(version: 0) do
create_table 'tags', force: :cascade do |t|
ActiveRecord::Schema.define(version: 1) do
create_table 'tags' do |t|
t.string 'name'
t.string 'title'
t.references 'parent'
t.integer 'sort_order'
t.timestamps null: false
end

create_table 'tag_hierarchies', id: false, force: :cascade do |t|
create_table 'tag_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

create_table 'uuid_tags', id: false, force: :cascade do |t|
create_table 'uuid_tags', id: false do |t|
t.string 'uuid', primary_key: true
t.string 'name'
t.string 'title'
Expand All @@ -24,115 +24,115 @@
t.timestamps null: false
end

create_table 'uuid_tag_hierarchies', id: false, force: :cascade do |t|
create_table 'uuid_tag_hierarchies', id: false do |t|
t.string 'ancestor_id', null: false
t.string 'descendant_id', null: false
t.integer 'generations', null: false
end

create_table 'destroyed_tags', force: :cascade do |t|
create_table 'destroyed_tags' do |t|
t.string 'name'
end

add_index 'tag_hierarchies', %i[ancestor_id descendant_id generations], unique: true,
name: 'tag_anc_desc_idx'
add_index 'tag_hierarchies', [:descendant_id], name: 'tag_desc_idx'

create_table 'groups', force: :cascade do |t|
create_table 'groups' do |t|
t.string 'name', null: false
end

create_table 'groupings', force: :cascade do |t|
create_table 'groupings' do |t|
t.string 'name', null: false
end

create_table 'user_sets', force: :cascade do |t|
create_table 'user_sets' do |t|
t.string 'name', null: false
end

create_table 'teams', force: :cascade do |t|
create_table 'teams' do |t|
t.string 'name', null: false
end

create_table 'users', force: :cascade do |t|
create_table 'users' do |t|
t.string 'email'
t.references 'referrer'
t.integer 'group_id'
t.timestamps null: false
end

create_table 'contracts', force: :cascade do |t|
create_table 'contracts' do |t|
t.references 'user', null: false
t.references 'contract_type'
t.string 'title'
end

create_table 'contract_types', force: :cascade do |t|
create_table 'contract_types' do |t|
t.string 'name', null: false
end

create_table 'referral_hierarchies', id: false, force: :cascade do |t|
create_table 'referral_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

create_table 'labels', force: :cascade do |t|
create_table 'labels' do |t|
t.string 'name'
t.string 'type'
t.integer 'column_whereby_ordering_is_inferred'
t.references 'mother'
end

create_table 'label_hierarchies', id: false, force: :cascade do |t|
create_table 'label_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

create_table 'cuisine_types', force: :cascade do |t|
create_table 'cuisine_types' do |t|
t.string 'name'
t.references 'parent'
end

create_table 'cuisine_type_hierarchies', id: false, force: :cascade do |t|
create_table 'cuisine_type_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

create_table 'namespace_types', force: :cascade do |t|
create_table 'namespace_types' do |t|
t.string 'name'
t.references 'parent'
end

create_table 'namespace_type_hierarchies', id: false, force: :cascade do |t|
create_table 'namespace_type_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

create_table 'metal', force: :cascade do |t|
create_table 'metal' do |t|
t.references 'parent'
t.string 'metal_type'
t.string 'value'
t.string 'description'
t.integer 'sort_order'
end

create_table 'metal_hierarchies', id: false, force: :cascade do |t|
create_table 'metal_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

create_table 'menu_items', force: :cascade do |t|
create_table 'menu_items' do |t|
t.string 'name'
t.references 'parent'
t.timestamps null: false
end

create_table 'menu_item_hierarchies', id: false, force: :cascade do |t|
create_table 'menu_item_hierarchies', id: false do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
Expand Down

0 comments on commit 149d59c

Please sign in to comment.