lib/redis-model-extension/initialize.rb in redis-model-extension-0.4.0 vs lib/redis-model-extension/initialize.rb in redis-model-extension-0.4.1
- old
+ new
@@ -34,20 +34,14 @@
# value exists? (not nil and not blank?)
define_method "#{name}?" do
value_get(name) && !value_get(name).blank? ? true : false
end
-
- # default saving nil values to redis
- redis_save_fields_with_nil true
-
- #set default key to autoincrement id
- set_redis_autoincrement_key
end
def set_redis_autoincrement_key
- @redis_key_config = [:id]
+ @redis_key_config ||= [:id]
# get value
define_method :id do
value_get :id
end
@@ -62,16 +56,13 @@
value_set :id, new_value
end
private :id= #set it as private
redis_fields_config[:id] = :autoincrement
-
end
def remove_redis_autoincrement_key
-
- puts "#{self.name} : remove"
# remove get value
remove_method :id
# remove value exists? (not nil and not blank?)
remove_method "id?"
@@ -153,11 +144,17 @@
end
end
module Initialize
+ extend ActiveSupport::Concern
+ included do
+ redis_save_fields_with_nil true
+ set_redis_autoincrement_key
+ end
+
# initialize instance
def initialize(args={})
args = HashWithIndifferentAccess.new(args)
# look for fields in input hash
redis_fields_config.each do |key, type|
@@ -174,6 +171,6 @@
return self
end
end
-end
\ No newline at end of file
+end