binky-builder 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec3bc7d5e0ac860ca01613229534eddb0f8ecea409aae8fbfb0a45ca832f44ae
4
- data.tar.gz: 44be568a3f14d0117d9782fcfea02875662a35549d9c89e9099e3b8fd64c0f54
3
+ metadata.gz: 48ae3e82b61cd05ef506c75db3161e6785b9d028417cf07a56fd6d611047437c
4
+ data.tar.gz: af023b00898403a2b924ba66df44bffaa24d5f37c496840d65a5bcd6525c49fb
5
5
  SHA512:
6
- metadata.gz: bbfc39168d710f666ad9ad99e433f7e2ef25499a9fb3ef0d70d71b3c741ccdca17df4c33d531af62637c03444f162bd49daf8a5b7f672db5ede8d9a88dd6f364
7
- data.tar.gz: 0a6fadd2533010b21b4545809f89080c43f93342f13f3ee43d6d52e941ae550c260b649a412dc5e4086a9ac0967aa494e3cd788cc7e67d079c5dad152698bedc
6
+ metadata.gz: 30d2250a30704797f61a2ba718170f5fc9c8004653328c15d7fbe917439a7123c9096cafb510d1581f9aca13ad5a25cb9abe4a06f7fdcda4084bdc946b2a6738
7
+ data.tar.gz: 357d984d515ccbfbcd90228a3148b0c910b5518ec10ae721dfcea2a4450c16101b1166ffbf0f56681ffd309f216e024bb3655194d95ae1a5cfc54e36101d5fff
@@ -2,7 +2,6 @@
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
4
  <list default="true" id="c1900bce-76f3-4483-9969-b14ec05dbe50" name="Default Changelist" comment="">
5
- <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
5
  <change beforePath="$PROJECT_DIR$/lib/binky/builder.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/binky/builder.rb" afterDir="false" />
7
6
  <change beforePath="$PROJECT_DIR$/lib/binky/builder/version.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/binky/builder/version.rb" afterDir="false" />
8
7
  </list>
@@ -17,8 +16,8 @@
17
16
  <file pinned="false" current-in-tab="false">
18
17
  <entry file="file://$PROJECT_DIR$/lib/binky/builder.rb">
19
18
  <provider selected="true" editor-type-id="text-editor">
20
- <state relative-caret-position="364">
21
- <caret line="14" column="29" lean-forward="true" selection-start-line="14" selection-start-column="29" selection-end-line="14" selection-end-column="29" />
19
+ <state relative-caret-position="965">
20
+ <caret line="85" column="27" lean-forward="true" selection-start-line="85" selection-start-column="27" selection-end-line="85" selection-end-column="27" />
22
21
  </state>
23
22
  </provider>
24
23
  </entry>
@@ -69,8 +68,8 @@
69
68
  <entry file="file://$PROJECT_DIR$/README.md">
70
69
  <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
71
70
  <state split_layout="SPLIT">
72
- <first_editor relative-caret-position="546">
73
- <caret line="42" column="15" selection-start-line="42" selection-start-column="15" selection-end-line="42" selection-end-column="15" />
71
+ <first_editor relative-caret-position="390">
72
+ <caret line="54" column="3" lean-forward="true" selection-start-line="54" selection-start-column="3" selection-end-line="54" selection-end-column="3" />
74
73
  </first_editor>
75
74
  <second_editor />
76
75
  </state>
@@ -150,11 +149,6 @@
150
149
  <item name="binky-builder" type="b2602c69:ProjectViewProjectNode" />
151
150
  <item name="binky-builder" type="462c0819:PsiDirectoryNode" />
152
151
  </path>
153
- <path>
154
- <item name="binky-builder" type="b2602c69:ProjectViewProjectNode" />
155
- <item name="binky-builder" type="462c0819:PsiDirectoryNode" />
156
- <item name="bin" type="462c0819:PsiDirectoryNode" />
157
- </path>
158
152
  <path>
159
153
  <item name="binky-builder" type="b2602c69:ProjectViewProjectNode" />
160
154
  <item name="binky-builder" type="462c0819:PsiDirectoryNode" />
@@ -250,7 +244,7 @@
250
244
  <updated>1596190242171</updated>
251
245
  <workItem from="1596190243364" duration="5305000" />
252
246
  <workItem from="1596196456720" duration="5542000" />
253
- <workItem from="1596439308667" duration="4894000" />
247
+ <workItem from="1596439308667" duration="7519000" />
254
248
  </task>
255
249
  <task id="LOCAL-00001" summary="Binky Builder gem initial commit.">
256
250
  <created>1596191104643</created>
@@ -294,7 +288,21 @@
294
288
  <option name="project" value="LOCAL" />
295
289
  <updated>1596442883197</updated>
296
290
  </task>
297
- <option name="localTasksCounter" value="7" />
291
+ <task id="LOCAL-00007" summary="Binky Builder gem initial commit.">
292
+ <created>1596445109199</created>
293
+ <option name="number" value="00007" />
294
+ <option name="presentableId" value="LOCAL-00007" />
295
+ <option name="project" value="LOCAL" />
296
+ <updated>1596445109199</updated>
297
+ </task>
298
+ <task id="LOCAL-00008" summary="Binky Builder gem initial commit.">
299
+ <created>1596447053126</created>
300
+ <option name="number" value="00008" />
301
+ <option name="presentableId" value="LOCAL-00008" />
302
+ <option name="project" value="LOCAL" />
303
+ <updated>1596447053126</updated>
304
+ </task>
305
+ <option name="localTasksCounter" value="9" />
298
306
  <servers />
299
307
  </component>
300
308
  <component name="TestHistory">
@@ -303,13 +311,13 @@
303
311
  </history-entry>
304
312
  </component>
305
313
  <component name="TimeTrackingManager">
306
- <option name="totallyTimeSpent" value="15741000" />
314
+ <option name="totallyTimeSpent" value="18366000" />
307
315
  </component>
308
316
  <component name="ToolWindowManager">
309
317
  <frame x="1920" y="28" width="1920" height="1052" extended-state="6" />
310
318
  <editor active="true" />
311
319
  <layout>
312
- <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2453125" />
320
+ <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.1625" />
313
321
  <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
314
322
  <window_info id="Favorites" order="2" side_tool="true" />
315
323
  <window_info anchor="bottom" id="Message" order="0" />
@@ -368,30 +376,30 @@
368
376
  </state>
369
377
  </provider>
370
378
  </entry>
379
+ <entry file="file://$PROJECT_DIR$/test/test_helper.rb">
380
+ <provider selected="true" editor-type-id="text-editor" />
381
+ </entry>
382
+ <entry file="file://$PROJECT_DIR$/binky-builder.gemspec">
383
+ <provider selected="true" editor-type-id="text-editor">
384
+ <state relative-caret-position="416">
385
+ <caret line="16" column="47" selection-start-line="16" selection-start-column="47" selection-end-line="16" selection-end-column="47" />
386
+ </state>
387
+ </provider>
388
+ </entry>
371
389
  <entry file="file://$PROJECT_DIR$/README.md">
372
390
  <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
373
391
  <state split_layout="SPLIT">
374
- <first_editor relative-caret-position="546">
375
- <caret line="42" column="15" selection-start-line="42" selection-start-column="15" selection-end-line="42" selection-end-column="15" />
392
+ <first_editor relative-caret-position="390">
393
+ <caret line="54" column="3" lean-forward="true" selection-start-line="54" selection-start-column="3" selection-end-line="54" selection-end-column="3" />
376
394
  </first_editor>
377
395
  <second_editor />
378
396
  </state>
379
397
  </provider>
380
398
  </entry>
381
- <entry file="file://$PROJECT_DIR$/test/test_helper.rb">
382
- <provider selected="true" editor-type-id="text-editor" />
383
- </entry>
384
399
  <entry file="file://$PROJECT_DIR$/lib/binky/builder.rb">
385
400
  <provider selected="true" editor-type-id="text-editor">
