Commit db7b6b48 by ivan Lan

Hahaha

parent 09d97099
...@@ -126,7 +126,39 @@ module Shotengai ...@@ -126,7 +126,39 @@ module Shotengai
# Will get methods: # Will get methods:
# "#{tag_name}_list" tag_name is singular # "#{tag_name}_list" tag_name is singular
# tagger_with('xx', on: "#{tag_name}.to_sym): tag_name is plural # tagger_with('xx', on: "#{tag_name}.to_sym): tag_name is plural
include JoinCatalog # include JoinCatalog
def join_catalog_system catalog_class_name, options={}
catalog_class = catalog_class_name.constantize
tag_name = options[:as] || catalog_class.model_name.singular
acts_as_taggable_on tag_name.to_sym
list_name = "#{tag_name}_list".to_sym
class_eval do
# define_method("#{tag_name}_list=") { |value|
# super catalog_class.validate_name_chain(value)
# }
scope "#{list_name}_filter".to_sym, ->(catalogs) {
tags = catalogs && catalogs.try(:tag) || catalogs.any? && catalogs&.map(&:tag)
tags ? tagged_with(tags, on: list_name) : all
}
define_method("#{tag_name}_ids=") { |ids|
send("#{list_name}=", catalog_class.ids_to_tags(ids))
}
define_method("#{tag_name}_ids") {
send(list_name).map(&:id)
}
define_method("#{tag_name}_names") {
send(list_name).map(&:name)
}
define_method(list_name) {
catalog_class.unscope(:order).where(id: super().map { |tag| Shotengai::Catalog.parse_tag(tag) }).order(:nested_level)
}
end
end
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment