saver 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 +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/lib/saver/version.rb +3 -0
- data/lib/saver.rb +34 -0
- data/saver.gemspec +22 -0
- metadata +66 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@saver --create
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Saver
|
2
|
+
|
3
|
+
This gem lets you easily add text columns to your mongo mapper (only for now)
|
4
|
+
models. We use this gem to save logging information for one of our web apps. In
|
5
|
+
the future if the associations break, you'll still have a text version of the
|
6
|
+
data saved.
|
7
|
+
|
8
|
+
Clearly I'm **not** advocating ever deleting data, but we wanted to use this
|
9
|
+
feature so **if** something happens later on, we'd still have string versions of
|
10
|
+
the data.
|
11
|
+
|
12
|
+
## Example
|
13
|
+
|
14
|
+
Here is a simple class of a log item:
|
15
|
+
|
16
|
+
class LogItem
|
17
|
+
include Saver
|
18
|
+
save_attributes :account, card
|
19
|
+
end
|
20
|
+
|
21
|
+
If you want to use something other than `to_s` to generate the string you can
|
22
|
+
pass the method to use to the singular version of `save_attribute`:
|
23
|
+
|
24
|
+
class LogItem
|
25
|
+
include Saver
|
26
|
+
save_attribute :account
|
27
|
+
save_attribute :card, :method => :card_data
|
28
|
+
end
|
29
|
+
|
30
|
+
Now when we save our model we get data like this:
|
31
|
+
|
32
|
+
LogItem {
|
33
|
+
:account_id => 1,
|
34
|
+
:account_saver => 'Christopher Giroir',
|
35
|
+
:card_id => 2,
|
36
|
+
:card_saver => 'Card 45 with $50.00 on it'
|
37
|
+
}
|
38
|
+
|
39
|
+
## Todo
|
40
|
+
|
41
|
+
* Add in tests
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/saver.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "saver/version"
|
2
|
+
|
3
|
+
module Saver
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before_save :save_savers
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def save_attributes(*attributes)
|
12
|
+
attributes.each do |attr|
|
13
|
+
save_attribute(attr)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_attribute(attribute, options = {})
|
18
|
+
key "#{attribute}_saver", String
|
19
|
+
self.savers[attribute] = options[:method] || :to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def savers
|
23
|
+
@savers ||= {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
def save_savers
|
29
|
+
self.class.savers.each do |attribute, method|
|
30
|
+
self.send("#{attribute}_saver=", self.send(attribute).send(method))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/saver.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "saver/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "saver"
|
7
|
+
s.version = Saver::VERSION
|
8
|
+
s.authors = ["Christopher Giroir"]
|
9
|
+
s.email = ["kelsin@valefor.com"]
|
10
|
+
s.homepage = "https://github.com/Kelsin/saver"
|
11
|
+
s.summary = %q{Save a string version of columns automatically}
|
12
|
+
s.description = %q{Save a string version of columns automatically}
|
13
|
+
|
14
|
+
s.rubyforge_project = "saver"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'activesupport', '~> 3.0.0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: saver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher Giroir
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-17 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: &2164805800 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2164805800
|
26
|
+
description: Save a string version of columns automatically
|
27
|
+
email:
|
28
|
+
- kelsin@valefor.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .rvmrc
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/saver.rb
|
39
|
+
- lib/saver/version.rb
|
40
|
+
- saver.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: https://github.com/Kelsin/saver
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: saver
|
62
|
+
rubygems_version: 1.6.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Save a string version of columns automatically
|
66
|
+
test_files: []
|