record_redis 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis_record.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Marcel Schlimper
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RedisRecord
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'redis_record'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install redis_record
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,90 @@
1
+ require 'json'
2
+
3
+ module RedisRecord
4
+ class Base
5
+ attr_accessor :hash_of_properties
6
+ def initialize
7
+ @hash_of_properties= Hash.new
8
+ end
9
+
10
+ def self.find(key)
11
+ name= self.name
12
+ RedisRecord::Connection.connect unless RedisRecord::Connection.isConnected?
13
+ result= RedisRecord::Connection.connection.hget(name,key)
14
+ if result
15
+ model = self.new
16
+ model.hash_of_properties= JSON.parse(result)
17
+ else
18
+ return nil
19
+ end
20
+ model
21
+ end
22
+
23
+ def update(attributes)
24
+ @hash_of_properties.merge!(attributes)
25
+ name= self.class
26
+ key= @hash_of_properties["key"]
27
+ value= @hash_of_properties
28
+
29
+ RedisRecord::Connection.connect unless RedisRecord::Connection.isConnected?
30
+ result= RedisRecord::Connection.connection.hset(name,key,value.to_json)
31
+
32
+
33
+ end
34
+
35
+ def self.create(opts)
36
+ @hash_of_properties= opts
37
+ @hash_of_properties[:key]= generate_key if @hash_of_properties[:key].nil?
38
+
39
+ name= self.name
40
+ key= @hash_of_properties[:key]
41
+ value= @hash_of_properties
42
+
43
+ RedisRecord::Connection.connect unless RedisRecord::Connection.isConnected?
44
+ result= RedisRecord::Connection.connection.hset(name,key,value.to_json)
45
+
46
+ #TODO: type of result
47
+ result
48
+ end
49
+
50
+ def delete
51
+ name= self.class
52
+ key= @hash_of_properties["key"]
53
+ RedisRecord::Connection.connect unless RedisRecord::Connection.isConnected?
54
+ result= RedisRecord::Connection.connection.hdel(name,key)
55
+ result
56
+ end
57
+
58
+ def self.properties(*elems)
59
+ elems.each do |elem|
60
+ name= elem.to_s
61
+ class_eval <<-EOD
62
+ def #{name}=(value)
63
+ @hash_of_properties['#{name}']=value
64
+ end
65
+ def #{name}
66
+ @hash_of_properties['#{name}']
67
+ end
68
+ EOD
69
+ end
70
+ end
71
+
72
+ def self.generate_key
73
+ name= self.name
74
+ key= (rand(899999999999)+100000000000).to_s
75
+ if self.find(key)
76
+ self.generate_key
77
+ else
78
+ key
79
+ end
80
+ end
81
+
82
+ def [](key)
83
+ @hash_of_properties[key]
84
+ end
85
+
86
+ def []=(key,value)
87
+ @hash_of_properties[key]=value
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,23 @@
1
+ module RedisRecord
2
+ class Connection
3
+ attr_accessor :connection
4
+
5
+ def self.connect
6
+ host= RedisRecord::Connection::Host
7
+ port= RedisRecord::Connection::Port
8
+ db= RedisRecord::Connection::Db
9
+ @@connection = Redis.new(:host => host, :port => port, :db => db)
10
+ @@connection.Ping == "PONG"
11
+ @@connection
12
+ end
13
+
14
+ def self.isConnected?
15
+ @@connection && @@connection.client.connected?
16
+ end
17
+
18
+ def self.connection
19
+ @@connection
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module RedisRecord
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "redis_record/version"
2
+ require "redis_record/config"
3
+ require "redis_record/base"
4
+ require 'redis'
5
+
6
+ #module RedisRecord
7
+ # # Your code goes here...
8
+ #end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redis_record/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "record_redis"
8
+ spec.version = RedisRecord::VERSION
9
+ spec.authors = ["Marcel Schlimper"]
10
+ spec.email = ["mschlimp@googlemail.com"]
11
+ spec.description = %q{a redis orm mapper for rails}
12
+ spec.summary = %q{a redis orm mapper}
13
+ spec.homepage = "http://redisrecord.storiesboard.de"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "redis","3.0.4"
22
+
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Komodo Project File - DO NOT EDIT -->
3
+ <project id="fbf55ecc-dfa0-584b-bb55-c6a1467fcc0c" kpf_version="5" name="redis_record.komodoproject">
4
+ </project>
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ class Network < RedisRecord::Base
4
+ properties :name, :format, :key
5
+ end
6
+
7
+ describe RedisRecord::Base do
8
+ before(:all) do
9
+ @host = "127.0.0.1"
10
+ RedisRecord::Connection::Host= @host
11
+ @port = "6379"
12
+ RedisRecord::Connection::Port= @port
13
+ @db = 0
14
+ RedisRecord::Connection::Db= @db
15
+ RedisRecord::Connection.connect
16
+
17
+ end
18
+
19
+ describe '#properties' do
20
+ it 'should have a method #name and #format' do
21
+ network= Network.new
22
+ network.methods.to_s.include?("name=").should be_true
23
+ network.methods.to_s.include?("format=").should be_true
24
+ end
25
+
26
+ it 'must change the value of the name property' do
27
+ network_name= "MyNetworkName"
28
+ network= Network.new
29
+ network.name= network_name
30
+ network.name.should == network_name
31
+ end
32
+ end
33
+
34
+ describe '#create' do
35
+ it 'should play arround' do
36
+ network= Network.create({:name => "paul", :key => "1234567890"})
37
+ end
38
+ end
39
+
40
+ describe '#generate_key' do
41
+ it 'should generate a new key' do
42
+ key = Network.generate_key
43
+ key.to_i.should > 0
44
+ end
45
+ end
46
+
47
+ describe '#find' do
48
+ it 'should find a existing entity' do
49
+ network= Network.find("1")
50
+ network.name.should == "testNetwork"
51
+ end
52
+ end
53
+
54
+ describe '#update' do
55
+ it 'should update a existing model entity' do
56
+ network= Network.find("1234567890")
57
+ network.update({"name" => "updatedNetwork"})
58
+ end
59
+ end
60
+
61
+ describe '#delete' do
62
+ it 'should remove a existing entity' do
63
+ network= Network.find("1234567890")
64
+ network.delete.should be_true
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedisRecord::Connection do
4
+ before(:all) do
5
+ @host = "127.0.0.1"
6
+ RedisRecord::Connection::Host= @host
7
+ @port = "6379"
8
+ RedisRecord::Connection::Port= @port
9
+ @db = 0
10
+ RedisRecord::Connection::Db= @db
11
+
12
+ end
13
+ it 'must set a host for a connection' do
14
+
15
+ RedisRecord::Connection::Host.should == @host
16
+ end
17
+
18
+ it 'must set a port for a connection' do
19
+ RedisRecord::Connection::Port.should == @port
20
+ end
21
+
22
+ it 'must set a db for a connection' do
23
+ RedisRecord::Connection::Db.should == @db
24
+ end
25
+
26
+ describe '#connect' do
27
+ it 'has to connect to a given redis db' do
28
+ redis = RedisRecord::Connection.connect
29
+ RedisRecord::Connection.isConnected?.should be_true
30
+ end
31
+
32
+ it 'has to reconnect to a given redis db' do
33
+ redis = RedisRecord::Connection.connect
34
+ redis.client.disconnect
35
+ redis = RedisRecord::Connection.connect
36
+ RedisRecord::Connection.isConnected?.should be_true
37
+ end
38
+
39
+ it 'should be false to check a failed redis connection' do
40
+ redis = RedisRecord::Connection.connect
41
+ redis.client.disconnect
42
+ RedisRecord::Connection.isConnected?.should be_false
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+
@@ -0,0 +1,23 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
9
+ $: << File.join(APP_ROOT, 'lib/redis_record') # so rspec knows where your file could be
10
+ require 'redis_record' # this loads the class you want to test
11
+
12
+
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ #config.filter_run :focus
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: record_redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marcel Schlimper
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: a redis orm mapper for rails
79
+ email:
80
+ - mschlimp@googlemail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/redis_record.rb
92
+ - lib/redis_record/base.rb
93
+ - lib/redis_record/config.rb
94
+ - lib/redis_record/version.rb
95
+ - redis_record.gemspec
96
+ - redis_record.komodoproject
97
+ - spec/lib/redis_record/base_spec.rb
98
+ - spec/lib/redis_record/config_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: http://redisrecord.storiesboard.de
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: -141422551716861098
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: -141422551716861098
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.25
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: a redis orm mapper
131
+ test_files:
132
+ - spec/lib/redis_record/base_spec.rb
133
+ - spec/lib/redis_record/config_spec.rb
134
+ - spec/spec_helper.rb