redis_object 1.2.3 → 1.2.4

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzUwMjBmYTE3ZDljZGMxMmE4MzBlNmQ5ZDQxNmUxNTAyMDU0ZGEzZA==
4
+ ZWZkNGY4Y2M4ZjI3YzEwY2NlMzgyNDlkNTBmMjc0ODY1NjUwZDhhMw==
5
5
  data.tar.gz: !binary |-
6
- ZjRkOTMzMzI0ZGMwOWY1NDY0ZWUzMjg4ODhjZjc5NjVlYWRjNjY5Mw==
6
+ ZmExZDRhNDYwNWU3NjI2N2U4OTgyMGE4MTE2Yzg4NjNhNWQ5MDhmOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Yjk2NWJhOGNlZTQ3ZWVkYzAzMTJkNDZmMTA0NDA1ZDNmN2Y3MmJkMGNjMWIw
10
- MzMzZmU1NTc1MmZkMTkzYTdlMDgzZjNkMGVlOGNhMzZiOWY4YjQ2YTVlNjVj
11
- YjAxOTNkMGY0NTgwZWE2MWZkNDk5Yzk4NTcxMzA1ZjUzM2Y2NWM=
9
+ NjI1ZjUyNGEyNzY0NTUxODljNmJhNTBiODcyNzIzNjllYjM5NjdmNmM4MGM5
10
+ MjRjNjQ1NDVmMTBmZGE4NGE1NGMyMDBkZmY1ZTlhY2ZlYWY1MDg2NmNjNGJi
11
+ ZGE0NDM5ODc5MWFhZWZlYzg2ZmRiNGRmMjVkZWI4ODZhMDM2YjM=
12
12
  data.tar.gz: !binary |-
13
- NWYyMmYxNzk2ZGJiYTQxOTYxYTM3NmNkOTg2MzY2NDJhNDFlOTUxNzQwZWMy
14
- YmU3MTMyZDA4M2Y2N2QxMmI3OGQ3OWRhYjIyNDA2OTIzYTMxMjhlMWFhNWFm
15
- MzNhOGRhMWRjN2MxMzQ4YWE1ODRlZTVkNTRhOGE2YmQ1ZDA4YWE=
13
+ ZDEwYzc3NWRkYWVlYjk2NzFkMjI4MDcxMjVmZGViYTJhZDk5MDdmODkwMjQ5
14
+ NWVjNjg4MjE1MDRmMjE5ZmUzMjRkNTM5NDlkMDE0YmE5MTY3YjMxNjIwNTc2
15
+ OTJhZDI2YWZiYmM0M2JmNDU0YWQ1ODQyYThhNTRjODhjMmY2Yzc=
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
4
5
  env:
5
6
  - "TEST_DB=14"
data/Gemfile CHANGED
@@ -4,6 +4,11 @@ group :test do
4
4
  gem 'rake'
5
5
  gem 'rspec'
6
6
  gem 'coveralls', require: false
7
+ gem 'fuubar'
8
+ end
9
+
10
+ group :development, :test do
11
+ gem 'guard-rspec'
7
12
  end
8
13
 
9
14
  # Specify your gem's dependencies in redis_object.gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', cli: "--format Fuubar --color" do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/README.markdown CHANGED
@@ -4,6 +4,7 @@ RedisObject is a fast and simple-to-use object persistence layer for Ruby.
4
4
  [![Build Status](https://travis-ci.org/remotezygote/RedisObject.png?branch=master)](https://travis-ci.org/remotezygote/RedisObject)
5
5
  [![Coverage Status](https://coveralls.io/repos/remotezygote/RedisObject/badge.png?branch=master)](https://coveralls.io/r/remotezygote/RedisObject?branch=master)
6
6
  [![Code Climate](https://codeclimate.com/github/remotezygote/RedisObject.png)](https://codeclimate.com/github/remotezygote/RedisObject)
7
+ [![Dependency Status](https://gemnasium.com/remotezygote/RedisObject.png)](https://gemnasium.com/remotezygote/RedisObject)
7
8
 
8
9
  ## Prerequisites
9
10
  You'll need [Redis](http://redis.io). Other storage adapters are in the works. Maybe.
data/lib/redis_object.rb CHANGED
@@ -14,7 +14,7 @@ require "redis_object/defaults"
14
14
  require "redis_object/collection"
15
15
  require "redis_object/indices"
16
16
  require "redis_object/timestamps"
17
- require "redis_object/experimental/history"
17
+ require "redis_object/experimental/dumping"
18
18
  require "redis_object/ext/views"
19
19
  require "redis_object/ext/view_caching"
20
20
  require "redis_object/ext/triggers"
@@ -38,8 +38,8 @@ module Seabright
38
38
  include Seabright::Views
39
39
  include Seabright::ViewCaching
40
40
  include Seabright::Timestamps
41
- include Seabright::History
42
41
  include Seabright::Benchmark
42
+ include Seabright::Dumping
43
43
 
44
44
  end
45
45
  end
@@ -25,9 +25,10 @@ module Seabright
25
25
  self.class.reserve(k)
26
26
  end
27
27
 
28
- def to_json
29
- Yajl::Encoder.encode(actual)
30
- end
28
+ # oved this to the dumper module in experimental - remove when it gets to base
29
+ # def to_json
30
+ # Yajl::Encoder.encode(actual)
31
+ # end
31
32
 
32
33
  def id
33
34
  @id || get(id_sym) || set(id_sym, generate_id)
@@ -188,14 +189,15 @@ module Seabright
188
189
  "#{cls.split('::').last.downcase}_id".to_sym
189
190
  end
190
191
 
191
- def load_all_hash_values
192
- @cached_hash_values = store.hgetall(hkey)
193
- cached_hash_values.keys.dup.each do |key|
194
- next if key == "class"
195
- define_setter_getter(key)
196
- end
197
- end
198
-
192
+ # Not used yet...
193
+ # def load_all_hash_values
194
+ # @cached_hash_values = store.hgetall(hkey)
195
+ # cached_hash_values.keys.dup.each do |key|
196
+ # next if key == "class"
197
+ # define_setter_getter(key)
198
+ # end
199
+ # end
200
+ #
199
201
  def cached_hash_values
200
202
  @cached_hash_values ||= {}
201
203
  end
@@ -127,6 +127,13 @@ module Seabright
127
127
  v
128
128
  end
129
129
 
130
+ def collect_type_by_key(col,*keys)
131
+ collect = get_collection(col)
132
+ keys.each do |k|
133
+ collect << k
134
+ end
135
+ end
136
+
130
137
  module ClassMethods
131
138
 
132
139
  def hkey_col(ident = nil)
@@ -0,0 +1,95 @@
1
+ require 'psych'
2
+ require 'active_support/core_ext/time/calculations'
3
+
4
+ module Seabright
5
+ class RedisObject
6
+
7
+ def self.dump_everything(file=nil)
8
+ out = {}
9
+ ObjectSpace.enum_for(:each_object, class << RedisObject; self; end).each do |cls|
10
+ unless cls == RedisObject
11
+ out[cls.name] = {}
12
+ out[cls.name][:objects] = cls.all.map do |obj|
13
+ obj.full_hash_dump
14
+ end
15
+ end
16
+ end
17
+ Psych.dump(out)
18
+ end
19
+
20
+ def self.load_dump(str)
21
+ Psych.load(str).each do |(k,v)|
22
+ if klass = RedisObject.deep_const_get(k)
23
+ if v[:objects]
24
+ v[:objects].each do |o|
25
+ load_object klass, o
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.load_object(klass,pkt)
33
+ puts "Loading a #{klass.name}: #{pkt.inspect}" if DEBUG
34
+ cols = nil
35
+ pkt.delete(:collections).each do |col_name|
36
+ if objs = pkt.delete(col_name.to_sym)
37
+ cols ||= {}
38
+ cols[col_name.to_sym] = objs
39
+ end
40
+ end
41
+ obj = klass.create(pkt)
42
+ if cols
43
+ cols.each do |name,objs|
44
+ puts " Loading in collected #{name}: #{objs.inspect}" if DEBUG
45
+ obj.collect_type_by_key name, *objs
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ module Dumping
53
+
54
+ # def dump(file=nil)
55
+ # if file && File.exists?(file)
56
+ # #
57
+ # else
58
+ # self.to_yaml
59
+ # end
60
+ # end
61
+
62
+ def full_hash_dump
63
+ store.hgetall(hkey).inject({}) {|acc,(k,v)| acc[k.to_sym] = enforce_format(k,v); acc }.merge(dump_collections)
64
+ end
65
+
66
+ def dump_collections
67
+ cols = []
68
+ collections.inject({}) do |acc,(k,v)|
69
+ acc[k.to_sym] = v.map {|o| o.hkey }
70
+ cols << k
71
+ acc
72
+ end.merge(collections: cols)
73
+ end
74
+
75
+ def to_json
76
+ Yajl::Encoder.encode(full_hash_dump)
77
+ end
78
+
79
+ def to_yaml
80
+ Psych.dump(full_hash_dump)
81
+ end
82
+ alias_method :to_yml, :to_yaml
83
+
84
+ module ClassMethods
85
+
86
+
87
+
88
+ end
89
+
90
+ def self.included(base)
91
+ base.extend(ClassMethods)
92
+ end
93
+
94
+ end
95
+ end
@@ -3,7 +3,7 @@ module Seabright
3
3
  class Adapter
4
4
 
5
5
  def initialize(config={})
6
- @config = config
6
+ configure config
7
7
  end
8
8
 
9
9
  def configure(conf)
@@ -38,7 +38,6 @@ module Seabright
38
38
  end
39
39
 
40
40
  def new_connection
41
- true
42
41
  end
43
42
 
44
43
  end
@@ -27,9 +27,12 @@ module Seabright
27
27
  File.open(file,'wb') do |f|
28
28
  keys = connection.send(:keys,"*")
29
29
  f.write keys.map {|k|
30
- v = connection.dump(k)
31
- v.force_encoding(Encoding::BINARY)
32
- [k,v].join(DUMP_SEPARATOR)
30
+ if v = connection.dump(k)
31
+ v.force_encoding(Encoding::BINARY)
32
+ [k,v].join(DUMP_SEPARATOR)
33
+ else
34
+ ""
35
+ end
33
36
  }.join(REC_SEPARATOR)
34
37
  end
35
38
  end
@@ -1,5 +1,5 @@
1
1
  module Seabright
2
2
  class RedisObject
3
- VERSION = "1.2.3"
3
+ VERSION = "1.2.4"
4
4
  end
5
5
  end
data/redis_object.gemspec CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
  s.required_ruby_version = '>= 1.9.2'
22
- s.add_dependency "utf8_utils"
23
- s.add_dependency "redis"
24
- s.add_dependency "yajl-ruby"
25
- s.add_dependency "activesupport"
22
+ s.add_dependency "utf8_utils", ">= 2.0.1"
23
+ s.add_dependency "redis", ">= 3.0.4"
24
+ s.add_dependency "yajl-ruby", ">= 1.1.0"
25
+ s.add_dependency "activesupport", ">= 3.2.13"
26
+ s.add_dependency "psych", "= 1.3.4"
26
27
  end
data/spec/base_spec.rb CHANGED
@@ -87,4 +87,16 @@ describe RedisObject do
87
87
  ObjectTests::User.find("test").should be_nil
88
88
  end
89
89
 
90
+ it "can dump itself raw-ly" do
91
+ obj = ObjectTests::User.create("testy")
92
+ obj.test = true
93
+ obj.raw.should be_a(Hash)
94
+ end
95
+
96
+ it "can iterate through instances with each" do
97
+ ObjectTests::User.each do |obj|
98
+ obj.should be_a(ObjectTests::User)
99
+ end
100
+ end
101
+
90
102
  end
@@ -19,7 +19,7 @@ module CollectionSpec
19
19
  GrandDad << @dad
20
20
  @granddad << @dad
21
21
  @granddad << @son
22
- @dad << @son
22
+ @dad.push @son
23
23
  @dad.push @sonny
24
24
  @son.reference @grandson
25
25
 
@@ -30,6 +30,7 @@ module CollectionSpec
30
30
  @granddad.daddies.count.should eq(1)
31
31
  @granddad.sons.count.should eq(1)
32
32
  @dad.sons.count.should eq(2)
33
+ @dad.sons.push Son.create
33
34
 
34
35
  end
35
36
 
@@ -61,6 +62,10 @@ module CollectionSpec
61
62
 
62
63
  @dad = Daddy.find("dad")
63
64
  @dad.sons.find(son_id: "sonny").first.should be_a(Son)
65
+ @dad.sons[0].should be_a(Son)
66
+ @dad.sons.first.should be_a(Son)
67
+ @dad.sons.last.should be_a(Son)
68
+ @dad.sons.objects.first.should be_a(Son)
64
69
 
65
70
  end
66
71
 
@@ -113,6 +118,22 @@ module CollectionSpec
113
118
 
114
119
  end
115
120
 
121
+ it "can delete a collection another way" do
122
+
123
+ @dad.remove_collection! :sons
124
+ @dad.collections.keys.should_not include(:sons)
125
+ @son.remove_collection!(:grand_sons)
126
+ @son.collections.keys.should_not include(:grand_sons)
127
+
128
+ end
129
+
130
+ it "can select a block of objects" do
131
+
132
+ i = @dad.sons.last.id
133
+ @dad.sons.select {|o| o.id == i }.count.should > 0
134
+
135
+ end
136
+
116
137
  it "retrieves via index" do
117
138
 
118
139
  5.times do
@@ -140,5 +161,16 @@ module CollectionSpec
140
161
 
141
162
  end
142
163
 
164
+ it "can remove a collection from a class itself" do
165
+
166
+ 5.times do
167
+ Daddy.push Son.create
168
+ end
169
+
170
+ Daddy.remove_collection! :sons
171
+ # Daddy.get(:sons).indexed(:created_at,3,true).count.should eq(3)
172
+
173
+ end
174
+
143
175
  end
144
176
  end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ module DumpingSpec
4
+
5
+ class DumpableObject < RedisObject
6
+
7
+ int :phone
8
+ bool :mailed
9
+ date :canceled_at
10
+
11
+ end
12
+
13
+ class GenericObject < RedisObject
14
+
15
+ json :complex
16
+
17
+ end
18
+
19
+ describe Seabright::Triggers do
20
+ before do
21
+ RedisObject.store.flushdb
22
+ 5.times do
23
+ d = DumpableObject.create(phone: Random.rand(100)*555, mailed: true, canceled_at: Time.now)
24
+ d << GenericObject.create(complex: {woot: true, ohnoes: false})
25
+ end
26
+ end
27
+
28
+ it "can dump an object" do
29
+
30
+ r = DumpableObject.latest.to_yaml
31
+ r.size.should > 100
32
+
33
+ end
34
+
35
+ it "can dump to json" do
36
+
37
+ r = DumpableObject.latest.to_json
38
+ r.size.should > 100
39
+
40
+ end
41
+
42
+ it "can dump errthing" do
43
+
44
+ r = RedisObject.dump_everything
45
+ r.size.should > 100
46
+
47
+ end
48
+
49
+ it "can load back in a dump" do
50
+
51
+ r = RedisObject.dump_everything
52
+ r.size.should > 100
53
+ RedisObject.store.flushdb
54
+ RedisObject.load_dump r
55
+ DumpableObject.latest.generic_objects.count.should eq(1)
56
+
57
+ end
58
+
59
+ end
60
+ end
data/spec/indices_spec.rb CHANGED
@@ -38,6 +38,9 @@ module IndexSpec
38
38
  end
39
39
 
40
40
  IndexedObject.indexed(:a_number,3,true).count.should eq(3)
41
+ IndexedObject.indexed(:a_number,3,true) do |o|
42
+ o.should be_a(IndexedObject)
43
+ end
41
44
 
42
45
  end
43
46
 
data/spec/spec_helper.rb CHANGED
@@ -14,8 +14,12 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
14
  ]
15
15
  SimpleCov.start do
16
16
  add_filter "_spec.rb"
17
- add_filter "/experimental/"
17
+ # add_filter "/experimental/"
18
18
  add_group "Extensions", "lib/redis_object/ext/"
19
+ add_group "Experimental", "lib/redis_object/experimental/" do |fl|
20
+ !/_untested/.match(fl)
21
+ end
22
+ maximum_coverage_drop 5
19
23
  end
20
24
 
21
25
  require 'redis_object'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bragg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: utf8_utils
@@ -16,56 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.0.1
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
- version: '0'
26
+ version: 2.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 3.0.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 3.0.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yajl-ruby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.2.13
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.2.13
69
+ - !ruby/object:Gem::Dependency
70
+ name: psych
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.4
69
83
  description: ''
70
84
  email:
71
85
  - john@seabrightstudios.com
@@ -75,15 +89,18 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - .coveralls.yml
77
91
  - .gitignore
92
+ - .rspec
78
93
  - .travis.yml
79
94
  - Gemfile
95
+ - Guardfile
80
96
  - README.markdown
81
97
  - Rakefile
82
98
  - lib/redis_object.rb
83
99
  - lib/redis_object/base.rb
84
100
  - lib/redis_object/collection.rb
85
101
  - lib/redis_object/defaults.rb
86
- - lib/redis_object/experimental/history.rb
102
+ - lib/redis_object/experimental/dumping.rb
103
+ - lib/redis_object/experimental/history_untested.rb
87
104
  - lib/redis_object/ext/benchmark.rb
88
105
  - lib/redis_object/ext/cleaner.rb
89
106
  - lib/redis_object/ext/filters.rb
@@ -118,6 +135,7 @@ files:
118
135
  - spec/benchmark_spec.rb
119
136
  - spec/collections_spec.rb
120
137
  - spec/defaults_spec.rb
138
+ - spec/dumping_spec.rb
121
139
  - spec/field_ref_spec.rb
122
140
  - spec/filters_spec.rb
123
141
  - spec/indices_spec.rb
@@ -159,6 +177,7 @@ test_files:
159
177
  - spec/benchmark_spec.rb
160
178
  - spec/collections_spec.rb
161
179
  - spec/defaults_spec.rb
180
+ - spec/dumping_spec.rb
162
181
  - spec/field_ref_spec.rb
163
182
  - spec/filters_spec.rb
164
183
  - spec/indices_spec.rb