ozy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +50 -27
  2. data/lib/ozy.rb +3 -0
  3. metadata +3 -3
data/README.md CHANGED
@@ -1,53 +1,76 @@
1
- Addressabler
1
+ Ozymandias
2
2
  =
3
3
 
4
- **Addressabler** extends the Addressable::URI class by adding TLD parsing, domain and subdomain parsing, and query modification.
4
+ **Ozy** is a simple Hash subclass that persists itself to Redis, if you'll let it. This provides a clean interface to storing data in Redis without calling all those crazy Redis commands. Of course, Ozy also supports those commands, so go nuts.
5
5
 
6
6
  Install
7
7
  ==
8
8
 
9
9
  Install using Rubygems:
10
10
 
11
- gem install addressabler
11
+ gem install ozy
12
12
 
13
13
  Then:
14
14
 
15
15
  require 'rubygems'
16
- require 'addressabler'
17
-
18
- Addressabler will automatically require `addressable/uri`.
16
+ require 'ozy'
19
17
 
20
18
  Usage
21
19
  ==
22
20
 
23
- Use Addressable::URI like you normally would:
21
+ Ozy's are just Hashes, but accept a hash for its initialization:
22
+
23
+ @ozy = Ozy.new(:foo => :bar)
24
+
25
+ Persistence
26
+ ===
27
+
28
+ An Ozy won't persist until you tell it to by calling "save" and passing it a key:
29
+
30
+ @ozy.save(:key)
31
+
32
+ You can get an Ozy using that key:
33
+
34
+ Ozy.get(:key) #=> key: {:foo => :bar}
35
+
36
+ Expiration
37
+ ===
38
+ You can pass an options hash into an Ozy initializer as well. Currently, the only supported option is `expire`:
39
+
40
+ @ozy = Ozy.new({:foo => :bar}, :expire => 60)
41
+ @ozy.expires_in #=> 60
42
+
43
+ Ozy's expiration times won't start ticking down until you save them. Cause they're not in Redis yet. Are you getting it?
24
44
 
25
- @uri = Addressable::URI.parse("http://www.google.com/")
26
- @uri.host #=> "www.google.com"
45
+ @ozy.save(:key)
46
+ sleep 1
47
+ @ozy.expires_in #=> 59
27
48
 
28
- Addressabler will add the following properties:
49
+ You can extend an Ozy's expiration like so:
29
50
 
30
- @uri.tld #=> "com"
31
- @uri.domain #=> "google"
32
- @uri.subdomain #=> "www"
51
+ @ozy.expire_in! 120
52
+ @ozy.expires_in #=> 120
33
53
 
34
- You can set these values, as well:
54
+ Automatic Persistence
55
+ ===
56
+ Changes made to a saved Ozy will automatically persist to Redis without calling save again:
35
57
 
36
- @uri.tld = "org"
37
- @uri.host #=> "www.google.org"
38
- @uri.domain = "amazon"
39
- @uri.host #=> "www.amazon.org"
40
- @uri.subdomain = "developers"
41
- @uri.host #=> "developers.amazon.org"
58
+ @ozy = Ozy.new(:foo => :bar)
59
+ @ozy.save(:key)
60
+ @ozy.merge!(:foo => :baz)
61
+ @ozy[:your] = :mom
62
+ Ozy.get(:key) #=> foo: {:foo => :baz, :your => :mom}
42
63
 
43
- Addressabler copies some of Paul Dix's [Domaintrix](https://github.com/pauldix/domainatrix) TLD code to support fancy TLDs, as well:
64
+ If you want to skip the whole "save" thing, just call Ozy.create(key, attributes):
44
65
 
45
- @uri.host = "www.google.co.uk"
46
- @uri.tld #=> "co.uk"
66
+ @ozy = Ozy.create(:key, :i_will => :hunt_ed)
67
+ Ozy.get(:key) #=> key: {:i_will => :hunt_ed}
47
68
 
48
- Addressabler also makes editing queries a little bit easier:
69
+ Redis Commands
70
+ ===
71
+ Ozy's accept any key-based Redis command, as well. Example:
49
72
 
50
- @uri.query_hash[:foo] = :bar
51
- @uri.to_s #=> "http://www.google.co.uk/?foo=bar"
73
+ @ozy.del
74
+ Ozy.get(:key) #=> nil
52
75
 
53
- That's it. Enjoy.
76
+ And... that's it!
data/lib/ozy.rb CHANGED
@@ -58,6 +58,9 @@ class Ozy < ::Hash
58
58
 
59
59
  def initialize(attributes = {}, options = {})
60
60
  @options = options
61
+ if @options[:key]
62
+ @persisted = true
63
+ end
61
64
  merge! attributes unless attributes.empty?
62
65
  end
63
66
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ozy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Flip Sasser