lib/pseudocephalopod.rb in pseudocephalopod-0.2.2 vs lib/pseudocephalopod.rb in pseudocephalopod-0.2.3
- old
+ new
@@ -1,23 +1,30 @@
+require 'active_support'
+require 'active_record'
require 'uuid'
+require 'active_support/dependencies/autoload'
+require 'active_support/core_ext/module/attribute_accessors'
+require 'active_support/concern'
+
module Pseudocephalopod
+ extend ActiveSupport::Autoload
+ mattr_accessor :cache_key_prefix, :cache
+
class << self
- attr_accessor :cache_key_prefix, :cache
-
def with_counter(prefix, counter = 0)
counter < 1 ? prefix : "#{prefix}--#{counter}"
end
def next_value(scope, prefix)
counter = 0
slug = self.with_counter(prefix, counter)
while scope.with_cached_slug(slug).exists?
counter += 1
- slug = self.with_counter(prefix, counter)
+ slug = self.with_counter(prefix, counter)
end
slug
end
def uuid
@@ -56,15 +63,15 @@
end
self.cache_key_prefix ||= "cached-slugs"
- autoload :Caching, 'pseudocephalopod/caching'
- autoload :Scopes, 'pseudocephalopod/scopes'
- autoload :Finders, 'pseudocephalopod/finders'
- autoload :SlugHistory, 'pseudocephalopod/slug_history'
- autoload :Slug, 'pseudocephalopod/slug'
- autoload :MemoryCache, 'pseudocephalopod/memory_cache'
+ autoload :Caching
+ autoload :Scopes
+ autoload :Finders
+ autoload :SlugHistory
+ autoload :Slug
+ autoload :MemoryCache
require 'pseudocephalopod/active_record_methods'
ActiveRecord::Base.extend Pseudocephalopod::ActiveRecordMethods
require 'pseudocephalopod/railtie' if defined?(Rails::Railtie)
\ No newline at end of file