mem_model 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzRmZDhkYTI1YTQ4MjUwZDEzMDcxZmQ2YjM3YjRmYjUxM2UzNzQxZg==
4
+ MjdiMTBhMWRhMGZmMWRkMDlkOGEwODJmNDUzYmJmOWFkODU0ZWJkZA==
5
5
  data.tar.gz: !binary |-
6
- ZWNjODQxZGM3MjRlMjg3OTY2ODBlMGFhYWQ3MzUzYmFjNDQ0MDhmYw==
6
+ ZjM2OTc3OWQ1ODlmOTJjZGQ4NDY3MDliNDlkMWQ3MTdlOTc5ZDlhNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTBjNDdhM2ZkYTc5NjkzMTQ1MTJjZGYwMDE5YWU3ZGYxMDMwY2RhMWI5ZjRh
10
- MGY3MzY4ZGVlYmVhNmQwNTBiZDVlYjZmMzAzZmQ2MzVmZjRmNjZmNDhjZGQ5
11
- OTA5YjZkMGM3MmJiNDdlNjA5ZjViMDhjMDkyZTg5ZTY3ZGNhYmE=
9
+ MTUzOTMwN2ViZjM1Y2Q4N2VhZDU4OWRkZDAyYjJkZjZiNjhlNGFjY2U2Y2Y2
10
+ YzY4YmEyYjY2MGYyZmJmNTM2MGVhN2NkZGU0MTFkNTUyNmI0NjBlNTM3MjMx
11
+ OWU5YTg2ZTgxMDI4MmUyOTk4MjM1YjJkNzVjZjk0ZDBmNzUxZGY=
12
12
  data.tar.gz: !binary |-
13
- Njk1ZWUzNGVkYjdiODFhODY4NDZiMDFlMmY1MzU5M2RmZDJlMGRhZjRmNjNk
14
- NWExM2Y1M2ZkY2EwNzk4NGQ1NWU1ODU5YzAwNjM5ZjY4NTNmZjgzMWU0ZDU4
15
- MzY2YTJjMDI5NjFjMDFjZDVjZjU5M2IxMDQwZDY0NDIzZTBkMmQ=
13
+ ZWYyMjgzODkwNTQxZGU5ZTc4ZWQ4MzFlZmRiZGEwN2MxYjYwNWEzNmEyNjgx
14
+ MDk1NzllNmMyZGMzZmRkMjY2ZjMzOGM3Njk5OTYwMTAxZDYxYTkzMGM4ZmQz
15
+ ZGY2ZTEzZjA1NDE5YjFkMmM3NTlhMzdkY2E3NWI2NzBlZGQxYTY=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.7.0 / 2014-01-03
2
+
3
+ * 2 enhancements:
4
+
5
+ * Having GUID be default
6
+ * Update persistence methods
7
+
8
+
1
9
  ### 0.6.0 / 2014-01-02
2
10
 
3
11
  * 1 unknown:
data/lib/mem_model.rb CHANGED
@@ -7,7 +7,25 @@ module MemModel
7
7
  def maglev?
8
8
  !defined?(Maglev).nil?
9
9
  end
10
- module_function :maglev?
10
+
11
+ def commit
12
+ maglev? ? Maglev.commit_transaction : true
13
+ end
14
+
15
+ def abort
16
+ maglev? ? Maglev.abort_transaction : true
17
+ end
18
+
19
+ def persistent(&block)
20
+ if maglev?
21
+ Maglev.persistent{ block.call }
22
+ commit
23
+ else
24
+ block.call
25
+ end
26
+ end
27
+
28
+ module_function :maglev?, :commit, :abort, :persistent
11
29
  end
12
30
 
13
31
  %w[ concern base errors guid model_name rooted_base validations version ].each do |file|
@@ -4,6 +4,7 @@ module MemModel
4
4
 
5
5
  included do
6
6
  include MemModel::Validations
7
+ include MemModel::Guid
7
8
  attr_accessor :id
8
9
  end
9
10
 
@@ -70,13 +71,11 @@ module MemModel
70
71
  end
71
72
 
72
73
  def abort
73
- # no-op
74
- true
74
+ MemModel.abort
75
75
  end
76
76
 
77
77
  def commit
78
- # no-op
79
- true
78
+ MemModel.commit
80
79
  end
81
80
 
82
81
  alias_method :to_str, :to_s
@@ -84,6 +83,16 @@ module MemModel
84
83
  def delete(record)
85
84
  store.delete(record)
86
85
  end
86
+
87
+ if !MemModel.maglev?
88
+ def committed?; false; end
89
+ end
90
+
91
+ def persistent(&block)
92
+ committed? ?
93
+ MemModel.persistent(&block) :
94
+ block.call
95
+ end
87
96
  end
88
97
 
89
98
  def initialize(attributes = {})
@@ -98,11 +107,25 @@ module MemModel
98
107
 
99
108
  def model_name; self.class.model_name; end
100
109
 
