resolver 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2@resolver --create
1
+ rvm 1.9.3@resolver --create
data/README.md CHANGED
@@ -29,7 +29,7 @@ class Post < ActiveRecord::Base
29
29
  include Resolver::Key
30
30
 
31
31
  key :category
32
- key :slug, :unique => true
32
+ key :slug, :unique => true, :global => true
33
33
 
34
34
  end
35
35
 
@@ -40,6 +40,8 @@ Post.exists_with?(:slug, 'example-post') # => true
40
40
  Post.count_with(:category, 'News') # => 1
41
41
  ```
42
42
 
43
+ The ```:global => true``` option means that the key globally namespaced and is shared by all models. If global is set to false the key is instead namespaced based on the name of the model class.
44
+
43
45
  Development
44
46
  -----------
45
47
 
data/lib/resolver/key.rb CHANGED
@@ -48,7 +48,12 @@ module Resolver
48
48
  end
49
49
 
50
50
  def index_name(name, value)
51
- "#{self.class.to_s}:#{name}:#{value}"
51
+ options = @resolver_keys[name.to_sym]
52
+ if options[:global]
53
+ "#{name}:#{value}"
54
+ else
55
+ "#{self.to_s}:#{name}:#{value}"
56
+ end
52
57
  end
53
58
 
54
59
  def write_index(key, object, options)
@@ -1,3 +1,3 @@
1
1
  module Resolver
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -17,6 +17,15 @@ class ResolverTest < Test::Unit::TestCase
17
17
  assert_equal 'namespace', Resolver.redis.namespace
18
18
  end
19
19
 
20
+ def test_index_name
21
+ TestModel.key(:example_1)
22
+ TestModel.key(:example_2, :unique => true)
23
+ TestModel.key(:example_3, :global => true)
24
+ assert_equal 'TestModel:example_1:foo', TestModel.send(:index_name, :example_1, 'foo')
25
+ assert_equal 'TestModel:example_2:foo', TestModel.send(:index_name, :example_2, 'foo')
26
+ assert_equal 'example_3:foo', TestModel.send(:index_name, :example_3, 'foo')
27
+ end
28
+
20
29
  def test_key
21
30
  TestModel.key(:example)
22
31
  TestModel.create('one', :example => 'foo')
data/test/test_model.rb CHANGED
@@ -3,6 +3,7 @@ require 'active_model'
3
3
  class TestModel
4
4
  extend ActiveModel::Callbacks
5
5
  include ActiveModel::Dirty
6
+ include ActiveModel::AttributeMethods
6
7
 
7
8
  define_model_callbacks :create, :update, :destroy, :save
8
9
 
@@ -19,12 +20,18 @@ class TestModel
19
20
  @id
20
21
  end
21
22
 
23
+ def attribute(name)
24
+ if @attributes.keys.include?(name.to_sym)
25
+ @attributes[name.to_sym]
26
+ end
27
+ end
28
+
22
29
  def method_missing(sym, *args, &block)
23
- if @attributes.keys.include?(sym)
24
- @attributes[sym]
25
- else
26
- super
27
- end
30
+ if @attributes.keys.include?(sym)
31
+ @attributes[sym]
32
+ else
33
+ super
34
+ end
28
35
  end
29
36
 
30
37
  def <=>(other)
metadata CHANGED
@@ -1,76 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resolver
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Niklas Holmgren
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-11-02 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: redis
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70299789960080 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">"
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 0
31
- - 0
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
32
21
  version: 2.0.0
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: redis-namespace
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70299789960080
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis-namespace
27
+ requirement: &70299789958920 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">"
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 8
46
- - 0
29
+ requirements:
30
+ - - ! '>'
31
+ - !ruby/object:Gem::Version
47
32
  version: 0.8.0
48
33
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: activemodel
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70299789958920
36
+ - !ruby/object:Gem::Dependency
37
+ name: activemodel
38
+ requirement: &70299789958000 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :development
62
- version_requirements: *id003
63
- description: Resolver is a flexible Redis-backed high performance index and cache solution for ActiveModel-like objects.
64
- email:
45
+ prerelease: false
46
+ version_requirements: *70299789958000
47
+ description: Resolver is a flexible Redis-backed high performance index and cache
48
+ solution for ActiveModel-like objects.
49
+ email:
65
50
  - niklas@sutajio.se
66
51
  executables: []
67
-
68
52
  extensions: []
69
-
70
- extra_rdoc_files:
53
+ extra_rdoc_files:
71
54
  - LICENSE
72
55
  - README.md
73
- files:
56
+ files:
74
57
  - .gitignore
75
58
  - .rvmrc
76
59
  - Gemfile
@@ -86,39 +69,33 @@ files:
86
69
  - test/resolver_test.rb
87
70
  - test/test_helper.rb
88
71
  - test/test_model.rb
89
- has_rdoc: true
90
72
  homepage: http://github.com/sutajio/resolver/
91
73
  licenses: []
92
-
93
74
  post_install_message:
94
- rdoc_options:
75
+ rdoc_options:
95
76
  - --charset=UTF-8
96
- require_paths:
77
+ require_paths:
97
78
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
79
+ required_ruby_version: !ruby/object:Gem::Requirement
99
80
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- segments:
104
- - 0
105
- version: "0"
106
- required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
86
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- segments:
112
- - 0
113
- version: "0"
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
114
91
  requirements: []
115
-
116
92
  rubyforge_project: resolver
117
- rubygems_version: 1.3.7
93
+ rubygems_version: 1.8.17
118
94
  signing_key:
119
95
  specification_version: 3
120
- summary: Resolver is a flexible Redis-backed high performance index and cache solution for ActiveModel-like objects.
121
- test_files:
96
+ summary: Resolver is a flexible Redis-backed high performance index and cache solution
97
+ for ActiveModel-like objects.
98
+ test_files:
122
99
  - test/redis-test.conf
123
100
  - test/resolver_test.rb
124
101
  - test/test_helper.rb