ocm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ocm (0.0.2)
4
+ ocm (0.0.3)
5
5
  iron_cache
6
6
  jsonable
7
7
 
data/lib/ocm.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require_relative 'ocm/version'
2
+ require_relative 'ocm/timestampable'
2
3
  require_relative 'ocm/ormable'
3
4
  require_relative 'ocm/iron_cache_orm'
@@ -21,8 +21,10 @@ module Ocm
21
21
  unless idable.id
22
22
  idable.id = Idable.generate_id
23
23
  end
24
+ if defined? idable.set_timestamps
25
+ idable.set_timestamps
26
+ end
24
27
  put(key_for(idable), idable)
25
-
26
28
  end
27
29
 
28
30
  def save_list(key, array)
@@ -38,12 +40,41 @@ module Ocm
38
40
  messages
39
41
  end
40
42
 
43
+ # first item that matches comps is replaced with item.
44
+ def update_in_list(key, item, comps)
45
+ messages = get_list(key)
46
+ messages.each_with_index do |m,i|
47
+ match = true
48
+ comps.each_pair do |k,v|
49
+ if m.is_a?(Hash)
50
+ if m[k] != v
51
+ match = false
52
+ break
53
+ end
54
+ else
55
+ if m.__send__(k.to_sym) != v
56
+ match = false
57
+ break
58
+ end
59
+ end
60
+ end
61
+ if match
62
+ messages[i] = item
63
+ put(key, messages)
64
+ return
65
+ end
66
+ end
67
+ raise "No matching item found in list"
68
+ end
69
+
70
+ # Warning, this is not a safe operation, be sure it is only being called once at a time
41
71
  def prepend_to_list(key, item)
42
72
  messages = get_list(key)
43
73
  messages.unshift(item)
44
74
  put(key, messages)
45
75
  end
46
76
 
77
+ # Warning, this is not a safe operation, be sure it is only being called once at a time
47
78
  def append_to_list(key, item)
48
79
  messages = get_list(key)
49
80
  messages.push(item)
@@ -85,6 +116,10 @@ module Ocm
85
116
  @cache.put(key, value, options)
86
117
  end
87
118
 
119
+ def remove(idable, id=nil)
120
+ delete(key_for(idable, id))
121
+ end
122
+
88
123
  def delete(key)
89
124
  @cache.delete(key)
90
125
  end
@@ -92,7 +127,7 @@ module Ocm
92
127
  def increment(key, value=1)
93
128
  puts 'INC'
94
129
  begin
95
- ret = @cache.increment(key)
130
+ ret = @cache.increment(key, value)
96
131
  puts 'INC RET ' + ret.inspect
97
132
  return ret.value
98
133
  rescue Rest::HttpError, IronCore::ResponseError => ex
@@ -0,0 +1,30 @@
1
+ module Ocm
2
+ module Timestampable
3
+
4
+ def created_at
5
+ @created_at
6
+ end
7
+
8
+ def created_at=(t)
9
+ @created_at = t
10
+ end
11
+
12
+ def updated_at
13
+ @updated_at
14
+ end
15
+
16
+ def updated_at=(t)
17
+ @updated_at = t
18
+ end
19
+
20
+ def set_timestamps
21
+ time = Time.now.utc
22
+ if !created_at
23
+ self.created_at = time
24
+ end
25
+ self.updated_at = time
26
+ end
27
+
28
+ end
29
+ end
30
+
data/lib/ocm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-15 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_cache
@@ -124,6 +124,7 @@ files:
124
124
  - lib/ocm/idable.rb
125
125
  - lib/ocm/iron_cache_orm.rb
126
126
  - lib/ocm/ormable.rb
127
+ - lib/ocm/timestampable.rb
127
128
  - lib/ocm/version.rb
128
129
  - ocm.gemspec
129
130
  - test/contact.rb