From 007e748355ac81feef04ca07976251dbc65090aa Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Mon, 19 May 2014 19:01:02 +0000 Subject: [PATCH 1/2] [Misc] Lazy loading --- lib/acts-as-taggable-on.rb | 32 ++++++++----------- .../compatibility.rb | 0 lib/acts_as_taggable_on/taggable.rb | 21 ++++++++---- .../cache.rb | 0 .../collection.rb | 0 .../{acts_as_taggable_on => taggable}/core.rb | 0 .../dirty.rb | 0 .../ownership.rb | 0 .../related.rb | 0 9 files changed, 29 insertions(+), 24 deletions(-) rename lib/acts_as_taggable_on/{acts_as_taggable_on => }/compatibility.rb (100%) rename lib/acts_as_taggable_on/{acts_as_taggable_on => taggable}/cache.rb (100%) rename lib/acts_as_taggable_on/{acts_as_taggable_on => taggable}/collection.rb (100%) rename lib/acts_as_taggable_on/{acts_as_taggable_on => taggable}/core.rb (100%) rename lib/acts_as_taggable_on/{acts_as_taggable_on => taggable}/dirty.rb (100%) rename lib/acts_as_taggable_on/{acts_as_taggable_on => taggable}/ownership.rb (100%) rename lib/acts_as_taggable_on/{acts_as_taggable_on => taggable}/related.rb (100%) diff --git a/lib/acts-as-taggable-on.rb b/lib/acts-as-taggable-on.rb index 9335888cf..5cef37b9a 100644 --- a/lib/acts-as-taggable-on.rb +++ b/lib/acts-as-taggable-on.rb @@ -6,6 +6,20 @@ require 'digest/sha1' module ActsAsTaggableOn + extend ActiveSupport::Autoload + + autoload :Engine + autoload :Utils + autoload :Taggable + autoload :Tag + autoload :Tagger + autoload :TagList + autoload :Tagging + autoload :TagsHelper + + autoload :Compatibility + + class DuplicateTagError < StandardError end @@ -45,24 +59,6 @@ def initialize setup end -require 'acts_as_taggable_on/utils' - -require 'acts_as_taggable_on/taggable' -require 'acts_as_taggable_on/acts_as_taggable_on/compatibility' -require 'acts_as_taggable_on/acts_as_taggable_on/core' -require 'acts_as_taggable_on/acts_as_taggable_on/collection' -require 'acts_as_taggable_on/acts_as_taggable_on/cache' -require 'acts_as_taggable_on/acts_as_taggable_on/ownership' -require 'acts_as_taggable_on/acts_as_taggable_on/related' -require 'acts_as_taggable_on/acts_as_taggable_on/dirty' - -require 'acts_as_taggable_on/tagger' -require 'acts_as_taggable_on/tag' -require 'acts_as_taggable_on/tag_list' -require 'acts_as_taggable_on/tags_helper' -require 'acts_as_taggable_on/tagging' -require 'acts_as_taggable_on/engine' - ActiveSupport.on_load(:active_record) do extend ActsAsTaggableOn::Compatibility extend ActsAsTaggableOn::Taggable diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb b/lib/acts_as_taggable_on/compatibility.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb rename to lib/acts_as_taggable_on/compatibility.rb diff --git a/lib/acts_as_taggable_on/taggable.rb b/lib/acts_as_taggable_on/taggable.rb index da3d601f2..b34cc7b25 100644 --- a/lib/acts_as_taggable_on/taggable.rb +++ b/lib/acts_as_taggable_on/taggable.rb @@ -1,5 +1,14 @@ module ActsAsTaggableOn module Taggable + extend ActiveSupport::Autoload + + autoload :Core + autoload :Collection + autoload :Cache + autoload :Ownership + autoload :Related + autoload :Dirty + def taggable? false end @@ -90,12 +99,12 @@ def self.taggable? # each of these add context-specific methods and must be # called on each call of taggable_on - include ActsAsTaggableOn::Taggable::Core - include ActsAsTaggableOn::Taggable::Collection - include ActsAsTaggableOn::Taggable::Cache - include ActsAsTaggableOn::Taggable::Ownership - include ActsAsTaggableOn::Taggable::Related - include ActsAsTaggableOn::Taggable::Dirty + include Core + include Collection + include Cache + include Ownership + include Related + include Dirty end end end diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb b/lib/acts_as_taggable_on/taggable/cache.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb rename to lib/acts_as_taggable_on/taggable/cache.rb diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb b/lib/acts_as_taggable_on/taggable/collection.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb rename to lib/acts_as_taggable_on/taggable/collection.rb diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb b/lib/acts_as_taggable_on/taggable/core.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/core.rb rename to lib/acts_as_taggable_on/taggable/core.rb diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb b/lib/acts_as_taggable_on/taggable/dirty.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb rename to lib/acts_as_taggable_on/taggable/dirty.rb diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb b/lib/acts_as_taggable_on/taggable/ownership.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb rename to lib/acts_as_taggable_on/taggable/ownership.rb diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb b/lib/acts_as_taggable_on/taggable/related.rb similarity index 100% rename from lib/acts_as_taggable_on/acts_as_taggable_on/related.rb rename to lib/acts_as_taggable_on/taggable/related.rb From 407de61b88a85a44a5eaee9df93ec20a4a623e8c Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 20 May 2014 11:30:30 +0000 Subject: [PATCH 2/2] [Misc] Cleaning Taggable --- lib/acts-as-taggable-on.rb | 19 ++++++++++++++----- lib/acts_as_taggable_on/taggable.rb | 8 -------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/acts-as-taggable-on.rb b/lib/acts-as-taggable-on.rb index 5cef37b9a..e1caa8150 100644 --- a/lib/acts-as-taggable-on.rb +++ b/lib/acts-as-taggable-on.rb @@ -9,14 +9,23 @@ module ActsAsTaggableOn extend ActiveSupport::Autoload autoload :Engine - autoload :Utils - autoload :Taggable autoload :Tag - autoload :Tagger autoload :TagList + autoload :Taggable + autoload :Tagger autoload :Tagging autoload :TagsHelper + autoload_under 'taggable' do + autoload :Cache + autoload :Collection + autoload :Core + autoload :Dirty + autoload :Ownership + autoload :Related + end + + autoload :Utils autoload :Compatibility @@ -30,7 +39,7 @@ def self.setup def self.method_missing(method_name, *args, &block) @configuration.respond_to?(method_name) ? - @configuration.send(method_name, *args, &block) : super + @configuration.send(method_name, *args, &block) : super end def self.respond_to?(method_name, include_private=false) @@ -45,7 +54,7 @@ def self.glue class Configuration attr_accessor :delimiter, :force_lowercase, :force_parameterize, - :strict_case_match, :remove_unused_tags + :strict_case_match, :remove_unused_tags def initialize @delimiter = ',' diff --git a/lib/acts_as_taggable_on/taggable.rb b/lib/acts_as_taggable_on/taggable.rb index b34cc7b25..aaadf1633 100644 --- a/lib/acts_as_taggable_on/taggable.rb +++ b/lib/acts_as_taggable_on/taggable.rb @@ -1,13 +1,5 @@ module ActsAsTaggableOn module Taggable - extend ActiveSupport::Autoload - - autoload :Core - autoload :Collection - autoload :Cache - autoload :Ownership - autoload :Related - autoload :Dirty def taggable? false