lib/trax/model.rb in trax_model-0.0.99 vs lib/trax/model.rb in trax_model-0.1.0

- old
+ new

@@ -20,11 +20,13 @@ module Model extend ::ActiveSupport::Concern extend ::ActiveSupport::Autoload autoload :Attributes + autoload :CacheKey autoload :Config + autoload :Concerns autoload :CoreExtensions autoload :ExtensionsFor autoload :Errors autoload :Registry autoload :UUID @@ -40,10 +42,11 @@ include ::Trax::Core::InheritanceHooks define_configuration_options! do option :auto_include, :default => false option :auto_include_mixins, :default => [] + option :cache, :default => ::ActiveSupport::Cache::MemoryStore.new end #like reverse merge, only assigns attributes which have not yet been assigned def reverse_assign_attributes(attributes_hash) attributes_to_assign = attributes_hash.keys.reject{|_attribute_name| attribute_present?(_attribute_name) } @@ -62,15 +65,27 @@ return if mixin_registry.key?(mixin_key) mixin_registry[mixin_key] = mixin_klass end + def self.cache + ::Trax::Model.config.cache + end + + def self.cache=(cache_store) + ::Trax::Model.configure do |config| + config.cache = cache_store + end + end + def self.root ::Pathname.new(::File.path(__FILE__)) end def self.eager_autoload_mixins! + ::Trax::Model::Mixins::CachedFindBy + ::Trax::Model::Mixins::CachedRelations ::Trax::Model::Mixins::FieldScopes ::Trax::Model::Mixins::Freezable ::Trax::Model::Mixins::IdScopes ::Trax::Model::Mixins::Restorable ::Trax::Model::Mixins::SortByScopes @@ -102,10 +117,10 @@ def mixin(key, options = {}) raise ::Trax::Model::Errors::MixinNotRegistered.new( model: self.name, mixin: key - ) unless ::Trax::Model.mixin_registry.key?(key) + ) unless ::Trax::Model.mixin_registry.key?(key) mixin_module = ::Trax::Model.mixin_registry[key] self.registered_mixins[key] = mixin_module self.class_eval do