mimeo 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/mimeo/version.rb +1 -1
  2. data/lib/mimeo.rb +21 -5
  3. metadata +2 -2
data/lib/mimeo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mimeo
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/mimeo.rb CHANGED
@@ -3,7 +3,7 @@ require "mimeo/version"
3
3
  module Mimeo
4
4
  module ClassMethods
5
5
  def ohm_model(model, options={})
6
- cattr_accessor :ohm_model_class, :field_map
6
+ cattr_accessor :ohm_model_class, :field_map, :if_block
7
7
 
8
8
  self.ohm_model_class = model
9
9
  self.field_map = options[:field_map] if options[:field_map]
@@ -23,6 +23,16 @@ module Mimeo
23
23
  end
24
24
 
25
25
  module InstanceMethods
26
+ def if_block_is_truthy
27
+ if if_block
28
+ if if_block.is_a? String
29
+ eval if_block
30
+ elsif if_block.is_a? Proc
31
+ if_block.call
32
+ end
33
+ end
34
+ end
35
+
26
36
  def remove_from_redis
27
37
  begin
28
38
  r = ohm_instance
@@ -33,10 +43,16 @@ module Mimeo
33
43
  end
34
44
 
35
45
  def save_to_redis
36
- begin
37
- r = ohm_instance
38
- populate(r).save
39
- ensure
46
+ # If an :if option is given,
47
+ # save to Redis only if the :if option evaluates to true
48
+ if if_block_is_truthy
49
+ begin
50
+ r = ohm_instance
51
+ populate(r).save
52
+ ensure
53
+ return true
54
+ end
55
+ else
40
56
  return true
41
57
  end
42
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mimeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
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-24 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ActiveRecord extension for saving data to Redis using a given Ohm model.
15
15
  email: