Class: Updater::ORM::Mock
- Inherits:
-
Object
- Object
- Updater::ORM::Mock
- Defined in:
- lib/updater/orm/mock.rb
Constant Summary collapse
- FINDER =
:find
- ID =
:id
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Instance Attribute Summary collapse
-
#finder ⇒ Object
Returns the value of attribute finder.
-
#finder_args ⇒ Object
Returns the value of attribute finder_args.
-
#id ⇒ Object
readonly
class << self.
-
#lock_name ⇒ Object
Returns the value of attribute lock_name.
-
#method ⇒ Object
Returns the value of attribute method.
-
#method_args ⇒ Object
Returns the value of attribute method_args.
-
#name ⇒ Object
Returns the value of attribute name.
-
#persistant ⇒ Object
Returns the value of attribute persistant.
-
#target ⇒ Object
Returns the value of attribute target.
-
#time ⇒ Object
Returns the value of attribute time.
Class Method Summary collapse
- ._delayed ⇒ Object
- .clear_all ⇒ Object
- .clear_locks(worker) ⇒ Object
- .create(hash) ⇒ Object
- .current ⇒ Object
- .current_load ⇒ Object
- .delayed ⇒ Object
- .for(target, finder, finder_args, name = nil) ⇒ Object
- .future(start, finish) ⇒ Object
- .get(id) ⇒ Object
- .index ⇒ Object
- .lock_next(worker) ⇒ Object
- .queue_time ⇒ Object
- .setup(options) ⇒ Object
- .storage ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(hash = {}) ⇒ Mock
constructor
A new instance of Mock.
- #lock(worker) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Mock
Returns a new instance of Mock.
95 96 97 98 99 100 |
# File 'lib/updater/orm/mock.rb', line 95 def initialize(hash = {}) @id = self.class.index hash.each do |k,v| self.send("#{k}=",v) end end |
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/updater/orm/mock.rb', line 10 def logger @logger end |
Instance Attribute Details
#finder ⇒ Object
Returns the value of attribute finder.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def finder @finder end |
#finder_args ⇒ Object
Returns the value of attribute finder_args.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def finder_args @finder_args end |
#id ⇒ Object (readonly)
class << self
91 92 93 |
# File 'lib/updater/orm/mock.rb', line 91 def id @id end |
#lock_name ⇒ Object
Returns the value of attribute lock_name.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def lock_name @lock_name end |
#method ⇒ Object
Returns the value of attribute method.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def method @method end |
#method_args ⇒ Object
Returns the value of attribute method_args.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def method_args @method_args end |
#name ⇒ Object
Returns the value of attribute name.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def name @name end |
#persistant ⇒ Object
Returns the value of attribute persistant.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def persistant @persistant end |
#target ⇒ Object
Returns the value of attribute target.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def target @target end |
#time ⇒ Object
Returns the value of attribute time.
93 94 95 |
# File 'lib/updater/orm/mock.rb', line 93 def time @time end |
Class Method Details
._delayed ⇒ Object
35 36 37 38 39 |
# File 'lib/updater/orm/mock.rb', line 35 def _delayed storage.values.find_all{|x| x.time && x.time > tnow }.sort{|a,b| a.time <=> b.time} end |
.clear_all ⇒ Object
66 67 68 |
# File 'lib/updater/orm/mock.rb', line 66 def clear_all @storage = {} end |
.clear_locks(worker) ⇒ Object
61 62 63 |
# File 'lib/updater/orm/mock.rb', line 61 def clear_locks(worker) storage.values.each{|x| x.lock_name = nil if x.lock_name == worker.name} end |
.create(hash) ⇒ Object
21 22 23 |
# File 'lib/updater/orm/mock.rb', line 21 def create(hash) new(hash).tap {|n| storage[n.id] = n} end |
.current ⇒ Object
25 26 27 28 29 |
# File 'lib/updater/orm/mock.rb', line 25 def current storage.values.find_all{|x| x.time && x.time <= tnow && !x.lock_name }.sort{|a,b| a.time <=> b.time} end |
.current_load ⇒ Object
31 32 33 |
# File 'lib/updater/orm/mock.rb', line 31 def current_load current.length end |
.delayed ⇒ Object
41 42 43 |
# File 'lib/updater/orm/mock.rb', line 41 def delayed _delayed.length end |
.for(target, finder, finder_args, name = nil) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/updater/orm/mock.rb', line 74 def for(target, finder, finder_args, name=nil) @storage.values.find_all do |x| naming = name ? x.name == name : true naming && x.finder == finder && x.finder_args == finder_args && x.target == target && !x.lock_name end end |
.future(start, finish) ⇒ Object
45 46 47 |
# File 'lib/updater/orm/mock.rb', line 45 def future(start, finish) _delayed.find_all{|x| x.time >= start+tnow && x.time < finish+tnow} end |
.get(id) ⇒ Object
17 18 19 |
# File 'lib/updater/orm/mock.rb', line 17 def get(id) storage[id] end |
.index ⇒ Object
12 13 14 15 |
# File 'lib/updater/orm/mock.rb', line 12 def index @index ||= 0 @index += 1 end |
.lock_next(worker) ⇒ Object
55 56 57 58 59 |
# File 'lib/updater/orm/mock.rb', line 55 def lock_next(worker) job = current.first job.lock(worker) if job job end |
.queue_time ⇒ Object
49 50 51 52 53 |
# File 'lib/updater/orm/mock.rb', line 49 def queue_time return 0 unless current.empty? return nil if (d = _delayed).empty? #tricky assignment in conditional d.first.time - tnow end |
.setup(options) ⇒ Object
70 71 72 |
# File 'lib/updater/orm/mock.rb', line 70 def setup() @storage = {} end |
.storage ⇒ Object
81 82 83 |
# File 'lib/updater/orm/mock.rb', line 81 def storage @storage ||= {} end |
Instance Method Details
#destroy ⇒ Object
111 112 113 |
# File 'lib/updater/orm/mock.rb', line 111 def destroy self.class.storage.delete(id) end |
#lock(worker) ⇒ Object
102 103 104 105 |
# File 'lib/updater/orm/mock.rb', line 102 def lock(worker) return false if @lock_name && @lock_name != worker.name @lock_name = worker.name end |
#save ⇒ Object
107 108 109 |
# File 'lib/updater/orm/mock.rb', line 107 def save self.class.storage[id] = self end |