perobs 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cea78483599ce586c57310a9d4aa622b3bfc3ca2
4
- data.tar.gz: febaf3328e7a157a38529507a4a5a91a0bc49d2e
3
+ metadata.gz: a2fdb476312688171e078295e7b128663885249e
4
+ data.tar.gz: 26b0422a60677e6120ded2ff43943a8b805304ca
5
5
  SHA512:
6
- metadata.gz: 6be86d3f49ff2e7bb816d7a6a257f07642b01cd8bdb94636fc2ccbd571fd225e0cd281786372051fc940f84f5440001ab5519994980775bd710c73fef59cffeb
7
- data.tar.gz: fc1632708462f8f81b15f28f8a0226d49521443bf6fc6a0b0f1470efcec0a9f81412a08093f956718d84ab9e02b3c5f6e31fa37fa9da3b949250f8c5904a8200
6
+ metadata.gz: b415f4d0e12b9fd5e62ec6bc801911651970b70fcb52609a2f24c2d13b86bdcaa668207ac4723589ca8538950da9ddea23aae221e0d1b321c07574c2d211e619
7
+ data.tar.gz: e52498a83b9a21bc6514ec6e61d6ca310d9054ec68801042e4ed65cda8f6a4276bfd3e6b325daf22d6fa79084b787b72cabc77cddda6a0bf6679f1a83148d3c6
data/README.md CHANGED
@@ -19,14 +19,14 @@ raised.
19
19
  It features a garbage collector that removes all objects that are no
20
20
  longer in use. A build-in cache keeps access latencies to recently
21
21
  used objects low and lazily flushes modified objects into the
22
- persistend back-end.
22
+ persistend back-end when not using transactions.
23
23
 
24
24
  Persistent objects must be created by deriving your class from
25
25
  PEROBS::Object. Only instance variables that are declared via
26
- po_attr will be persistent. All objects that are stored in persitant
27
- instance variables must provide a to_json method that generates JSON
28
- syntax that can be parsed into their original object again. It is
29
- recommended that references to other objects are all going to persistent
26
+ po_attr will be persistent. All objects that are stored in persistent
27
+ instance variables must provide a to_json() method that generates JSON
28
+ syntax that can be also parsed into their original object again. It is
29
+ required that references to other objects are all going to persistent
30
30
  objects again.
31
31
 
32
32
  There are currently 3 kinds of persistent objects available:
@@ -40,12 +40,11 @@ There are currently 3 kinds of persistent objects available:
40
40
  * PEROBS::Hash provides an interface similar to the built-in Hash
41
41
  class but its objects are automatically stored.
42
42
 
43
- In addition to these classes, you also need to create a PEROBS::Store
44
- object that owns your persistent objects. The store provides the
45
- persistent database. If you are using the default serializer (JSON),
46
- you can only use the subset of Ruby types that JSON supports.
47
- Alternatively, you can use Marshal or YAML which support almost every
48
- Ruby data type.
43
+ You must create at least one PEROBS::Store object that owns your
44
+ persistent objects. The store provides the persistent database. If you
45
+ are using the default serializer (JSON), you can only use the subset
46
+ of Ruby types that JSON supports. Alternatively, you can use Marshal
47
+ or YAML which support almost every Ruby data type.
49
48
 
50
49
  Here is an example how to use PEROBS. Let's define a class that models
51
50
  a person with their family relations.
@@ -55,17 +54,23 @@ require 'perobs'
55
54
 
56
55
  class Person < PEROBS::Object
57
56
 
58
- po_attr :name, :mother, :father, :kids
57
+ po_attr :name, :mother, :father, :kids, :spouse, :status
59
58
 
60
59
  def initialize(store, name)
61
60
  super
62
61
  attr_init(:name, name)
63
62
  attr_init(:kids, store.new(PEROBS::Array))
63
+ attr_init(:status, :single)
64
+ end
65
+
66
+ def merry(spouse)
67
+ self.spouse = spouse
68
+ self.status = :married
64
69
  end
65
70
 
66
71
  def to_s
67
- "#{@name} is the child of #{self.mother ? self.mother.name : 'unknown'} " +
68
- "and #{self.father ? self.father.name : 'unknown'}.
72
+ "#{@name} is the child of #{@mother ? @mother.name : 'unknown'} " +
73
+ "and #{@father ? @father.name : 'unknown'}.
69
74
  end
