active_redis 0.0.3.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWEwZjlmY2YyODRkNTY3ZTU3NmVlZTlkOTFhNDU0MTM5NjMwNGY3NQ==
4
+ OGYyYjNmN2ZjY2FhNjgyNmI0MDk0ZjYxZmM1YzhiMmUzOGVmMjQzNA==
5
5
  data.tar.gz: !binary |-
6
- YzNmNjQwZGVhNDVmOTdlZWNmNTM4OTdhNmY2NzhiZTI4YmU2MDUyYg==
6
+ Y2ZjMWYwODllNjMwMWQzMDg0MTRiMWIzYjY1YjFjZTI5MDUxNzg3Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjIyZDkwNDk5ODIyMmIzMDEzNzdlZjA3NWIzZmI1MmE5ZDU4YTJhMGYyNDA0
10
- YTRlNjJhMWUwNDY0YTdmMjQ4NTdkMmU5MWY5ZDNlNjY5ZmZiYzE1ODk1NGI1
11
- NWZjZDk2ZGI2N2ZhYmJhMmI1ZDZjN2U4YTY3ZDU0MTZhYzQ1NzY=
9
+ NGRjOWU0YzI3YTZhZDVjZmFiNjJhOGE1NzY1ZmFjNDQ5MmNkODZkNTlkMzVl
10
+ NWJiNTBhMTM4ZjQzMzMzMDY4OWJkMGNkOTZjYzc4NTEyZTgwZjZkNjdmYjJm
11
+ MjRmZTk0NmEzZjdkZTc3NzlhNWU1YWNiNTZmNWRlZjk4MTJmZDU=
12
12
  data.tar.gz: !binary |-
13
- ZTRjYTNjY2EwNTNkMTEwOWQwOGJkMjJlZGMxNjdhY2FmODdhYjMxNDNmNTY3
14
- Y2ExZTFkMmQ3OGU3NTQ1YmUyNWM4NjFkNWU4ODI3Njg3MjczYjBiZDAzYzZm
15
- ZjkzNzE1MDllYTY4N2E5ZTFkZWIxMjQ5YjYxMWQzN2YwZWFjMWU=
13
+ OGQxNzY5YWQwYWE0YTdlZjJmYTQyNDEwYWE5Yjc4ZjRiZTdiNWVkZDc1MThm
14
+ ZmMyNzA3YzMzMzY5MThhMDZmMzY5NzhhNmQ4ZTM4NTY5ZmI1OTkwYWVjZGQ4
15
+ MWVmYmM4MTZhZWY1YTcyNTk1ZTUzNTE2NTU0ZDc2MjgxMDk1YTg=
data/README.md CHANGED
@@ -73,6 +73,14 @@ Article.destroy_all
73
73
  p Article.count # => 0
74
74
  ```
75
75
 
76
+ ### Associations _(from 0.0.4)_
77
+
78
+ #### has_one association
79
+
80
+ #### has_many association
81
+
82
+ #### belongs_to association
83
+
76
84
  ### Finders and Calculations
77
85
 
78
86
  You may find 'row' by it's id
@@ -103,15 +111,36 @@ From version 0.0.2 you are able to search item by multiple attributes using meth
103
111
  Article.where(title: "Title article", views: 1000)
104
112
  ```
105
113
 
114
+ ### Generators
115
+
116
+ In version 0.0.4 is implemented model generator
117
+
118
+ ```bash
119
+ rails g active_redis:model ModelName attribute1 attribute2
120
+ ```
121
+
122
+ For example:
123
+
124
+ ```bash
125
+ Sergeys-MacBook-Pro-2:test_active_redis sergey$ rails g active_redis:model User name city
126
+ create app/models/user.rb
127
+ ```
128
+
129
+ The result is app/models/user.rb with stub content
130
+
131
+ ```ruby
132
+ class User < ActiveRedis::Base
133
+ attributes :name, :city
134
+ end
135
+ ```
136
+
106
137
  ### Future work
107
138
 
108
139
  At an early time I want to implement such features:
109
140
 
110
- 1. Add _all_ class method
111
- 2. Implement Association module
112
- 3. Setting/getting attributes with it's types
113
- 4. Relational Operators in where
114
- 5. Scopes???
141
+ 1. Setting/getting attributes with it's types
142
+ 2. Relational Operators in where
143
+ 3. Scopes???
115
144
 
116
145
  ## Contributing
117
146
 
data/active_redis.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "redis"
22
+ spec.add_dependency "activesupport"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "rake"
@@ -16,12 +16,17 @@ module ActiveRedis
16
16
  end
17
17
  end
18
18
 
19
- # TODO: add has_many functionality
20
- def has_many
21
-
19
+ def has_many(name)
20
+ define_method name.to_s do
21
+ name.to_s.singularize.capitalize.constantize.where("#{self.class.foreign_key_name}" => self.id)
22
+ end
23
+ define_method "#{name.to_s}=" do |value|
24
+ value.each do |object|
25
+ object.send "#{self.class.foreign_key_name}=", self.id
26
+ end
27
+ end
22
28
  end
23
29
 
24
- # TODO: add belongs_to functionality
25
30
  def belongs_to(name)
26
31
  define_attributes_accessors "#{name.to_s}_id"
27
32
  define_method name.to_s do
@@ -1,3 +1,3 @@
1
1
  module ActiveRedis
2
- VERSION = "0.0.3.1"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'generators/active_redis'
2
+
3
+ module ActiveRedis
4
+ module Generators
5
+ class ModelGenerator < Base
6
+ argument :actions, type: :array, default: [], banner: "attribute attribute"
7
+
8
+ def create_model
9
+ template 'model.rb', File.join('app/models', "#{file_name}.rb")
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRedis::Base
2
+ attributes <%= actions.map{|a| ":#{a}"}.join(", ") %>
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module ActiveRedis
4
+ module Generators
5
+ class Base < ::Rails::Generators::NamedBase
6
+
7
+ def self.source_root
8
+ @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'active_redis', generator_name, 'templates'))
9
+ end
10
+
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gernyak
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ name: activesupport
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  requirement: !ruby/object:Gem::Requirement
29
43
  requirements:
@@ -100,6 +114,9 @@ files:
100
114
  - lib/active_redis/persistence.rb
101
115
  - lib/active_redis/railtie.rb
102
116
  - lib/active_redis/version.rb
117
+ - lib/generators/active_redis.rb
118
+ - lib/generators/active_redis/model/model_generator.rb
119
+ - lib/generators/active_redis/model/templates/model.rb
103
120
  homepage: ''
104
121
  licenses:
105
122
  - MIT