dynamic-records-meritfront 2.0.14 → 2.0.16

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
  SHA256:
3
- metadata.gz: e8746dd95a3481fbf2e337f18d1acd23cd905c0ca1e6ec819378779cec44618f
4
- data.tar.gz: 89ccbea41dffe5905735cdd3169f6088e703515701299bb3cb6c450a62660120
3
+ metadata.gz: fa19593097842159f3b5f7b387a3ae2771ac0ce89edfa94ca83a3ca4065418b7
4
+ data.tar.gz: e3294816f249639df5bbdc64346cc625c2eeda98c8c12baa9a0c75a451acfd34
5
5
  SHA512:
6
- metadata.gz: 1883f52d923060e1ff6c989423156abbd3d564d3bfedf47d8bca018e9b7935ae13bb0d9cfc6294f5a39e306dda92573f47e7ec14b75fd69faae9471d73f06e3a
7
- data.tar.gz: 246dab456f53b2318649215741290970001b52034428f6a62d36fe25945de4e5961ab66008fed2f3ce84eda85e9487ef5b02eded119c83456ec2323c616f6565
6
+ metadata.gz: 20307306744813447e04c58df7ed54fce62de160acbda99e0fbe0a7b208572fadf8ef8195600eac292d0cc7684da14a2072ef00a728d1f9d706b8d209aa44382
7
+ data.tar.gz: 4de4c710212960930835a7a1cf2a699a8fdbc7931ac57895557affce1b34ac49d505d7cbc7fefc6d82f08e2961e11357c9b00d0afbc57f8101fadf46e4c4e8ce
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamic-records-meritfront (2.0.14)
4
+ dynamic-records-meritfront (2.0.16)
5
5
  hashid-rails
6
6
 
7
7
  GEM
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 # {:is_this_vote_cool=>"yes"}
146
- test.dynamic[:is_this_vote_cool] # "yes"
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).
@@ -1,5 +1,5 @@
1
1
 
2
2
  module DynamicRecordsMeritfront
3
- VERSION = '2.0.14'
3
+ VERSION = '2.0.16'
4
4
  end
5
5
  #this file gets overwritten automatically on minor updates, major ones need to be manually changed
@@ -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)
@@ -93,7 +94,7 @@ module DynamicRecordsMeritfront
93
94
 
94
95
  def dynamic_print(v, print: true)
95
96
  return if Rails.env.production?
96
- if v.class.kind_of? Hash || v.class.kind_of OpenStruct
97
+ if v.class == Hash || v.class == OpenStruct
97
98
  ret = dynamic_print_h v
98
99
  elsif v.class == Array
99
100
  ret = dynamic_print_arr v
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-records-meritfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.14
4
+ version: 2.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Clancy