attr_pouch 0.1.0 → 0.1.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: 1e70f1aaa49e8c698db7004d2137dff0fb396462
4
- data.tar.gz: e29ed8ec737976e0e65180c79c3a4736f92d691f
3
+ metadata.gz: 0bc7099e267a11a0723eaa8b16654b6221e928bc
4
+ data.tar.gz: 79fad57b11a02ac0b0093c4d579c7fc109dbbb70
5
5
  SHA512:
6
- metadata.gz: 4961584f437d46255b6e0ce970b61b7bd9d820b943397e498c129e75176553bca6975ee52e2470fad4790ab5bfcfdb022ca920367e32a7f89b301a4fbf4ec00d
7
- data.tar.gz: fd0c772494d398b7bfdfdd4e08cd52e93644cd30af48b6b98fa494b304d4ea1b8ce84d95b019098bb5f4578813a79d4d52c7707c0d7ccc1742b94f2048c0532a
6
+ metadata.gz: 4700d4f626b53b6d3dae2211d16e14288b8d51327f8059f8520356bf0de0f977b023fc9d6e1b32c8ec13f6b70093cb9fab0a80e09c05ef19b7e7772afc82f808
7
+ data.tar.gz: 83accbe6882fef94e44d1ab5aae58a2d66c811b792ce68b0a19f99032158a96e42d9547ed7305b147bd6d2035410948d1c75a84393dc0ced0e7d4c9178be41bd
data/.travis.yml CHANGED
@@ -7,6 +7,6 @@ addons:
7
7
  postgresql: "9.4"
8
8
  env:
9
9
  rvm:
10
- - 2.2.3
10
+ - 2.4.1
11
11
  notifications:
12
12
  email: false
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- ruby '2.2.3'
3
+ ruby '2.4.1'
4
4
 
5
5
  # Specify your gem's dependencies in attr_pouch.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attr_pouch (0.1.0)
