packed-model 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -9
- data/Gemfile.lock +35 -6
- data/Rakefile +0 -25
- data/VERSION +1 -1
- data/lib/packed_model/base.rb +24 -0
- data/packed-model.gemspec +12 -19
- data/spec/packed_model/base_spec.rb +71 -0
- metadata +54 -84
data/Gemfile
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
3
|
group :development do
|
9
|
-
gem
|
10
|
-
gem "
|
11
|
-
gem "rcov", ">= 0"
|
12
|
-
gem "rspec", ">= 0"
|
4
|
+
gem 'jeweler'
|
5
|
+
gem "rspec"
|
13
6
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,47 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
4
6
|
diff-lcs (1.2.4)
|
7
|
+
faraday (0.8.8)
|
8
|
+
multipart-post (~> 1.2.0)
|
5
9
|
git (1.2.5)
|
6
|
-
|
10
|
+
github_api (0.10.1)
|
11
|
+
addressable
|
12
|
+
faraday (~> 0.8.1)
|
13
|
+
hashie (>= 1.2)
|
14
|
+
multi_json (~> 1.4)
|
15
|
+
nokogiri (~> 1.5.2)
|
16
|
+
oauth2
|
17
|
+
hashie (2.0.5)
|
18
|
+
highline (1.6.20)
|
19
|
+
httpauth (0.2.0)
|
20
|
+
jeweler (1.8.8)
|
21
|
+
builder
|
7
22
|
bundler (~> 1.0)
|
8
23
|
git (>= 1.2.5)
|
24
|
+
github_api (= 0.10.1)
|
25
|
+
highline (>= 1.6.15)
|
26
|
+
nokogiri (= 1.5.10)
|
9
27
|
rake
|
10
28
|
rdoc
|
11
29
|
json (1.7.7)
|
12
|
-
|
13
|
-
|
30
|
+
jwt (0.1.8)
|
31
|
+
multi_json (>= 1.5)
|
32
|
+
multi_json (1.8.2)
|
33
|
+
multi_xml (0.5.5)
|
34
|
+
multipart-post (1.2.0)
|
35
|
+
nokogiri (1.5.10)
|
36
|
+
oauth2 (0.9.2)
|
37
|
+
faraday (~> 0.8)
|
38
|
+
httpauth (~> 0.2)
|
39
|
+
jwt (~> 0.1.4)
|
40
|
+
multi_json (~> 1.0)
|
41
|
+
multi_xml (~> 0.5)
|
42
|
+
rack (~> 1.2)
|
43
|
+
rack (1.5.2)
|
44
|
+
rake (10.1.0)
|
14
45
|
rdoc (3.12.2)
|
15
46
|
json (~> 1.4)
|
16
47
|
rspec (2.13.0)
|
@@ -26,7 +57,5 @@ PLATFORMS
|
|
26
57
|
ruby
|
27
58
|
|
28
59
|
DEPENDENCIES
|
29
|
-
jeweler
|
30
|
-
rcov
|
31
|
-
rdoc (~> 3.12)
|
60
|
+
jeweler
|
32
61
|
rspec
|
data/Rakefile
CHANGED
@@ -25,29 +25,4 @@ Jeweler::Tasks.new do |gem|
|
|
25
25
|
end
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
27
27
|
|
28
|
-
require 'rake/testtask'
|
29
|
-
Rake::TestTask.new(:test) do |test|
|
30
|
-
test.libs << 'lib' << 'test'
|
31
|
-
test.pattern = 'test/**/test_*.rb'
|
32
|
-
test.verbose = true
|
33
|
-
end
|
34
|
-
|
35
|
-
require 'rcov/rcovtask'
|
36
|
-
Rcov::RcovTask.new do |test|
|
37
|
-
test.libs << 'test'
|
38
|
-
test.pattern = 'test/**/test_*.rb'
|
39
|
-
test.verbose = true
|
40
|
-
test.rcov_opts << '--exclude "gems/*"'
|
41
|
-
end
|
42
28
|
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'rdoc/task'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "packed-model #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/packed_model/base.rb
CHANGED
@@ -162,6 +162,30 @@ module PackedModel
|
|
162
162
|
self.class_eval method_src, __FILE__, __LINE__
|
163
163
|
end
|
164
164
|
|
165
|
+
def self.bit_vector(name, fields, options={})
|
166
|
+
raise "too many fields for bit vecotr #{name}" if fields.size > 32
|
167
|
+
|
168
|
+
self.attribute name, {:type => :integer}.merge(options)
|
169
|
+
|
170
|
+
name_equals = "#{name}="
|
171
|
+
|
172
|
+
fields.each_with_index do |fld, idx|
|
173
|
+
mask = 1 << idx
|
174
|
+
|
175
|
+
define_method fld do
|
176
|
+
(self.send(name) & mask) == mask
|
177
|
+
end
|
178
|
+
|
179
|
+
define_method "#{fld}=" do |val|
|
180
|
+
if val
|
181
|
+
self.send(name_equals, self.send(name) | mask)
|
182
|
+
else
|
183
|
+
self.send(name_equals, self.send(name) ^ mask)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
165
189
|
def initialize(values=nil)
|
166
190
|
case values
|
167
191
|
when String
|
data/packed-model.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.1.
|
7
|
+
s.name = "packed-model"
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Doug Youch"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2013-11-05"
|
13
|
+
s.description = "Used to minimize storage space required to store list of data"
|
14
|
+
s.email = "doug@sessionm.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.rdoc"
|
@@ -35,31 +35,24 @@ Gem::Specification.new do |s|
|
|
35
35
|
"test/helper.rb",
|
36
36
|
"test/test_packed_model_base.rb"
|
37
37
|
]
|
38
|
-
s.homepage =
|
38
|
+
s.homepage = "http://github.com/dyouch5@yahoo.com/packed-model"
|
39
39
|
s.licenses = ["MIT"]
|
40
40
|
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version =
|
42
|
-
s.summary =
|
41
|
+
s.rubygems_version = "1.8.23"
|
42
|
+
s.summary = "PackedModel stores model data in a binary string"
|
43
43
|
|
44
44
|
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
45
|
s.specification_version = 3
|
47
46
|
|
48
|
-
if Gem::Version.new(Gem::
|
49
|
-
s.add_development_dependency(%q<
|
50
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
51
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
52
49
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
53
50
|
else
|
54
|
-
s.add_dependency(%q<
|
55
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
51
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
57
52
|
s.add_dependency(%q<rspec>, [">= 0"])
|
58
53
|
end
|
59
54
|
else
|
60
|
-
s.add_dependency(%q<
|
61
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
62
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
63
56
|
s.add_dependency(%q<rspec>, [">= 0"])
|
64
57
|
end
|
65
58
|
end
|
@@ -197,4 +197,75 @@ describe PackedModel::Base do
|
|
197
197
|
m2.bytesize.should == 38
|
198
198
|
end
|
199
199
|
end
|
200
|
+
|
201
|
+
context "bit vector" do
|
202
|
+
class TestBitVectorPackedModel < PackedModel::Base
|
203
|
+
bit_vector :supports, [:bit1, :bit2, :bit3, :bit4, :bit5, :bit6, :bit7, :bit8,
|
204
|
+
:bit9, :bit10, :bit11, :bit12, :bit13, :bit14, :bit15, :bit16,
|
205
|
+
:bit17, :bit18, :bit19, :bit20, :bit21, :bit22, :bit23, :bit24,
|
206
|
+
:bit25, :bit26, :bit27, :bit28, :bit29, :bit30, :bit31, :bit32]
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should set all flags to false" do
|
210
|
+
m = TestBitVectorPackedModel.new
|
211
|
+
m.supports.should == 0
|
212
|
+
m.bit1.should be_false
|
213
|
+
m.bit8.should be_false
|
214
|
+
m.bit32.should be_false
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should be able to set individual flags" do
|
218
|
+
m = TestBitVectorPackedModel.new
|
219
|
+
m.bit7.should be_false
|
220
|
+
m.bit7 = true
|
221
|
+
m.bit7.should be_true
|
222
|
+
|
223
|
+
m = TestBitVectorPackedModel.new m.pack
|
224
|
+
m.bit7.should be_true
|
225
|
+
|
226
|
+
m.supports.should == (1 << 6)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should be able to set and unset individual flags" do
|
230
|
+
m = TestBitVectorPackedModel.new
|
231
|
+
m.bit1 = true
|
232
|
+
m.bit7 = true
|
233
|
+
m.bit10 = true
|
234
|
+
m.bit17 = true
|
235
|
+
m.bit20 = true
|
236
|
+
|
237
|
+
m = TestBitVectorPackedModel.new m.pack
|
238
|
+
m.bit1.should be_true
|
239
|
+
m.bit7.should be_true
|
240
|
+
m.bit10.should be_true
|
241
|
+
m.bit17.should be_true
|
242
|
+
m.bit20.should be_true
|
243
|
+
|
244
|
+
m.bit2.should be_false
|
245
|
+
m.bit16.should be_false
|
246
|
+
m.bit18.should be_false
|
247
|
+
m.bit32.should be_false
|
248
|
+
|
249
|
+
m.bit10 = false
|
250
|
+
m.bit10.should be_false
|
251
|
+
m.bit32 = true
|
252
|
+
m.bit32.should be_true
|
253
|
+
|
254
|
+
m = TestBitVectorPackedModel.new m.pack
|
255
|
+
m.bit1.should be_true
|
256
|
+
m.bit7.should be_true
|
257
|
+
m.bit10.should be_false
|
258
|
+
m.bit17.should be_true
|
259
|
+
m.bit20.should be_true
|
260
|
+
m.bit32.should be_true
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should default all flags to true" do
|
264
|
+
m = TestBitVectorPackedModel.new
|
265
|
+
m.supports = 0xFFFFFFFF
|
266
|
+
(1..32).each do |n|
|
267
|
+
m.send("bit#{n}").should be_true
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
200
271
|
end
|
metadata
CHANGED
@@ -1,83 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: packed-model
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Doug Youch
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
prerelease: false
|
22
|
-
type: :development
|
23
|
-
name: rdoc
|
24
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 3
|
30
|
-
- 12
|
31
|
-
version: "3.12"
|
32
|
-
requirement: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
prerelease: false
|
35
|
-
type: :development
|
12
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
36
15
|
name: jeweler
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- 8
|
44
|
-
- 4
|
45
|
-
version: 1.8.4
|
46
|
-
requirement: *id002
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
prerelease: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
49
22
|
type: :development
|
50
|
-
name: rcov
|
51
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 0
|
57
|
-
version: "0"
|
58
|
-
requirement: *id003
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
23
|
prerelease: false
|
61
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
62
31
|
name: rspec
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
71
46
|
description: Used to minimize storage space required to store list of data
|
72
47
|
email: doug@sessionm.com
|
73
48
|
executables: []
|
74
|
-
|
75
49
|
extensions: []
|
76
|
-
|
77
|
-
extra_rdoc_files:
|
50
|
+
extra_rdoc_files:
|
78
51
|
- LICENSE.txt
|
79
52
|
- README.rdoc
|
80
|
-
files:
|
53
|
+
files:
|
81
54
|
- .document
|
82
55
|
- Gemfile
|
83
56
|
- Gemfile.lock
|
@@ -95,35 +68,32 @@ files:
|
|
95
68
|
- spec/packed_model/list_spec.rb
|
96
69
|
- test/helper.rb
|
97
70
|
- test/test_packed_model_base.rb
|
98
|
-
has_rdoc: true
|
99
71
|
homepage: http://github.com/dyouch5@yahoo.com/packed-model
|
100
|
-
licenses:
|
72
|
+
licenses:
|
101
73
|
- MIT
|
102
74
|
post_install_message:
|
103
75
|
rdoc_options: []
|
104
|
-
|
105
|
-
require_paths:
|
76
|
+
require_paths:
|
106
77
|
- lib
|
107
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
segments:
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
segments:
|
119
85
|
- 0
|
120
|
-
|
86
|
+
hash: -1850752806979400646
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
121
93
|
requirements: []
|
122
|
-
|
123
94
|
rubyforge_project:
|
124
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 1.8.23
|
125
96
|
signing_key:
|
126
97
|
specification_version: 3
|
127
98
|
summary: PackedModel stores model data in a binary string
|
128
99
|
test_files: []
|
129
|
-
|