baccigalupi-aqua 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardoc +0 -0
- data/Aqua.gemspec +17 -1
- data/VERSION +1 -1
- data/doc/Aqua.html +12 -12
- data/doc/Aqua/Config.html +1 -1
- data/doc/Aqua/Config/ClassMethods.html +1 -1
- data/doc/Aqua/From.html +107 -0
- data/doc/Aqua/ObjectNotFound.html +1 -1
- data/doc/Aqua/Pack.html +2 -2
- data/doc/Aqua/Pack/ClassMethods.html +4 -4
- data/doc/Aqua/Pack/InstanceMethods.html +379 -17
- data/doc/Aqua/Query.html +1 -1
- data/doc/Aqua/Query/ClassMethods.html +1 -1
- data/doc/Aqua/Query/InstanceMethods.html +1 -1
- data/doc/Aqua/Storage.html +1 -1
- data/doc/Aqua/Store.html +1 -1
- data/doc/Aqua/Store/CouchDB.html +1 -1
- data/doc/Aqua/Store/CouchDB/Conflict.html +1 -1
- data/doc/Aqua/Store/CouchDB/Database.html +1 -1
- data/doc/Aqua/Store/CouchDB/RequestFailed.html +1 -1
- data/doc/Aqua/Store/CouchDB/RequestTimeout.html +1 -1
- data/doc/Aqua/Store/CouchDB/ResourceNotFound.html +1 -1
- data/doc/Aqua/Store/CouchDB/Server.html +1 -1
- data/doc/Aqua/Store/CouchDB/ServerBrokeConnection.html +1 -1
- data/doc/Aqua/Store/CouchDB/StorageMethods.html +1 -1
- data/doc/Aqua/Store/CouchDB/StorageMethods/ClassMethods.html +1 -1
- data/doc/Aqua/Store/CouchDB/StorageMethods/InstanceMethods.html +7 -7
- data/doc/Aqua/Stub.html +464 -0
- data/doc/Aqua/Tank.html +4 -4
- data/doc/Aqua/TempStub.html +81 -0
- data/doc/Aqua/To.html +179 -0
- data/doc/Aqua/Unpack.html +1 -1
- data/doc/Aqua/Unpack/ClassMethods.html +41 -10
- data/doc/Aqua/Unpack/InstanceMethods.html +1244 -37
- data/doc/Array.html +178 -0
- data/doc/Bignum.html +102 -0
- data/doc/Date.html +102 -0
- data/doc/FalseClass.html +102 -0
- data/doc/Fixnum.html +102 -0
- data/doc/Float.html +102 -0
- data/doc/Hash.html +196 -0
- data/doc/OpenStruct.html +102 -0
- data/doc/README.rdoc.html +10 -1
- data/doc/Rational.html +170 -0
- data/doc/RestAPI.html +1 -1
- data/doc/RestClientAdapter.html +1 -1
- data/doc/Time.html +102 -0
- data/doc/TrueClass.html +102 -0
- data/doc/all-methods.html +252 -0
- data/doc/all-namespaces.html +30 -0
- data/doc/custom.css +3 -5
- data/doc/top-level-namespace.html +1 -1
- data/lib/aqua.rb +1 -0
- data/lib/aqua/object/pack.rb +104 -132
- data/lib/aqua/object/unpack.rb +71 -49
- data/lib/aqua/support/initializers.rb +133 -0
- metadata +17 -1
@@ -0,0 +1,133 @@
|
|
1
|
+
# AQUA INITIALIZATION
|
2
|
+
# Some object store state in a fundamental way, not in instance variables, that needs to be initialized.
|
3
|
+
# Examples: Array, Numeric types, Hashes, Time ...
|
4
|
+
# You can make any object requiring this initialization savable to aqua by adding the following methods:
|
5
|
+
module Aqua
|
6
|
+
module To
|
7
|
+
def to_aqua( base_object )
|
8
|
+
hash = {
|
9
|
+
'class' => self.class.to_s,
|
10
|
+
'init' => to_aqua_init( base_object )
|
11
|
+
}
|
12
|
+
if instance_variables.size > 0
|
13
|
+
hash.merge!({ 'ivars' => base_object._pack_ivars( self ) })
|
14
|
+
end
|
15
|
+
hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_aqua_init( base_object )
|
19
|
+
self.to_s
|
20
|
+
end
|
21
|
+
end # To
|
22
|
+
|
23
|
+
module From
|
24
|
+
def aqua_init( init )
|
25
|
+
new( init )
|
26
|
+
end
|
27
|
+
end # From
|
28
|
+
end
|
29
|
+
|
30
|
+
[ TrueClass, FalseClass, Time, Date, Fixnum, Bignum, Float, Rational, Hash, Array, OpenStruct].each do |klass|
|
31
|
+
klass.class_eval do
|
32
|
+
include Aqua::To
|
33
|
+
extend Aqua::From
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TrueClass
|
38
|
+
def self.aqua_init( init )
|
39
|
+
true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class FalseClass
|
44
|
+
def self.aqua_init( init )
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Date
|
50
|
+
def self.aqua_init( init )
|
51
|
+
parse( init )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Time
|
56
|
+
def self.aqua_init( init )
|
57
|
+
parse( init )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Fixnum
|
62
|
+
def self.aqua_init( init )
|
63
|
+
init.to_i
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Bignum
|
68
|
+
def self.aqua_init( init )
|
69
|
+
init.to_i
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Float
|
74
|
+
def self.aqua_init( init )
|
75
|
+
init.to_f
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Rational
|
80
|
+
def to_aqua_init( base_object )
|
81
|
+
self.to_s.match(/(\d*)\/(\d*)/).to_a.slice(1,2)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.aqua_init( init )
|
85
|
+
Rational( init[0].to_i, init[1].to_i )
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class Hash
|
90
|
+
def to_aqua_init( base_object )
|
91
|
+
return_hash = {}
|
92
|
+
self.each do |raw_key, value|
|
93
|
+
key_class = raw_key.class
|
94
|
+
if key_class == Symbol
|
95
|
+
key = ":#{raw_key.to_s}"
|
96
|
+
elsif key_class == String
|
97
|
+
key = raw_key
|
98
|
+
else
|
99
|
+
index = base_object._build_object_key( raw_key )
|
100
|
+
key = "/OBJECT_#{index}"
|
101
|
+
end
|
102
|
+
return_hash[key] = base_object._pack_object( value )
|
103
|
+
end
|
104
|
+
return_hash
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.aqua_init( init )
|
108
|
+
new.replace( init )
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Array
|
113
|
+
def to_aqua_init( base_object )
|
114
|
+
return_arr = []
|
115
|
+
self.each do |obj|
|
116
|
+
return_arr << base_object._pack_object( obj )
|
117
|
+
end
|
118
|
+
return_arr
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.aqua_init( init )
|
122
|
+
new.replace( init )
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class OpenStruct
|
127
|
+
def to_aqua_init( base_object )
|
128
|
+
instance_variable_get("@table").to_aqua_init( base_object )
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baccigalupi-aqua
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kane Baccigalupi
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- doc/Aqua.html
|
36
36
|
- doc/Aqua/Config.html
|
37
37
|
- doc/Aqua/Config/ClassMethods.html
|
38
|
+
- doc/Aqua/From.html
|
38
39
|
- doc/Aqua/ObjectNotFound.html
|
39
40
|
- doc/Aqua/Pack.html
|
40
41
|
- doc/Aqua/Pack/ClassMethods.html
|
@@ -55,13 +56,27 @@ files:
|
|
55
56
|
- doc/Aqua/Store/CouchDB/StorageMethods.html
|
56
57
|
- doc/Aqua/Store/CouchDB/StorageMethods/ClassMethods.html
|
57
58
|
- doc/Aqua/Store/CouchDB/StorageMethods/InstanceMethods.html
|
59
|
+
- doc/Aqua/Stub.html
|
58
60
|
- doc/Aqua/Tank.html
|
61
|
+
- doc/Aqua/TempStub.html
|
62
|
+
- doc/Aqua/To.html
|
59
63
|
- doc/Aqua/Unpack.html
|
60
64
|
- doc/Aqua/Unpack/ClassMethods.html
|
61
65
|
- doc/Aqua/Unpack/InstanceMethods.html
|
66
|
+
- doc/Array.html
|
67
|
+
- doc/Bignum.html
|
68
|
+
- doc/Date.html
|
69
|
+
- doc/FalseClass.html
|
70
|
+
- doc/Fixnum.html
|
71
|
+
- doc/Float.html
|
72
|
+
- doc/Hash.html
|
73
|
+
- doc/OpenStruct.html
|
62
74
|
- doc/README.rdoc.html
|
75
|
+
- doc/Rational.html
|
63
76
|
- doc/RestAPI.html
|
64
77
|
- doc/RestClientAdapter.html
|
78
|
+
- doc/Time.html
|
79
|
+
- doc/TrueClass.html
|
65
80
|
- doc/all-files.html
|
66
81
|
- doc/all-methods.html
|
67
82
|
- doc/all-namespaces.html
|
@@ -90,6 +105,7 @@ files:
|
|
90
105
|
- lib/aqua/store/couch_db/server.rb
|
91
106
|
- lib/aqua/store/couch_db/storage_methods.rb
|
92
107
|
- lib/aqua/store/storage.rb
|
108
|
+
- lib/aqua/support/initializers.rb
|
93
109
|
- lib/aqua/support/mash.rb
|
94
110
|
- lib/aqua/support/string_extensions.rb
|
95
111
|
- spec/aqua_spec.rb
|