4
+ attr_pouch (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -20,7 +20,7 @@ GEM
20
20
  rspec-mocks (3.1.3)
21
21
  rspec-support (~> 3.1.0)
22
22
  rspec-support (3.1.2)
23
- sequel (4.13.0)
23
+ sequel (4.49.0)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
@@ -29,7 +29,10 @@ DEPENDENCIES
29
29
  attr_pouch!
30
30
  pg (~> 0.18.3)
31
31
  rspec (~> 3.0)
32
- sequel (~> 4.13)
32
+ sequel (~> 4.46)
33
+
34
+ RUBY VERSION
35
+ ruby 2.4.1p111
33
36
 
34
37
  BUNDLED WITH
35
- 1.10.6
38
+ 1.14.6
data/README.md CHANGED
@@ -23,6 +23,15 @@ parts of your data model, but augment it with schema-less storage for
23
23
  the parts that are in flux or just awkward to fit into the relational
24
24
  model.
25
25
 
26
+ ### Installation
27
+
28
+ Add `attr_pouch` to your `Gemfile`:
29
+
30
+ ```ruby
31
+ gem 'attr_pouch'
32
+ ```
33
+
34
+ Then run `bundle install`.
26
35
 
27
36
  ### Usage
28
37
 
@@ -35,6 +44,8 @@ fact stored in the pouch:
35
44
 
36
45
  ```ruby
37
46
  class User < Sequel::Model
47
+ include AttrPouch
48
+
38
49
  pouch(:preferences) do
39
50
  field :theme
40
51
  field :autoplay_videos?
@@ -63,8 +74,10 @@ can be marked as optional by providing a default:
63
74
 
64
75
  ```ruby
65
76
  class User < Sequel::Model
77
+ include AttrPouch
78
+
66
79
  pouch(:preferences) do
67
- field :favorite_color, default: 'puce'
80
+ field :favorite_color, default: 'puce'
68
81
  end
69
82
  end
70
83
 
@@ -87,6 +100,8 @@ simple built-in types are `String`, `Integer`, `Float`, `Time`, and
87
100
 
88
101
  ```ruby
89
102
  class User < Sequel::Model
103
+ include AttrPouch
104
+
90
105
  pouch(:preferences) do
91
106
  field :favorite_color, type: String
92
107
  field :lucky_number, type: Integer
@@ -99,10 +114,10 @@ You can override these built-ins or register entirely new types:
99
114
 
100
115
  ```ruby
101
116
  AttrPouch.configure do |config|
102
- config.write(:obfuscated_string) do |field, value|
117
+ config.encode(:obfuscated_string) do |field, value|
103
118
  value.reverse
104
119
  end
105
- config.read(:obfuscated_string) do |field, value|
120
+ config.decode(:obfuscated_string) do |field, value|
106
121
  value.reverse
107
122
  end
108
123
  end
@@ -123,6 +138,8 @@ This can be illustrated via the last built-in codec, for
123
138
 
124
139
  ```ruby
125
140
  class User < Sequel::Model
141
+ include AttrPouch
142
+
126
143
  pouch(:preferences) do
127
144
  field :bff, type: User
128
145
  end
@@ -165,6 +182,8 @@ methods for them:
165
182
 
166
183
  ```ruby
167
184
  class User < Sequel::Model
185
+ include AttrPouch
186
+
168
187
  pouch(:preferences) do
169
188
  field :proxy_address, deletable: true
170
189
  end
@@ -197,6 +216,8 @@ updates once an initial value has been set:
197
216
 
198
217
  ```ruby
199
218
  class User < Sequel::Model
219
+ include AttrPouch
220
+
200
221
  pouch(:preferences) do
201
222
  field :lucky?, mutable: false
202
223
  end
@@ -214,6 +235,8 @@ previous names under the `was` option.
214
235
 
215
236
  ```ruby
216
237
  class User < Sequel::Model
238
+ include AttrPouch
239
+
217
240
  pouch(:preferences) do
218
241
  field :tls?, was: :ssl?
219
242
  field :instabul?, was: %i[constantinople? byzantion?]
@@ -249,10 +272,12 @@ absent field value deferring to the default:
249
272
 
250
273
  ```ruby
251
274
  class User < Sequel::Model
275
+ include AttrPouch
276
+
252
277
  pouch(:preferences) do
253
278
  field :bff, type: User, raw_field: :bff_id
254
279
  field :arch_nemesis, type: User, raw_field: :nemesis_id,
255
- default: User[name: 'donald']
280
+ default: User[name: 'donald']
256
281
  end
257
282
  end
258
283
 
@@ -275,6 +300,8 @@ contents. The interface is similar to querying first-class columns:
275
300
 
276
301
  ```ruby
277
302
  class User < Sequel::Model
303
+ include AttrPouch
304
+
278
305
  pouch(:preferences) do
279
306
  field :bff, type: User
280
307
  field :favorite_color
data/TODO CHANGED
@@ -1,7 +1,6 @@
1
1
  # TODO thoughts:
2
- - docs
3
- - dataset
4
- - update to note json / jsonb support
2
+ - chainable encode/decode filters
3
+ - support for inheritance (pouch with some fields in parent class, some in child)
5
4
  - support for access via [] and []= methods
6
5
  - opt: eager_default on create for fields
7
6
  - opt: run tracking
data/attr_pouch.gemspec CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency "rspec", '~> 3.0'
19
19
  gem.add_development_dependency "pg", '~> 0.18.3'
20
- gem.add_development_dependency "sequel", '~> 4.13'
20
+ gem.add_development_dependency "sequel", '~> 4.46'
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module AttrPouch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/attr_pouch.rb CHANGED
@@ -15,40 +15,42 @@ module AttrPouch
15
15
  def self.included(base)
16
16
  base.extend(ClassMethods)
17
17
  # we can't just independently define this in ClassMethods since
18
- # `def_dataset_method` is only defined on Sequel::Model subclasses
19
- base.def_dataset_method(:where_pouch) do |pouch_field, expr_hash|
20
- ds = self
21
- pouch = model.pouch(pouch_field)
22
- if pouch.nil?
23
- raise ArgumentError,
24
- "No pouch defined for #{pouch_field}"
25
- end
26
- if pouch.json?
27
- raise UnsupportedError, "Dataset queries not supported for columns of type json"
28
- end
29
-
30
- expr_hash.each do |key, value|
31
- key = key.to_s
32
- field = pouch.field_definition(key)
33
- if field.nil?
18
+ # `dataset_module` is only defined on Sequel::Model subclasses
19
+ base.dataset_module do
20
+ define_method(:where_pouch) do |pouch_field, expr_hash|
21
+ ds = self
22
+ pouch = model.pouch(pouch_field)
23
+ if pouch.nil?
34
24
  raise ArgumentError,
35
- "No field #{key} defined for pouch #{pouch_field}"
25
+ "No pouch defined for #{pouch_field}"
26
+ end
27
+ if pouch.json?
28
+ raise UnsupportedError, "Dataset queries not supported for columns of type json"
36
29
  end
37
30
 
38
- if value.respond_to?(:each)
39
- value.each_with_index do |v,i|
40
- condition = pouch.store.contains(pouch.wrap(key => field.encode(v)))
41
- ds = i == 0 ? ds.where(condition) : ds.or(condition)
31
+ expr_hash.each do |key, value|
32
+ key = key.to_s
33
+ field = pouch.field_definition(key)
34
+ if field.nil?
35
+ raise ArgumentError,
36
+ "No field #{key} defined for pouch #{pouch_field}"
37
+ end
38
+
39
+ if value.respond_to?(:each)
40
+ value.each_with_index do |v,i|
41
+ condition = pouch.store.contains(pouch.wrap(key => field.encode(v)))
42
+ ds = i == 0 ? ds.where(condition) : ds.or(condition)
43
+ end
44
+ elsif value.nil?
45
+ ds = ds.where(pouch.store.has_key?(key) => false)
46
+ .or(pouch.store.contains(pouch.wrap(key => field.encode(value))))
47
+ else
48
+ ds = ds.where(pouch.store
49
+ .contains(pouch.wrap(key => field.encode(value))))
42
50
  end
43
- elsif value.nil?
44
- ds = ds.where(pouch.store.has_key?(key) => false)
45
- .or(pouch.store.contains(pouch.wrap(key => field.encode(value))))
46
- else
47
- ds = ds.where(pouch.store
48
- .contains(pouch.wrap(key => field.encode(value))))
49
51
  end
52
+ ds
50
53
  end
51
- ds
52
54
  end
53
55
  end
54
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_pouch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciek Sakrejda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-26 00:00:00.000000000 Z
11
+ date: 2017-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '4.13'
47
+ version: '4.46'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '4.13'
54
+ version: '4.46'
55
55
  description: Schema-less attribute storage
56
56
  email:
57
57
  - m.sakrejda@gmail.com
@@ -91,11 +91,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.4.5.1
94
+ rubygems_version: 2.6.11
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Sequel plugin for schema-less attribute storage
98
98
  test_files:
99
99
  - spec/attr_pouch_spec.rb
100
100
  - spec/spec_helper.rb
101
- has_rdoc: