active_redis 0.0.4 → 0.0.5
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.
- checksums.yaml +8 -8
- data/README.md +6 -12
- data/lib/active_redis/associations.rb +1 -1
- data/lib/active_redis/attributes/attribute.rb +17 -0
- data/lib/active_redis/attributes/integer_attribute.rb +15 -0
- data/lib/active_redis/attributes/string_attribute.rb +15 -0
- data/lib/active_redis/attributes/time_attribute.rb +15 -0
- data/lib/active_redis/attributes.rb +28 -11
- data/lib/active_redis/base.rb +2 -0
- data/lib/active_redis/constants.rb +1 -1
- data/lib/active_redis/inspector.rb +11 -0
- data/lib/active_redis/persistence.rb +5 -5
- data/lib/active_redis/version.rb +1 -1
- data/lib/generators/active_redis/model/model_generator.rb +1 -1
- data/lib/generators/active_redis/model/templates/model.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDI3NjI4MjQwYjg4NmI4YTQzMjk1Y2RkYTdmMzk1ZDA3MWM4YjM0OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDdjN2ViZGVlODZhNDdkMGQ1OWRmNWQ3NzE5ZGY1MGQ2NzkzMGFiOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTliYzEyZDQxOTgxY2MyZWVhZjlmOTg5MTZkMjk3OWMwZjVhMmU4MzQyMDJj
|
10
|
+
Y2U0YzA3MTEyYTk5ZWU2OWQwYWM1ZWFhMTU1ZTIzNzY0ZDBkNDFkMjIyMWU5
|
11
|
+
NGM5NzEzOGFmZjA2MDU1MDIzNzNkYWVjNmRkNjg1M2VmNGM0NjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2ZlMzRiYzAzNjJkMmRmY2RkZjFkNGFlMmEzMWFkNWMxYWE3NGVhZTVlNWVh
|
14
|
+
ZDY5Yjk4ZWFlZTU4MmUyZmI2ZDUxOGQyNjkxM2IyNTY3OWJlMWQzZmNhZDJk
|
15
|
+
YThiMmE4ZDMyMGI5YjY3Yjk0MmI5NzliYWI3NTc0ODlkZGVmYmU=
|
data/README.md
CHANGED
@@ -20,9 +20,11 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
### Basic usage
|
22
22
|
|
23
|
+
In model you may add attributes with next types: __string__, __integer__, __time__
|
24
|
+
|
23
25
|
```ruby
|
24
26
|
class Article < ActiveRedis::Base
|
25
|
-
attributes :
|
27
|
+
attributes title: :string, link: :string
|
26
28
|
end
|
27
29
|
```
|
28
30
|
|
@@ -93,7 +95,7 @@ Also gem add support for some aggregation functions like __sum__, __min__, __max
|
|
93
95
|
|
94
96
|
```ruby
|
95
97
|
class Article < ActiveRedis::Base
|
96
|
-
attributes :
|
98
|
+
attributes link: :string, title: :string, views: :integer
|
97
99
|
end
|
98
100
|
|
99
101
|
Article.create(views: 1000, link: "http://someblog.com/1", title: "Title article")
|
@@ -122,7 +124,7 @@ rails g active_redis:model ModelName attribute1 attribute2
|
|
122
124
|
For example:
|
123
125
|
|
124
126
|
```bash
|
125
|
-
Sergeys-MacBook-Pro-2:test_active_redis sergey$ rails g active_redis:model User name city
|
127
|
+
Sergeys-MacBook-Pro-2:test_active_redis sergey$ rails g active_redis:model User name:string city:string
|
126
128
|
create app/models/user.rb
|
127
129
|
```
|
128
130
|
|
@@ -130,18 +132,10 @@ The result is app/models/user.rb with stub content
|
|
130
132
|
|
131
133
|
```ruby
|
132
134
|
class User < ActiveRedis::Base
|
133
|
-
attributes :
|
135
|
+
attributes name: :string, city: :string
|
134
136
|
end
|
135
137
|
```
|
136
138
|
|
137
|
-
### Future work
|
138
|
-
|
139
|
-
At an early time I want to implement such features:
|
140
|
-
|
141
|
-
1. Setting/getting attributes with it's types
|
142
|
-
2. Relational Operators in where
|
143
|
-
3. Scopes???
|
144
|
-
|
145
139
|
## Contributing
|
146
140
|
|
147
141
|
1. Fork it
|
@@ -28,7 +28,7 @@ module ActiveRedis
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def belongs_to(name)
|
31
|
-
define_attributes_accessors "#{name.to_s}_id"
|
31
|
+
define_attributes_accessors "#{name.to_s}_id" => :integer
|
32
32
|
define_method name.to_s do
|
33
33
|
name.to_s.capitalize.constantize.find(self.send("#{name.to_s}_id"))
|
34
34
|
end
|
@@ -1,4 +1,7 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/attributes/*.rb'].each {|file| require file }
|
2
|
+
|
1
3
|
module ActiveRedis
|
4
|
+
|
2
5
|
module Attributes
|
3
6
|
|
4
7
|
def self.included(base)
|
@@ -12,7 +15,7 @@ module ActiveRedis
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def attributes
|
15
|
-
self.class.
|
18
|
+
self.class.attributes_list.inject({}) do |hash, attribute|
|
16
19
|
hash[attribute.to_sym] = self.send(attribute.to_s)
|
17
20
|
hash
|
18
21
|
end
|
@@ -20,37 +23,51 @@ module ActiveRedis
|
|
20
23
|
|
21
24
|
module ClassMethods
|
22
25
|
|
23
|
-
def attributes(
|
24
|
-
|
26
|
+
def attributes(attrs)
|
27
|
+
raise ActiveRedis::InvalidArgumentError, "Value must be a Hash!" unless attrs.is_a?(Hash)
|
28
|
+
attrs = attrs.merge(ActiveRedis::Constants::DEFAULT_ATTRIBUTES)
|
25
29
|
class << self; attr_accessor :defined_attributes; end
|
26
|
-
self.defined_attributes ||=
|
30
|
+
self.defined_attributes ||= {}
|
27
31
|
define_attributes_accessors attrs
|
28
32
|
end
|
29
33
|
|
30
34
|
def define_attributes_accessors(attrs)
|
31
|
-
attrs
|
32
|
-
|
35
|
+
attrs.each do |attribute, type|
|
36
|
+
next unless register_attribute(attribute, type)
|
33
37
|
read_attribute attribute
|
34
38
|
write_attribute attribute
|
35
|
-
register_attribute attribute
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
42
|
+
def attributes_list
|
43
|
+
self.defined_attributes.keys.map(&:to_s)
|
44
|
+
end
|
45
|
+
|
39
46
|
private
|
40
47
|
|
41
|
-
def register_attribute(attribute)
|
42
|
-
|
48
|
+
def register_attribute(attribute, type)
|
49
|
+
return if self.defined_attributes.has_key? attribute.to_sym
|
50
|
+
self.defined_attributes[attribute.to_sym] = {
|
51
|
+
class: "ActiveRedis::Attributes::#{type.to_s.capitalize}Attribute".constantize,
|
52
|
+
type: type
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def attribute_class(attribute)
|
57
|
+
attr_class = self.defined_attributes[attribute.to_sym][:class]
|
43
58
|
end
|
44
59
|
|
45
60
|
def read_attribute(attribute)
|
46
61
|
define_method attribute do
|
47
|
-
|
62
|
+
klass = self.class.send :attribute_class, attribute
|
63
|
+
klass.load(instance_variable_get("@#{attribute}"))
|
48
64
|
end
|
49
65
|
end
|
50
66
|
|
51
67
|
def write_attribute(attribute)
|
52
68
|
define_method "#{attribute}=" do |value|
|
53
|
-
|
69
|
+
klass = self.class.send :attribute_class, attribute
|
70
|
+
klass.dump(instance_variable_set("@#{attribute}", value))
|
54
71
|
end
|
55
72
|
end
|
56
73
|
|
data/lib/active_redis/base.rb
CHANGED
@@ -4,6 +4,7 @@ require 'active_redis/persistence'
|
|
4
4
|
require 'active_redis/naming'
|
5
5
|
require 'active_redis/calculations'
|
6
6
|
require 'active_redis/finders'
|
7
|
+
require 'active_redis/inspector'
|
7
8
|
|
8
9
|
# TODO: Add Expiring module
|
9
10
|
|
@@ -16,6 +17,7 @@ module ActiveRedis
|
|
16
17
|
include Attributes
|
17
18
|
include Associations
|
18
19
|
include Persistence
|
20
|
+
include Inspector
|
19
21
|
|
20
22
|
end
|
21
23
|
end
|
@@ -25,15 +25,15 @@ module ActiveRedis
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def fill_attributes
|
28
|
-
self.id
|
29
|
-
self.created_at ||= Time.now
|
30
|
-
self.updated_at
|
28
|
+
self.id ||= ActiveRedis.connection.next_id(self.class)
|
29
|
+
self.created_at ||= Time.now
|
30
|
+
self.updated_at = Time.now
|
31
31
|
end
|
32
32
|
|
33
33
|
def prepare_hash
|
34
34
|
fill_attributes
|
35
|
-
self.class.
|
36
|
-
hash[attribute] = self.send("#{attribute}"); hash
|
35
|
+
self.class.attributes_list.inject({}) do |hash, attribute|
|
36
|
+
hash[attribute.to_sym] = self.send("#{attribute}"); hash
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/active_redis/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'generators/active_redis'
|
|
3
3
|
module ActiveRedis
|
4
4
|
module Generators
|
5
5
|
class ModelGenerator < Base
|
6
|
-
argument :actions, type: :array, default: [], banner: "attribute attribute"
|
6
|
+
argument :actions, type: :array, default: [], banner: "attribute:type attribute:type"
|
7
7
|
|
8
8
|
def create_model
|
9
9
|
template 'model.rb', File.join('app/models', "#{file_name}.rb")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Gernyak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,6 +97,10 @@ files:
|
|
97
97
|
- lib/active_redis/adapters/basic_adapter.rb
|
98
98
|
- lib/active_redis/associations.rb
|
99
99
|
- lib/active_redis/attributes.rb
|
100
|
+
- lib/active_redis/attributes/attribute.rb
|
101
|
+
- lib/active_redis/attributes/integer_attribute.rb
|
102
|
+
- lib/active_redis/attributes/string_attribute.rb
|
103
|
+
- lib/active_redis/attributes/time_attribute.rb
|
100
104
|
- lib/active_redis/base.rb
|
101
105
|
- lib/active_redis/calculations.rb
|
102
106
|
- lib/active_redis/config.rb
|
@@ -109,6 +113,7 @@ files:
|
|
109
113
|
- lib/active_redis/errors.rb
|
110
114
|
- lib/active_redis/finders.rb
|
111
115
|
- lib/active_redis/helpers/lua_scripts.rb
|
116
|
+
- lib/active_redis/inspector.rb
|
112
117
|
- lib/active_redis/lua_scripts/main.lua
|
113
118
|
- lib/active_redis/naming.rb
|
114
119
|
- lib/active_redis/persistence.rb
|