quick_state 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.
Files changed (2) hide show
  1. data/lib/quick_state.rb +31 -0
  2. metadata +61 -0
@@ -0,0 +1,31 @@
1
+ class QuickState
2
+ attr_accessor :autosave
3
+
4
+ def initialize(file_path=nil)
5
+ @file_path = file_path || "#{$0}.state"
6
+ if File.exist?(@file_path)
7
+ @data = Marshal.load(File.read(@file_path))
8
+ else
9
+ @data = {}
10
+ end
11
+ end
12
+
13
+ def [](key)
14
+ @data[key]
15
+ end
16
+
17
+ def []=(key,val)
18
+ @data[key] = val
19
+ save if autosave
20
+ val
21
+ end
22
+
23
+ def save
24
+ File.open(@file_path, "w") {|f| Marshal.dump(@data, f); f.fsync}
25
+ end
26
+
27
+ def autosave!
28
+ self.autosave = true
29
+ self
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quick_state
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Eric Mason
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-06-16 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description:
21
+ email: eric@ericmason.net
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/quick_state.rb
30
+ has_rdoc: true
31
+ homepage: https://github.com/ericmason/quick_state
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ requirements:
54
+ - none
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.6
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Quick way to store application state.
60
+ test_files: []
61
+