redis_props 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -34,12 +34,18 @@ The `RedisProps` module depends on `Redis.current` (provided by the `redis` gem)
34
34
  Key names and namespaces are generated using a customized version of a 1-file library called `Nest`
35
35
  hat we bundled into this gem.
36
36
 
37
- To add RedisProps to your models just include `RedisProps` in your ActiveRecord class.
37
+ To add RedisProps to your models just include `RedisProps` in your ActiveRecord class and use the
38
+ `redis_props` method to declare extra (optionally namespaced) properties for your objects.
38
39
 
39
40
  ```ruby
40
41
  class Dog < ActiveRecord::Base
41
42
  include RedisProps
42
43
 
44
+ redis_props do
45
+ define :nickname
46
+ define :favorite_treat
47
+ end
48
+
43
49
  redis_props :has_medical_condition do
44
50
  define :fleas, default: false
45
51
  end
@@ -48,6 +54,9 @@ end
48
54
  >> dog = Dog.create(name: "Fido")
49
55
  => <Dog id: 1, name: "Fido", created_at: "2012-05-13 02:15:35", updated_at: "2012-05-13 02:15:35">
50
56
 
57
+ >> dog.nickname = "the wonder dog"
58
+ => "the wonder dog"
59
+
51
60
  >> dog.has_medical_condition_fleas?
52
61
  => false
53
62
 
@@ -57,6 +66,9 @@ end
57
66
  >> dog = Dog.find_by_name("Fido")
58
67
  => <Dog id: 1, name: "Fido", created_at: "2012-05-13 02:15:35", updated_at: "2012-05-13 02:15:35">
59
68
 
69
+ >> dog.nickname
70
+ => "the wonder dog"
71
+
60
72
  >> dog.has_medical_condition_fleas?
61
73
  => true
62
74
  ```
data/lib/redis_props.rb CHANGED
@@ -33,7 +33,7 @@ module RedisProps
33
33
  # time instead of the updated_at/on attribute.
34
34
  # This option defaults to +false+.
35
35
  #
36
- def props(context_name, opts={}, &block)
36
+ def props(context_name="", opts={}, &block)
37
37
  PropsContext.new(context_name, self, opts, block)
38
38
  end
39
39
  end
@@ -41,11 +41,12 @@ module RedisProps
41
41
  class PropsContext
42
42
  def initialize(context_name, klass, opts, block)
43
43
  @context_name, @klass, @opts = context_name, klass, opts
44
+ @context_name = "#{@context_name}_" unless @context_name.blank?
44
45
  instance_exec(&block)
45
46
  end
46
47
 
47
48
  def define(name, d_opts={})
48
- add_methods_to(@klass, "#{@context_name}_#{name}", d_opts, @opts)
49
+ add_methods_to(@klass, "#{@context_name}#{name}", d_opts, @opts)
49
50
  end
50
51
 
51
52
  private
@@ -1,3 +1,3 @@
1
1
  module RedisProps
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -11,6 +11,10 @@ class Dog < ActiveRecord::Base
11
11
  t.timestamps
12
12
  end
13
13
 
14
+ props do
15
+ define :nickname
16
+ end
17
+
14
18
  props :has_medical_condition do
15
19
  define :fleas, default: false
16
20
  define :pants, default: true
@@ -56,6 +60,13 @@ describe RedisProps do
56
60
  let(:dirty_dog) { Dog.create!(name: "Bodiddly") }
57
61
  let(:user) { User.create!(name: "Hugo", saved_at: 1.day.ago) }
58
62
 
63
+ context "blank context" do
64
+ it do
65
+ clean_dog.nickname = "the amazing beer dog"
66
+ Dog.find_by_name("Wego").nickname.should == "the amazing beer dog"
67
+ end
68
+ end
69
+
59
70
  context "props options" do
60
71
  it "should touch the AR object's updated_at if touch: true" do
61
72
  orig_updated_at = clean_dog.updated_at
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_props
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
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-05-14 00:00:00.000000000 Z
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec