saver 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +2 -4
- data/Rakefile +10 -0
- data/lib/saver.rb +4 -5
- data/lib/saver/version.rb +1 -1
- data/saver.gemspec +6 -1
- data/spec/spec_helper.rb +8 -0
- data/spec/unit/saver_spec.rb +67 -0
- metadata +82 -29
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Saver
|
2
2
|
|
3
|
+
[![Build Status](http://travis-ci.org/Kelsin/saver.png)](http://travis-ci.org/Kelsin/saver)
|
4
|
+
|
3
5
|
This gem lets you easily add text columns to your mongo mapper (only for now)
|
4
6
|
models. We use this gem to save logging information for one of our web apps. In
|
5
7
|
the future if the associations break, you'll still have a text version of the
|
@@ -35,7 +37,3 @@ Now when we save our model we get data like this:
|
|
35
37
|
:card_id => 2,
|
36
38
|
:card_saver => 'Card 45 with $50.00 on it'
|
37
39
|
}
|
38
|
-
|
39
|
-
## Todo
|
40
|
-
|
41
|
-
* Add in tests
|
data/Rakefile
CHANGED
data/lib/saver.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "saver/version"
|
2
|
+
require "active_support"
|
2
3
|
|
3
4
|
module Saver
|
4
5
|
extend ActiveSupport::Concern
|
@@ -24,11 +25,9 @@ module Saver
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
self.
|
30
|
-
self.send("#{attribute}_saver=", self.send(attribute).send(method))
|
31
|
-
end
|
28
|
+
def save_savers
|
29
|
+
self.class.savers.each do |attribute, method|
|
30
|
+
self.send("#{attribute}_saver=", self.send(attribute).send(method))
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
data/lib/saver/version.rb
CHANGED
data/saver.gemspec
CHANGED
@@ -18,5 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency 'activesupport', '~> 3.0
|
21
|
+
s.add_dependency 'activesupport', '~> 3.0'
|
22
|
+
s.add_dependency 'mongo_mapper'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rspec', '~> 2.6.0'
|
25
|
+
s.add_development_dependency 'rake'
|
26
|
+
s.add_development_dependency 'simplecov'
|
22
27
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Saver do
|
4
|
+
class SingleTest
|
5
|
+
include MongoMapper::Document
|
6
|
+
include Saver
|
7
|
+
|
8
|
+
key :data, Integer
|
9
|
+
|
10
|
+
save_attribute :data
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"Number #{self.data}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def long_string
|
17
|
+
"OMG LONG Number #{self.data}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class DoubleTest
|
22
|
+
include MongoMapper::Document
|
23
|
+
include Saver
|
24
|
+
|
25
|
+
key :data, Integer
|
26
|
+
belongs_to :single_test
|
27
|
+
|
28
|
+
save_attributes :data, :single_test
|
29
|
+
end
|
30
|
+
|
31
|
+
class MethodTest
|
32
|
+
include MongoMapper::Document
|
33
|
+
include Saver
|
34
|
+
|
35
|
+
belongs_to :single_test
|
36
|
+
|
37
|
+
save_attribute :single_test, :method => :long_string
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:single_test) { SingleTest.create(:data => 5) }
|
41
|
+
let(:double_test) { DoubleTest.create(:data => 5, :single_test => single_test) }
|
42
|
+
let(:method_test) { MethodTest.create(:single_test => single_test) }
|
43
|
+
|
44
|
+
describe '#savers' do
|
45
|
+
it "should accurately save array of savers" do
|
46
|
+
single_test.class.savers.should == { :data => :to_s }
|
47
|
+
double_test.class.savers.should == { :data => :to_s, :single_test => :to_s }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#save_attribute' do
|
52
|
+
it "should work" do
|
53
|
+
single_test.data_saver.should == '5'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should work with custom method" do
|
57
|
+
method_test.single_test_saver.should == 'OMG LONG Number 5'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#save_attributes' do
|
62
|
+
it "should work" do
|
63
|
+
double_test.data_saver.should == '5'
|
64
|
+
double_test.single_test_saver.should == 'Number 5'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,35 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: saver
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Christopher Giroir
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
|
13
|
+
date: 2012-05-14 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
19
|
none: false
|
19
|
-
requirements:
|
20
|
+
requirements:
|
20
21
|
- - ~>
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 3.0
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "3.0"
|
23
24
|
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mongo_mapper
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.6.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
24
50
|
prerelease: false
|
25
|
-
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: simplecov
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
26
70
|
description: Save a string version of columns automatically
|
27
|
-
email:
|
71
|
+
email:
|
28
72
|
- kelsin@valefor.com
|
29
73
|
executables: []
|
74
|
+
|
30
75
|
extensions: []
|
76
|
+
|
31
77
|
extra_rdoc_files: []
|
32
|
-
|
78
|
+
|
79
|
+
files:
|
33
80
|
- .gitignore
|
34
81
|
- .rvmrc
|
35
82
|
- Gemfile
|
@@ -38,29 +85,35 @@ files:
|
|
38
85
|
- lib/saver.rb
|
39
86
|
- lib/saver/version.rb
|
40
87
|
- saver.gemspec
|
41
|
-
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/unit/saver_spec.rb
|
42
90
|
homepage: http://kelsin.github.com/saver/
|
43
91
|
licenses: []
|
92
|
+
|
44
93
|
post_install_message:
|
45
94
|
rdoc_options: []
|
46
|
-
|
95
|
+
|
96
|
+
require_paths:
|
47
97
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
99
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
105
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version:
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: "0"
|
60
110
|
requirements: []
|
111
|
+
|
61
112
|
rubyforge_project: saver
|
62
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.8.17
|
63
114
|
signing_key:
|
64
115
|
specification_version: 3
|
65
116
|
summary: Save a string version of columns automatically
|
66
|
-
test_files:
|
117
|
+
test_files:
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/unit/saver_spec.rb
|