easy_redis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a68248d9943685f76f55cab4a361fbeac38afec1
4
- data.tar.gz: e4b13bcfe55bb488d9dd1456d94772783ba35663
3
+ metadata.gz: 195815edfacb1c85290d569e268c67090b4233d4
4
+ data.tar.gz: af059c901a40e331a20a992fd2c9be05c3ce8aa0
5
5
  SHA512:
6
- metadata.gz: c4fc6e232a524341a9c8ae291f4308713d9d1adcc513c856d272120cd514054e7693362e6e29eddd96f3434e4c2819f2ea22a09d768fec5b707ee647875cdc23
7
- data.tar.gz: e34e377338aa09c874a6212671c941faca290b05353c551bca5658743f37b775a343bb5f9ae0ec0f8062e12b27d28a6b39ccb4c22e2c4786b5efa6ec65fb74ad
6
+ metadata.gz: c2973d34dcba12294e95a43b44ea14301007a4ba8566aa1b67df32448ab9128e7c509fc276e7a3e2c2f710a6b506fda319bae31a7e9964930c13e4b8fb5724bc
7
+ data.tar.gz: 7c3648c87aab8d5578cc50d64b56adf916c93bd80fca166149a53191e1c36cb83096866a0e8b0a93df4998c8b4878b86ed4bac3942c1d83a316d8638fa694c79
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # EasyRedis
2
2
 
3
- Helper methods for activerecord objects to use redis easily
3
+ Helper methods for activerecord objects to use redis easily.
4
4
  Don't worry about the type casting. EasyRedis does type conversions!
5
5
 
6
6
  ## Installation
@@ -19,28 +19,34 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- Create a file under initializers directory and set a redis client like above:
22
+ Create a file under initializers directory and set a redis client like below:
23
+
24
+ EasyRedis::Redis.configure(redis: Redis.new)
23
25
 
24
- EasyRedis::Redis.configure(:redis => Redis.new)
25
26
 
26
27
  Examples:
27
28
 
28
- u = User.find(1)
29
- u.r_set("key", "value")
30
- u.redis_set("key", "value")
31
- u.redis_set_key("value")
29
+ u = User.find(1) #sample ActiveRecord object
30
+ u.r_set("foo", "bar")
31
+ u.r_set_foo("bar")
32
+ u.redis_set("foo", "bar")
33
+ u.redis_set_foo("bar")
34
+
35
+ u.r_get("foo")
36
+ u.r_get_foo
37
+ u.redis_get("foo")
38
+ u.redis_get_foo
32
39
 
33
- u.r_get("key")
34
- u.redis_get("key")
35
- u.redis_get_key
40
+ u.r_del("foo")
41
+ u.r_del_foo
42
+ u.redis_del("foo")
43
+ u.redis_del_foo
36
44
 
37
- u.r_del("key")
38
- u.redis_del("key")
39
- u.redis_del_key
45
+ u.r_set_foo true
46
+ u.r_get_foo #returns true
40
47
 
41
- u.r_update("key", "value")
42
- u.redis_update("key", "value")
43
- u.redis_update_key("value")
48
+ u.r_set_foo 1
49
+ u.r_get_foo #returns 1
44
50
 
45
51
  ## Contributing
46
52
 
@@ -1,4 +1,5 @@
1
1
  require "easy_redis/version/version"
2
+ require "easy_redis/errors/non_existent_object_error"
2
3
  require "easy_redis/initialize/active_record"
3
4
 
4
5
  module EasyRedis
@@ -8,7 +9,7 @@ module EasyRedis
8
9
  @@redis = nil
9
10
  @@config = {
10
11
  namespace: "easyredis",
11
- type_cast: true,
12
+ raise_non_existent_object_error: true,
12
13
  redis: nil
13
14
  }
14
15
  @@valid_config_keys = @@config.keys
@@ -27,8 +28,8 @@ module EasyRedis
27
28
  @@config[:namespace]
28
29
  end
29
30
 
30
- def use_type_casting?
31
- @@config[:type_cast]
31
+ def raise_non_existent_object_error?
32
+ @@config[:raise_non_existent_object_error]
32
33
  end
33
34
 
34
35
  def configure(opts = {})
@@ -0,0 +1,7 @@
1
+ class NonExistentObjectError < RuntimeError
2
+
3
+ def to_s
4
+ "Can not set value for nonexistent object's attributes"
5
+ end
6
+
7
+ end
@@ -4,7 +4,7 @@ module EasyRedis
4
4
 
5
5
  def r_get(attribute)
6
6
  val = self.redis_cli.hget(redis_key, attribute)
7
- self.use_type_casting? ? YAML.load(val.to_s) : val
7
+ val.nil? ? nil : YAML.load(val.to_s)
8
8
  end
9
9
 
10
10
  def method_missing(meth, *args, &block)
@@ -1,7 +1,6 @@
1
1
  require "easy_redis/methods/getters"
2
2
  require "easy_redis/methods/setters"
3
3
  require "easy_redis/methods/deleters"
4
- require "easy_redis/methods/updaters"
5
4
 
6
5
  module EasyRedis
7
6
 
@@ -12,11 +11,11 @@ module EasyRedis
12
11
  include EasyRedis::Getters
13
12
  include EasyRedis::Setters
14
13
  include EasyRedis::Deleters
15
- include EasyRedis::Updaters
16
14
  end
17
15
  end
18
16
 
19
17
  def redis_key
18
+ raise NonExistentObjectError if self.new_record? && EasyRedis::Redis.raise_non_existent_object_error?
20
19
  @redis_key ||= "#{EasyRedis::Redis.namespace}:attributes:#{self.class.name}:#{self.id}"
21
20
  end
22
21
 
@@ -24,10 +23,6 @@ module EasyRedis
24
23
  EasyRedis::Redis.redis
25
24
  end
26
25
 
27
- def use_type_casting?
28
- EasyRedis::Redis.use_type_casting?
29
- end
30
-
31
26
  end
32
27
 
33
28
  end
@@ -1,3 +1,3 @@
1
1
  module EasyRedis
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Emin İNAÇ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Creates getter and setter methods for redis store.
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
62
+ - .gitignore
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -67,12 +67,12 @@ files:
67
67
  - easy_redis.gemspec
68
68
  - lib/easy_redis.rb
69
69
  - lib/easy_redis/easy_redis.rb
70
+ - lib/easy_redis/errors/non_existent_object_error.rb
70
71
  - lib/easy_redis/initialize/active_record.rb
71
72
  - lib/easy_redis/methods/deleters.rb
72
73
  - lib/easy_redis/methods/getters.rb
73
74
  - lib/easy_redis/methods/methods.rb
74
75
  - lib/easy_redis/methods/setters.rb
75
- - lib/easy_redis/methods/updaters.rb
76
76
  - lib/easy_redis/version/version.rb
77
77
  homepage: http://github.com/meinac/easy_redis
78
78
  licenses:
@@ -84,19 +84,18 @@ require_paths:
84
84
  - lib
85
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ">="
92
+ - - '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.2.2
97
+ rubygems_version: 2.0.3
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Less coding for redis store
101
101
  test_files: []
102
- has_rdoc:
@@ -1,20 +0,0 @@
1
- module EasyRedis
2
-
3
- module Updaters
4
-
5
- def r_update(attribute, value)
6
- self.r_del(attribute)
7
- self.r_set(attribute, value)
8
- end
9
-
10
- def method_missing(meth, *args, &block)
11
- (meth.to_s =~ /^redis_update_(.+)$/ || meth.to_s =~ /^r_update_(.+)$/) ? r_delete($1, *args) : super
12
- end
13
-
14
- alias_method :redis_update, :r_update
15
-
16
-
17
-
18
- end
19
-
20
- end