386
- <state relative-caret-position="364">
387
- <caret line="14" column="29" lean-forward="true" selection-start-line="14" selection-start-column="29" selection-end-line="14" selection-end-column="29" />
388
- </state>
389
- </provider>
390
- </entry>
391
- <entry file="file://$PROJECT_DIR$/binky-builder.gemspec">
392
- <provider selected="true" editor-type-id="text-editor">
393
- <state relative-caret-position="416">
394
- <caret line="16" column="47" selection-start-line="16" selection-start-column="47" selection-end-line="16" selection-end-column="47" />
401
+ <state relative-caret-position="965">
402
+ <caret line="85" column="27" lean-forward="true" selection-start-line="85" selection-start-column="27" selection-end-line="85" selection-end-column="27" />
395
403
  </state>
396
404
  </provider>
397
405
  </entry>
data/README.md CHANGED
@@ -21,7 +21,7 @@ OpenStruct and accessor builder modules.
21
21
 
22
22
  ### Used as OpenStruct
23
23
  Initialize an instance using json data, including the Builder class on your class definition.
24
- Once initialized just use the accessors as a normal class instance.
24
+ Once initialized just use the accessors as any other instance.
25
25
  ```ruby
26
26
  class Issue
27
27
  include Binky::Builder
@@ -31,20 +31,40 @@ Once initialized just use the accessors as a normal class instance.
31
31
  super_initialize json
32
32
  end
33
33
  end
34
+
35
+ issue = Issue.new({id: 1234})
36
+ issue.id # => 1234
34
37
  ```
35
38
 
36
39
  ### Used on ActiveRecord models
37
40
  Binky-Builder includes another helper that can be used to initialize *ActiveRecord* models based on its column names.
38
41
  ```ruby
39
- class ChangeLog < ApplicationRecord
40
- include Binky::BuilderHelper
42
+ class Issue < ApplicationRecord
43
+ include Binky::BuilderHelper
44
+ end
45
+
46
+ issue = Issue.new.build_by_keys({id: 1234},Issue.column_names) # => Issue.column_names = id:
47
+ issue.id # => 1234
48
+ ```
49
+
50
+ Call *build_by_keys* method once the model has been initialized passing a json message,
51
+ it will *yield* self as a block in case you want to perform further actions.
52
+ This method will also create an instance variable called *@to_hash* contains a pair-value hash as a result.
53
+ ```ruby
54
+ build_by_keys(json = {},keys = nil)
41
55
  ```
42
56
 
43
- Call *initialize_by_keys* method once the model has been initialized passing a json message.
44
- This method will *yield* self as a block. This method will also create an instance variable called *@to_hash*.
57
+ ### Auxiliary methods
58
+ Binky-Builder comes with two extra methods to search and create instance variable and methods.
59
+ It creates a instance variable along with its accessor methods (read/write).
45
60
  ```ruby
46
- build_by_keys(json = {})(&:column_names)
61
+ accessor_builder(key, value)
47
62
  ```
63
+ This method goes through the whole object, being a hash, looking for the passed key and return the value found.
64
+ ```ruby
65
+ nested_hash_value(obj, key)
66
+ ```
67
+
48
68
 
49
69
  ## Development
50
70
 
@@ -12,7 +12,7 @@ module Binky
12
12
  raise ArgumentError unless k&.respond_to?(:each)
13
13
  k.each do |key|
14
14
  @to_hash.merge!({key => nested_hash_value(json,key)})
15
- end unless json&.blank?
15
+ end unless json.blank?
16
16
  yield self if block_given?
17
17
  end
18
18
 
@@ -61,7 +61,7 @@ module Binky
61
61
  @attributes = {}
62
62
  json.each do |k, v|
63
63
  self.send("#{k}=", v)
64
- end unless json&.blank?
64
+ end unless json.blank?
65
65
  end
66
66
 
67
67
  def method_missing(name, *args)
@@ -1,5 +1,5 @@
1
1
  module Binky
2
2
  module Builder
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binky-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduard Garcia Castello