Module: Taskinator::Persistence
- Included in:
- Process, Task
- Defined in:
- lib/taskinator/persistence.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, UnknownType
Classes: LazyLoader, RedisCleanupVisitor, RedisDeserializationVisitor, RedisSerializationVisitor, UnknownTypeError, XmlSerializationVisitor
Class Method Summary
collapse
Class Method Details
.add_process_to_list(process) ⇒ Object
11
12
13
14
15
|
# File 'lib/taskinator/persistence.rb', line 11
def add_process_to_list(process)
Taskinator.redis do |conn|
conn.sadd processes_list_key(process.scope), process.uuid
end
end
|
.deserialize(yaml) ⇒ Object
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
|
# File 'lib/taskinator/persistence.rb', line 706
def deserialize(yaml)
values = YAML.load(yaml)
if values.is_a?(Array)
values = values.collect {|value|
(value.respond_to?(:model_id) && value.respond_to?(:find)) ? value.find : value
}
elsif values.is_a?(Hash)
values.each {|key, value|
values[key] = value.find if value.respond_to?(:model_id) && value.respond_to?(:find)
}
elsif values.respond_to?(:model_id) && values.respond_to?(:find)
values = values.find
end
values
end
|
.included(klass) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/taskinator/persistence.rb', line 19
def self.included(klass)
klass.class_eval do
extend ClassMethods
include InstanceMethods
end
end
|
.processes_list_key(scope = :shared) ⇒ Object
7
8
9
|
# File 'lib/taskinator/persistence.rb', line 7
def processes_list_key(scope=:shared)
"taskinator:#{scope}:processes"
end
|
.serialize(values) ⇒ Object
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
# File 'lib/taskinator/persistence.rb', line 690
def serialize(values)
if values.is_a?(Array)
values = values.collect {|value|
value.respond_to?(:to_global_id) ? value.to_global_id : value
}
elsif values.is_a?(Hash)
values.each {|key, value|
values[key] = value.to_global_id if value.respond_to?(:to_global_id)
}
elsif values.respond_to?(:to_global_id)
values = values.to_global_id
end
YAML.dump(values)
end
|