dynamic-records-meritfront 2.0.15 → 2.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +65 -4
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 122854ead22d0622151522249d115b088dc1ecd4d21fe9a794a23126ab105d65
|
4
|
+
data.tar.gz: 216371aab9c74e6a9a0c3638d0436cfc0f83e72f7668c7c57a3f73dc20876c19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4d2ab247cf4cff13fad1f772cc437585aeb28a59686b4ff0046a7bffd2466c944749c1ab22fdc058b02150043d4e05515e0d5b5d962c78b84c02d9b8985618f
|
7
|
+
data.tar.gz: 6f962c2213eedc0441a38002e5ce5770ec932e6ee0c36faa2ff9c965abfa56502ad8e56accade17d94216b8c6025883e6276f65515d6886aa09681ec11f713e4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -141,9 +141,10 @@ This is an example of why this method is good for dynamic prepared statements.
|
|
141
141
|
test = Vote.dynamic_sql('test', %Q{
|
142
142
|
SELECT id, 'yes' AS is_this_vote_cool FROM votes LIMIT 1
|
143
143
|
}).first
|
144
|
-
test.inspect # "#<Vote id: 696969>" we dont have the dynamic attributes as normal ones because of some implementation issues and some real issues to do with accidently logging sensative info.
|
145
|
-
test.dynamic #
|
146
|
-
test.dynamic
|
144
|
+
test.inspect # "#<Vote id: 696969>" we dont have the dynamic attributes as normal ones because of some implementation issues and some real issues to do with accidently logging sensative info. Implementation issues are to do with the fact that ActiveRecord::Base doesn't expect database columns to change randomly, and doesn't allow us to append to the attributes accessor.
|
145
|
+
test.dynamic # <OpenStruct is_this_vote_cool='yes'>
|
146
|
+
test.dynamic.is_this_vote_cool # "yes"
|
147
|
+
test.dynamic[:is_this_vote_cool] #yes
|
147
148
|
```
|
148
149
|
</details>
|
149
150
|
|
@@ -293,7 +294,7 @@ ApplicationRecord.dynamic_attach(out, 'limited_users', 'users_friends', attach_o
|
|
293
294
|
ApplicationRecord.dynamic_attach(out, 'limited_users', 'users_follows', attach_on: Proc.new {|follow|
|
294
295
|
follow['follower_id']
|
295
296
|
})
|
296
|
-
pp out['limited_users'].map{|o| {id: o.id, users_friends: o.users_friends.first(4), users_follows: o.users_follows.first(4)}}
|
297
|
+
pp out['limited_users'].map{|o| {id: o.id, users_friends: o.dynamic.users_friends.first(4), users_follows: o.dynamic.users_follows.first(4)}}
|
297
298
|
|
298
299
|
```
|
299
300
|
|
@@ -326,8 +327,63 @@ printed output:
|
|
326
327
|
```
|
327
328
|
|
328
329
|
</details>
|
330
|
+
|
331
|
+
#### dynamic_print(v, print: true)
|
332
|
+
- prints models along with dynamic variables using the pretty-printer. Fails in production to prevent leaking sensative information.
|
333
|
+
- The reason this exists is that I could not override the inspect method for ActiveRecord. In my case, devise then overrode it from me. A little annoying. Because of that, this is now the best way to view both attributes and dynamic variables in the same location.
|
334
|
+
|
335
|
+
<details>
|
336
|
+
<summary> example using output of dynamic_attach example </summary>
|
329
337
|
|
338
|
+
```ruby
|
339
|
+
ApplicationRecord.dynamic_print(out['limited_users'])
|
340
|
+
```
|
330
341
|
|
342
|
+
printed output:
|
343
|
+
```ruby
|
344
|
+
[#<struct DynamicRecordsMeritfront::RecordForPrint
|
345
|
+
class="User",
|
346
|
+
attributes={"id"=>3},
|
347
|
+
dynamic=
|
348
|
+
{:users_friends=>
|
349
|
+
[#<struct DynamicRecordsMeritfront::RecordForPrint
|
350
|
+
class="User",
|
351
|
+
attributes={"id"=>5},
|
352
|
+
dynamic={:friended_to=>3}>,
|
353
|
+
#<struct DynamicRecordsMeritfront::RecordForPrint
|
354
|
+
class="User",
|
355
|
+
attributes={"id"=>6},
|
356
|
+
dynamic={:friended_to=>3}>,
|
357
|
+
#<struct DynamicRecordsMeritfront::RecordForPrint
|
358
|
+
class="User",
|
359
|
+
attributes={"id"=>21},
|
360
|
+
dynamic={:friended_to=>3}>],
|
361
|
+
:users_follows=>
|
362
|
+
[{"followable_id"=>935, "follower_id"=>3},
|
363
|
+
{"followable_id"=>938, "follower_id"=>3},
|
364
|
+
{"followable_id"=>939, "follower_id"=>3},
|
365
|
+
{"followable_id"=>932, "follower_id"=>3},
|
366
|
+
{"followable_id"=>5, "follower_id"=>3},
|
367
|
+
{"followable_id"=>4, "follower_id"=>3},
|
368
|
+
{"followable_id"=>23, "follower_id"=>3},
|
369
|
+
{"followable_id"=>22, "follower_id"=>3},
|
370
|
+
{"followable_id"=>15, "follower_id"=>3},
|
371
|
+
{"followable_id"=>6, "follower_id"=>3},
|
372
|
+
{"followable_id"=>3, "follower_id"=>3},
|
373
|
+
{"followable_id"=>8, "follower_id"=>3},
|
374
|
+
{"followable_id"=>7, "follower_id"=>3},
|
375
|
+
{"followable_id"=>1, "follower_id"=>3},
|
376
|
+
{"followable_id"=>18, "follower_id"=>3},
|
377
|
+
{"followable_id"=>16, "follower_id"=>3},
|
378
|
+
{"followable_id"=>21, "follower_id"=>3},
|
379
|
+
{"followable_id"=>9, "follower_id"=>3},
|
380
|
+
{"followable_id"=>19, "follower_id"=>3}]}>,
|
381
|
+
|
382
|
+
...
|
383
|
+
|
384
|
+
```
|
385
|
+
|
386
|
+
</details>
|
331
387
|
|
332
388
|
### Hashed Global IDS
|
333
389
|
|
@@ -377,6 +433,11 @@ This gem was made with a postgresql database. This could cause a lot of issues w
|
|
377
433
|
- the output of dynamic_instaload_sql can be made more useful with dynamic_attach. See more above.
|
378
434
|
- postgres is now a pretty hard requirement as I use its database features liberally and I am somewhat certain that other databases wont work in the exact same way
|
379
435
|
|
436
|
+
2.0.16
|
437
|
+
- changed model.dynamic attribute to an OpenStruct class which just makes it easier to work with
|
438
|
+
- changed dynamic_attach so that it now uses the model.dynamic attribute, instead of using singleton classes. This is better practice, and also contains all the moving parts of this gem in one place.
|
439
|
+
- added the dynamic_print method to easier see the objects one is working with.
|
440
|
+
|
380
441
|
## Contributing
|
381
442
|
|
382
443
|
Bug reports and pull requests are welcome on GitHub at https://github.com/LukeClancy/dynamic-records-meritfront. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/LukeClancy/dynamic-records-meritfront/blob/master/CODE_OF_CONDUCT.md).
|
@@ -66,6 +66,7 @@ module DynamicRecordsMeritfront
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
RecordForPrint = Struct.new(:class, :attributes, :dynamic)
|
69
70
|
module ClassMethods
|
70
71
|
|
71
72
|
def dynamic_print_h(v)
|
@@ -530,7 +531,9 @@ module DynamicRecordsMeritfront
|
|
530
531
|
attach_on = Proc.new{|x| x[default_attach_col]}
|
531
532
|
else
|
532
533
|
attach_on = Proc.new{|x|
|
533
|
-
|
534
|
+
ret = x.attributes[default_attach_col]
|
535
|
+
ret ||= x.dynamic[default_attach_col]
|
536
|
+
ret
|
534
537
|
}
|
535
538
|
end
|
536
539
|
end
|
@@ -645,4 +648,4 @@ module DynamicRecordsMeritfront
|
|
645
648
|
self.class.where(id: self.id).update_all("#{col} = #{col} + #{val}")
|
646
649
|
end
|
647
650
|
|
648
|
-
end
|
651
|
+
end
|