101
- unless MemModel.maglev?
110
+ if !MemModel.maglev?
102
111
  def committed?; @persisted == true; end
103
112
  end
104
- alias_method :persisted?, :committed?
105
- alias_method :exists?, :committed?
113
+
114
+ def class_committed?
115
+ self.class.committed?
116
+ end
117
+
118
+ def persisted?
119
+ class_committed? ?
120
+ committed? :
121
+ @persisted == true
122
+ end
123
+ alias_method :exists?, :persisted?
124
+
125
+ def new?
126
+ !persisted?
127
+ end
128
+ alias_method :new_record?, :new?
106
129
 
107
130
  def to_key; end
108
131
  def to_param; end
@@ -110,7 +133,6 @@ module MemModel
110
133
 
111
134
  def errors; @errors ||= Errors.new(self); end
112
135
 
113
-
114
136
  def maglev?
115
137
  self.class.maglev?
116
138
  end
@@ -124,15 +146,9 @@ module MemModel
124
146
  end
125
147
 
126
148
  def persistent(&block)
127
- # no-op
128
- block.call
149
+ self.class.persistent(&block)
129
150
  end
130
151
 
131
- def new?
132
- !persisted?
133
- end
134
- alias_method :new_record?, :new?
135
-
136
152
  def save
137
153
  new? ? create : update
138
154
  end
@@ -141,7 +157,7 @@ module MemModel
141
157
  self.id ||= generate_id
142
158
  persistent do
143
159
  self.class.store << self
144
- @persisted = true unless maglev?
160
+ @persisted = true unless class_committed?
145
161
  end
146
162
  self.id
147
163
  end
@@ -2,11 +2,23 @@ module MemModel
2
2
  module Guid
3
3
  extend MemModel::Concern
4
4
 
5
+ def generate_id
6
+ self.class.generate_id
7
+ end
8
+
5
9
  module ClassMethods
6
10
  def generate_id
7
11
  [guid_prefix, '-', new_uuid].join.upcase
8
12
  end
9
13
 
14
+ def guid_prefix
15
+ name[0...3]
16
+ end
17
+
18
+ def find_all_matching(substring)
19
+ store.select{ |r| r.id.include?(substring.to_s.upcase) }
20
+ end
21
+
10
22
  def random_bytes(n=16)
11
23
  flags = File::RDONLY
12
24
  flags |= File::NONBLOCK if defined? File::NONBLOCK
@@ -34,14 +46,6 @@ module MemModel
34
46
  ary[3] = (ary[3] & 0x3fff) | 0x8000
35
47
  "%08x-%04x-%04x-%04x-%04x%08x" % ary
36
48
  end
37
-
38
- def guid_prefix
39
- name[0...3]
40
- end
41
-
42
- def find_all_matching(substring)
43
- store.select{ |r| r.id.include?(substring.to_s.upcase) }
44
- end
45
49
  end
46
50
  end
47
51
  end
@@ -3,7 +3,10 @@ module MemModel
3
3
 
4
4
  module RootedBase
5
5
  extend MemModel::Concern
6
- include Base
6
+
7
+ included do
8
+ include MemModel::Base
9
+ end
7
10
 
8
11
  module ClassMethods
9
12
  def root_container
@@ -22,28 +25,6 @@ module MemModel
22
25
  def root
23
26
  @root ||= root_container::PERSISTENT_ROOT
24
27
  end
25
-
26
- def abort
27
- Maglev.abort_transaction if maglev?
28
- true
29
- end
30
-
31
- def commit
32
- Maglev.commit_transaction if maglev?
33
- true
34
- end
35
-
36
- def persistent(&block)
37
- abort
38
- maglev? ?
39
- Maglev.persistent { block.call } :
40
- block.call
41
- commit
42
- end
43
- end
44
-
45
- def persistent(&block)
46
- self.class.persistent(&block)
47
28
  end
48
29
  end
49
30
  end
@@ -1,3 +1,3 @@
1
1
  module MemModel
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
data/mem_model.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mem_model 0.6.0.20140102221058 ruby lib
2
+ # stub: mem_model 0.7.0.20140103165733 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mem_model"
6
- s.version = "0.6.0.20140102221058"
6
+ s.version = "0.7.0.20140103165733"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["JohnnyT"]
@@ -18,23 +18,10 @@ class TestRootedBase < Minitest::Test
18
18
  refute Account.exists? 314159
19
19
  end
20
20
 
21
- if MemModel.maglev?
22
-
23
- def test_maglev_exists
24
- assert_raises TransactionError, 'The test Account class is transient' do
25
- @account.save
26
- end
27
- @account.abort
28
- end
29
-
30
- else
31
-
32
- def test_mri_exists
33
- refute Account.exists? @account.id
34
- @account.save
35
- assert Account.exists? @account.id
36
- end
37
-
21
+ def test_exists
22
+ refute Account.exists? @account.id
23
+ @account.save
24
+ assert Account.exists? @account.id
38
25
  end
39
26
 
40
27
  def test_root_container
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mem_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JohnnyT