data_bank 0.2.0

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Amos L. King
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ lib/data_bank.rb
2
+ MIT-LICENSE
3
+ Rakefile
4
+ README.rdoc
5
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = Data Bank
2
+
3
+ Ever want to save data for later, but don't want the overhead of a database, or parsing large files into objects? With the data bank you can store an object in the same file as the defined class. Data Bank is just a little hack I tried out to learn how to marshal data.
4
+
5
+ == Install
6
+
7
+ gem install Adkron-data_bank --source http://gems.github.com
8
+
9
+ == Example
10
+
11
+ require 'rubygems'
12
+ require 'data_bank'
13
+
14
+ class MyObject
15
+ attr_accessor :data
16
+
17
+ def initialize(data)
18
+ @data = data
19
+ end
20
+ end
21
+
22
+ db = DataBank.new ".", "data_bank.data"
23
+
24
+ my_object = db.withdraw || MyObject.new(1)
25
+ my_object.data += 1
26
+ puts my_object.data
27
+ db.deposit my_object
28
+
29
+
30
+
31
+
32
+ **Copyright (c) 2008 Amos L. King, released under the MIT license**
33
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('data_bank', '0.2.0') do |p|
7
+ p.description = 'Marshal data to be loaded on sequential runs of your script.'
8
+ p.url = 'http://github.com/Adkron/databank'
9
+ p.author = 'Amos King'
10
+ p.email = 'amos.l.king@gmail.com'
11
+ p.ignore_pattern = ['tmp/*', 'script/*', 'example.rb']
12
+ p.development_dependencies = []
13
+ end
14
+
15
+ Dir['#{File.dirname(__FILE__)}/tasks/*.rake'].sort.each
data/data_bank.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{data_bank}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Amos King"]
9
+ s.date = %q{2008-12-19}
10
+ s.description = %q{Marshal data to be loaded on sequential runs of your script.}
11
+ s.email = %q{amos.l.king@gmail.com}
12
+ s.extra_rdoc_files = ["lib/data_bank.rb", "README.rdoc"]
13
+ s.files = ["lib/data_bank.rb", "MIT-LICENSE", "Rakefile", "README.rdoc", "Manifest", "data_bank.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/Adkron/databank}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Data_bank", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{data_bank}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Marshal data to be loaded on sequential runs of your script.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
data/lib/data_bank.rb ADDED
@@ -0,0 +1,36 @@
1
+ # This gem eases data marshaling from one run of a script
2
+ # to the next.
3
+ #
4
+ # Author:: Amos King (mailto:amos.l.king@gmail.com)
5
+ # Copyright:: Copyright (c) 2008 Amos King
6
+ # License:: Released under the MIT license
7
+
8
+ require 'base64'
9
+
10
+ class DataBank
11
+
12
+ # Takes the path and the filename of the data store.
13
+ def initialize(path, filename)
14
+ @path = path
15
+ @filename = filename
16
+ end
17
+
18
+ # Stores a base64 encoded representation of a class at
19
+ # the end of the file specified in initialize. On
20
+ # subsequent calls it will replace the data with the
21
+ # new data passed in.
22
+ def deposit(data)
23
+ File.open("#{@path}/#{@filename}", 'w+') do |file|
24
+ file.write Base64.encode64(Marshal.dump(data))
25
+ end
26
+ end
27
+
28
+ # Loads the data stored at the end of the file form
29
+ # which it is called. If data is present.
30
+ def withdraw
31
+ if File.exists?("#{@path}/#{@filename}")
32
+ data = File.read "#{@path}/#{@filename}"
33
+ Marshal.load(Base64.decode64(data)) rescue NameError
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_bank
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Amos King
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-19 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Marshal data to be loaded on sequential runs of your script.
17
+ email: amos.l.king@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/data_bank.rb
24
+ - README.rdoc
25
+ files:
26
+ - lib/data_bank.rb
27
+ - MIT-LICENSE
28
+ - Rakefile
29
+ - README.rdoc
30
+ - Manifest
31
+ - data_bank.gemspec
32
+ has_rdoc: true
33
+ homepage: http://github.com/Adkron/databank
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --line-numbers
39
+ - --inline-source
40
+ - --title
41
+ - Data_bank
42
+ - --main
43
+ - README.rdoc
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "1.2"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project: data_bank
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Marshal data to be loaded on sequential runs of your script.
65
+ test_files: []
66
+