70
75
 
71
76
  end
@@ -84,6 +89,23 @@ store.sync
84
89
  When you run this script, a folder named 'family' will be created. It
85
90
  contains the 3 Person objects.
86
91
 
92
+ ### Accessing persistent instance variables
93
+
94
+ All instance variables that should be persisted must be declared with
95
+ 'po_attr'. This will create the instance variable, a getter and setter
96
+ method for it. These getter and setter methods are the recommended way
97
+ to access instance variables both from ouside of the instances as well
98
+ as from within. To access the setter or getter method from within an
99
+ instance method use the self.<variable> notation.
100
+
101
+ The @<variable> notation is also supported, but special care needs to
102
+ be taken when modifying an instance variable. The setter methods will
103
+ automatically take care of persisting the modified instance when
104
+ required. If you use the @ notation for mutating instance variable
105
+ accesses, you must manually mark the instance as modified by calling
106
+ Object::mark_as_modified(). If that is forgotten, the change will
107
+ reside in memory but might not be persisted into the database.
108
+
87
109
  ## Installation
88
110
 
89
111
  Add this line to your application's Gemfile:
@@ -100,6 +122,31 @@ Or install it yourself as:
100
122
 
101
123
  $ gem install perobs
102
124
 
125
+ ## Copyright and License
126
+
127
+ Copyright (c) 2015, 2016 by Chris Schlaeger <chris@taskjuggler.org>
128
+
129
+ PEROBS and all accompanying files are licensed under this MIT License
130
+
131
+ Permission is hereby granted, free of charge, to any person obtaining
132
+ a copy of this software and associated documentation files (the
133
+ "Software"), to deal in the Software without restriction, including
134
+ without limitation the rights to use, copy, modify, merge, publish,
135
+ distribute, sublicense, and/or sell copies of the Software, and to
136
+ permit persons to whom the Software is furnished to do so, subject to
137
+ the following conditions:
138
+
139
+ The above copyright notice and this permission notice shall be
140
+ included in all copies or substantial portions of the Software.
141
+
142
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
143
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
144
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
145
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
146
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
147
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
148
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
149
+
103
150
  ## Contributing
104
151
 
105
152
  1. Fork it ( https://github.com/scrapper/perobs/fork )
data/lib/perobs/Object.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # = Object.rb -- Persistent Ruby Object Store
4
4
  #
5
- # Copyright (c) 2015 by Chris Schlaeger <chris@taskjuggler.org>
5
+ # Copyright (c) 2015, 2016 by Chris Schlaeger <chris@taskjuggler.org>
6
6
  #
7
7
  # MIT License
8
8
  #
@@ -99,6 +99,21 @@ module PEROBS
99
99
  false
100
100
  end
101
101
 
102
+ # Call this method to manually mark the object as modified. This is
103
+ # necessary if you are using the '@' notation to access instance variables
104
+ # during assignment operations (=, +=, -=, etc.). To avoid having to call
105
+ # this method you can use the self. notation.
106
+ #
107
+ # @foo = 42 # faster but requires call to mark_as_modified()
108
+ # self.foo = 42 # somewhat slower
109
+ #
110
+ # IMPORTANT: If you use @foo = ... and forget to call mark_as_modified()
111
+ # your data will only be modified in memory but might not be persisted
112
+ # into the database!
113
+ def mark_as_modified
114
+ @store.cache.cache_write(self)
115
+ end
116
+
102
117
  # Return a list of all object IDs that the attributes of this instance are
103
118
  # referencing.
104
119
  # @return [Array of Fixnum or Bignum] IDs of referenced objects
@@ -142,7 +157,11 @@ module PEROBS
142
157
  "{\n" +
143
158
  _all_attributes.map do |attr|
144
159
  ivar = ('@' + attr.to_s).to_sym
145
- " #{attr.inspect}=>#{instance_variable_get(ivar).inspect}"
160
+ if (value = instance_variable_get(ivar)).respond_to?('is_poxreference?')
161
+ " #{attr}=>#{value.class}:#{value._id}"
162
+ else
163
+ " #{attr}=>#{value}"
164
+ end
146
165
  end.join(",\n") +
147
166
  "\n}\n"
148
167
  end
@@ -1,4 +1,4 @@
1
1
  module PEROBS
2
2
  # The version number
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schlaeger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-19 00:00:00.000000000 Z
11
+ date: 2016-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler