binky-builder 0.1.0 → 0.1.1
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 +4 -4
- data/.idea/workspace.xml +140 -49
- data/README.md +1 -1
- data/lib/binky/builder.rb +51 -1
- data/lib/binky/builder/version.rb +1 -1
- metadata +1 -2
- data/lib/binky/builder/builder_helper.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28356c5e83c4eacb791af7fcedbc00dd1642eb57d32a5d86ffe19a2a1fb39208
|
4
|
+
data.tar.gz: 8210ea517e156cec26aa68e1fdc5092a5fcbc0490906380cf4145c6c8559b2bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70d4f074376d61fc6d292780254af6ec310045417e255d323153a663536f1ca5297a7f0a1388bb7c6e586f8c963ef08ef000e1ce34495009e0bd6551de12289
|
7
|
+
data.tar.gz: 3b66c02cf97dbfa53f81f43fa0f460d9c96314634e8866515c7d1a7aafc029cdd743577b8b14b6e72b6baf55883e38d9304b92cd0dde62942da7f8bd14e4f1d3
|
data/.idea/workspace.xml
CHANGED
@@ -2,8 +2,10 @@
|
|
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
|
6
|
-
<change beforePath="$PROJECT_DIR$/binky
|
5
|
+
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
6
|
+
<change beforePath="$PROJECT_DIR$/lib/binky/builder.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/binky/builder.rb" afterDir="false" />
|
7
|
+
<change beforePath="$PROJECT_DIR$/lib/binky/builder/builder_helper.rb" beforeDir="false" />
|
8
|
+
<change beforePath="$PROJECT_DIR$/lib/binky/builder/version.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/binky/builder/version.rb" afterDir="false" />
|
7
9
|
</list>
|
8
10
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
9
11
|
<option name="SHOW_DIALOG" value="false" />
|
@@ -16,40 +18,36 @@
|
|
16
18
|
<file pinned="false" current-in-tab="false">
|
17
19
|
<entry file="file://$PROJECT_DIR$/lib/binky/builder.rb">
|
18
20
|
<provider selected="true" editor-type-id="text-editor">
|
19
|
-
<state relative-caret-position="
|
20
|
-
<caret line="
|
21
|
+
<state relative-caret-position="463">
|
22
|
+
<caret line="59" column="22" lean-forward="true" selection-start-line="59" selection-start-column="22" selection-end-line="59" selection-end-column="22" />
|
21
23
|
</state>
|
22
24
|
</provider>
|
23
25
|
</entry>
|
24
26
|
</file>
|
25
|
-
<file pinned="false" current-in-tab="
|
26
|
-
<entry file="file://$PROJECT_DIR$/lib/binky/builder/
|
27
|
+
<file pinned="false" current-in-tab="true">
|
28
|
+
<entry file="file://$PROJECT_DIR$/lib/binky/builder/version.rb">
|
27
29
|
<provider selected="true" editor-type-id="text-editor">
|
28
|
-
<state relative-caret-position="
|
29
|
-
<caret line="
|
30
|
+
<state relative-caret-position="52">
|
31
|
+
<caret line="2" column="20" selection-start-line="2" selection-start-column="20" selection-end-line="2" selection-end-column="20" />
|
30
32
|
</state>
|
31
33
|
</provider>
|
32
34
|
</entry>
|
33
35
|
</file>
|
34
36
|
<file pinned="false" current-in-tab="false">
|
35
|
-
<entry file="file://$PROJECT_DIR
|
36
|
-
<provider selected="true" editor-type-id="text-editor"
|
37
|
-
<state relative-caret-position="104">
|
38
|
-
<caret line="4" selection-start-line="4" selection-end-line="4" />
|
39
|
-
</state>
|
40
|
-
</provider>
|
37
|
+
<entry file="file://$PROJECT_DIR$/.travis.yml">
|
38
|
+
<provider selected="true" editor-type-id="text-editor" />
|
41
39
|
</entry>
|
42
40
|
</file>
|
43
41
|
<file pinned="false" current-in-tab="false">
|
44
|
-
<entry file="file://$PROJECT_DIR$/.
|
42
|
+
<entry file="file://$PROJECT_DIR$/.gitignore">
|
45
43
|
<provider selected="true" editor-type-id="text-editor" />
|
46
44
|
</entry>
|
47
45
|
</file>
|
48
|
-
<file pinned="false" current-in-tab="
|
46
|
+
<file pinned="false" current-in-tab="false">
|
49
47
|
<entry file="file://$PROJECT_DIR$/binky-builder.gemspec">
|
50
48
|
<provider selected="true" editor-type-id="text-editor">
|
51
|
-
<state relative-caret-position="
|
52
|
-
<caret line="
|
49
|
+
<state relative-caret-position="416">
|
50
|
+
<caret line="16" column="47" selection-start-line="16" selection-start-column="47" selection-end-line="16" selection-end-column="47" />
|
53
51
|
</state>
|
54
52
|
</provider>
|
55
53
|
</entry>
|
@@ -63,8 +61,8 @@
|
|
63
61
|
<entry file="file://$PROJECT_DIR$/README.md">
|
64
62
|
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
|
65
63
|
<state split_layout="SPLIT">
|
66
|
-
<first_editor
|
67
|
-
<caret
|
64
|
+
<first_editor>
|
65
|
+
<caret column="27" selection-start-column="27" selection-end-column="77" />
|
68
66
|
</first_editor>
|
69
67
|
<second_editor />
|
70
68
|
</state>
|
@@ -72,10 +70,19 @@
|
|
72
70
|
</entry>
|
73
71
|
</file>
|
74
72
|
<file pinned="false" current-in-tab="false">
|
75
|
-
<entry file="file://$PROJECT_DIR$/
|
73
|
+
<entry file="file://$PROJECT_DIR$/test/test_helper.rb">
|
76
74
|
<provider selected="true" editor-type-id="text-editor" />
|
77
75
|
</entry>
|
78
76
|
</file>
|
77
|
+
<file pinned="false" current-in-tab="false">
|
78
|
+
<entry file="file://$PROJECT_DIR$/test/binky/builder_test.rb">
|
79
|
+
<provider selected="true" editor-type-id="text-editor">
|
80
|
+
<state relative-caret-position="208">
|
81
|
+
<caret line="8" column="40" selection-start-line="8" selection-start-column="40" selection-end-line="8" selection-end-column="40" />
|
82
|
+
</state>
|
83
|
+
</provider>
|
84
|
+
</entry>
|
85
|
+
</file>
|
79
86
|
</leaf>
|
80
87
|
</component>
|
81
88
|
<component name="FileTemplateManagerImpl">
|
@@ -92,10 +99,11 @@
|
|
92
99
|
<option name="CHANGED_PATHS">
|
93
100
|
<list>
|
94
101
|
<option value="$PROJECT_DIR$/lib/binky/builder/builder_helper.rb" />
|
102
|
+
<option value="$PROJECT_DIR$/binky-builder.gemspec" />
|
103
|
+
<option value="$PROJECT_DIR$/README.md" />
|
104
|
+
<option value="$PROJECT_DIR$/test/binky/builder_test.rb" />
|
95
105
|
<option value="$PROJECT_DIR$/lib/binky/builder.rb" />
|
96
106
|
<option value="$PROJECT_DIR$/lib/binky/builder/version.rb" />
|
97
|
-
<option value="$PROJECT_DIR$/README.md" />
|
98
|
-
<option value="$PROJECT_DIR$/binky-builder.gemspec" />
|
99
107
|
</list>
|
100
108
|
</option>
|
101
109
|
</component>
|
@@ -145,6 +153,17 @@
|
|
145
153
|
<item name="binky" type="462c0819:PsiDirectoryNode" />
|
146
154
|
<item name="builder" type="462c0819:PsiDirectoryNode" />
|
147
155
|
</path>
|
156
|
+
<path>
|
157
|
+
<item name="binky-builder" type="b2602c69:ProjectViewProjectNode" />
|
158
|
+
<item name="binky-builder" type="462c0819:PsiDirectoryNode" />
|
159
|
+
<item name="test" type="462c0819:PsiDirectoryNode" />
|
160
|
+
</path>
|
161
|
+
<path>
|
162
|
+
<item name="binky-builder" type="b2602c69:ProjectViewProjectNode" />
|
163
|
+
<item name="binky-builder" type="462c0819:PsiDirectoryNode" />
|
164
|
+
<item name="test" type="462c0819:PsiDirectoryNode" />
|
165
|
+
<item name="binky" type="462c0819:PsiDirectoryNode" />
|
166
|
+
</path>
|
148
167
|
</expand>
|
149
168
|
<select />
|
150
169
|
</subPane>
|
@@ -154,6 +173,7 @@
|
|
154
173
|
</component>
|
155
174
|
<component name="PropertiesComponent">
|
156
175
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
176
|
+
<property name="last_opened_file_path" value="$USER_HOME$" />
|
157
177
|
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
|
158
178
|
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
|
159
179
|
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
|
@@ -170,6 +190,42 @@
|
|
170
190
|
</list>
|
171
191
|
</option>
|
172
192
|
</component>
|
193
|
+
<component name="RunManager">
|
194
|
+
<configuration name="All tests in test: binky-builder" type="TestUnitRunConfigurationType" factoryName="Test::Unit/Shoulda/Minitest" temporary="true">
|
195
|
+
<module name="binky-builder" />
|
196
|
+
<predefined_log_file enabled="true" id="RUBY_TESTUNIT" />
|
197
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-Ilib:test" />
|
198
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
199
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
200
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
201
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
202
|
+
<envs>
|
203
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
204
|
+
</envs>
|
205
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
206
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
207
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov">
|
208
|
+
<COVERAGE_PATTERN ENABLED="true">
|
209
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
210
|
+
</COVERAGE_PATTERN>
|
211
|
+
</EXTENSION>
|
212
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="$MODULE_DIR$/test" />
|
213
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
|
214
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/{*_test,test_*,*_spec}.rb" />
|
215
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_METHOD_NAME" VALUE="" />
|
216
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="ALL_IN_FOLDER" />
|
217
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
218
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
219
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
|
220
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_OPTIONS" VALUE="" />
|
221
|
+
<method v="2" />
|
222
|
+
</configuration>
|
223
|
+
<recent_temporary>
|
224
|
+
<list>
|
225
|
+
<item itemvalue="Test::Unit/Shoulda/Minitest.All tests in test: binky-builder" />
|
226
|
+
</list>
|
227
|
+
</recent_temporary>
|
228
|
+
</component>
|
173
229
|
<component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" />
|
174
230
|
<component name="TaskManager">
|
175
231
|
<task active="true" id="Default" summary="Default task">
|
@@ -178,7 +234,7 @@
|
|
178
234
|
<option name="number" value="Default" />
|
179
235
|
<option name="presentableId" value="Default" />
|
180
236
|
<updated>1596190242171</updated>
|
181
|
-
<workItem from="1596190243364" duration="
|
237
|
+
<workItem from="1596190243364" duration="4804000" />
|
182
238
|
</task>
|
183
239
|
<task id="LOCAL-00001" summary="Binky Builder gem initial commit.">
|
184
240
|
<created>1596191104643</created>
|
@@ -187,11 +243,30 @@
|
|
187
243
|
<option name="project" value="LOCAL" />
|
188
244
|
<updated>1596191104643</updated>
|
189
245
|
</task>
|
190
|
-
<
|
246
|
+
<task id="LOCAL-00002" summary="Binky Builder gem initial commit.">
|
247
|
+
<created>1596192937723</created>
|
248
|
+
<option name="number" value="00002" />
|
249
|
+
<option name="presentableId" value="LOCAL-00002" />
|
250
|
+
<option name="project" value="LOCAL" />
|
251
|
+
<updated>1596192937723</updated>
|
252
|
+
</task>
|
253
|
+
<task id="LOCAL-00003" summary="Binky Builder gem initial commit.">
|
254
|
+
<created>1596194970038</created>
|
255
|
+
<option name="number" value="00003" />
|
256
|
+
<option name="presentableId" value="LOCAL-00003" />
|
257
|
+
<option name="project" value="LOCAL" />
|
258
|
+
<updated>1596194970038</updated>
|
259
|
+
</task>
|
260
|
+
<option name="localTasksCounter" value="4" />
|
191
261
|
<servers />
|
192
262
|
</component>
|
263
|
+
<component name="TestHistory">
|
264
|
+
<history-entry file="All_tests_in_test__binky-builder - 2020.07.31 at 13h 29m 07s.xml">
|
265
|
+
<configuration name="All tests in test: binky-builder" configurationId="TestUnitRunConfigurationType" />
|
266
|
+
</history-entry>
|
267
|
+
</component>
|
193
268
|
<component name="TimeTrackingManager">
|
194
|
-
<option name="totallyTimeSpent" value="
|
269
|
+
<option name="totallyTimeSpent" value="4804000" />
|
195
270
|
</component>
|
196
271
|
<component name="ToolWindowManager">
|
197
272
|
<frame x="0" y="0" width="1920" height="1200" extended-state="6" />
|
@@ -206,8 +281,8 @@
|
|
206
281
|
<window_info anchor="bottom" id="Terminal" />
|
207
282
|
<window_info anchor="bottom" id="Event Log" side_tool="true" />
|
208
283
|
<window_info anchor="bottom" id="Message" order="0" />
|
209
|
-
<window_info anchor="bottom" id="Find" order="1" />
|
210
|
-
<window_info anchor="bottom" id="Run" order="2"
|
284
|
+
<window_info anchor="bottom" id="Find" order="1" weight="0.32976827" />
|
285
|
+
<window_info anchor="bottom" id="Run" order="2" weight="0.32976827" />
|
211
286
|
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
212
287
|
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
213
288
|
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
@@ -225,51 +300,67 @@
|
|
225
300
|
<MESSAGE value="Binky Builder gem initial commit." />
|
226
301
|
<option name="LAST_COMMIT_MESSAGE" value="Binky Builder gem initial commit." />
|
227
302
|
</component>
|
303
|
+
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
304
|
+
<SUITE FILE_PATH="coverage/binky_builder@All_tests_in_test__binky_builder.rcov" NAME="All tests in test: binky-builder Coverage Results" MODIFIED="1596194945839" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="binky-builder" />
|
305
|
+
</component>
|
228
306
|
<component name="editorHistoryManager">
|
307
|
+
<entry file="file://$PROJECT_DIR$/Gemfile">
|
308
|
+
<provider selected="true" editor-type-id="text-editor" />
|
309
|
+
</entry>
|
310
|
+
<entry file="file://$PROJECT_DIR$/LICENSE.txt">
|
311
|
+
<provider selected="true" editor-type-id="text-editor" />
|
312
|
+
</entry>
|
229
313
|
<entry file="file://$PROJECT_DIR$/.travis.yml">
|
230
314
|
<provider selected="true" editor-type-id="text-editor" />
|
231
315
|
</entry>
|
232
|
-
<entry file="file://$PROJECT_DIR
|
316
|
+
<entry file="file://$PROJECT_DIR$/.gitignore">
|
233
317
|
<provider selected="true" editor-type-id="text-editor" />
|
234
318
|
</entry>
|
235
|
-
<entry file="file://$PROJECT_DIR$/
|
319
|
+
<entry file="file://$PROJECT_DIR$/README.md">
|
320
|
+
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
|
321
|
+
<state split_layout="SPLIT">
|
322
|
+
<first_editor>
|
323
|
+
<caret column="27" selection-start-column="27" selection-end-column="77" />
|
324
|
+
</first_editor>
|
325
|
+
<second_editor />
|
326
|
+
</state>
|
327
|
+
</provider>
|
328
|
+
</entry>
|
329
|
+
<entry file="file://$PROJECT_DIR$/test/test_helper.rb">
|
330
|
+
<provider selected="true" editor-type-id="text-editor" />
|
331
|
+
</entry>
|
332
|
+
<entry file="file://$PROJECT_DIR$/test/binky/builder_test.rb">
|
236
333
|
<provider selected="true" editor-type-id="text-editor">
|
237
|
-
<state relative-caret-position="
|
238
|
-
<caret line="
|
334
|
+
<state relative-caret-position="208">
|
335
|
+
<caret line="8" column="40" selection-start-line="8" selection-start-column="40" selection-end-line="8" selection-end-column="40" />
|
239
336
|
</state>
|
240
337
|
</provider>
|
241
338
|
</entry>
|
242
339
|
<entry file="file://$PROJECT_DIR$/lib/binky/builder/builder_helper.rb">
|
243
340
|
<provider selected="true" editor-type-id="text-editor">
|
244
|
-
<state relative-caret-position="
|
245
|
-
<caret line="
|
341
|
+
<state relative-caret-position="639">
|
342
|
+
<caret line="48" selection-end-line="48" />
|
246
343
|
</state>
|
247
344
|
</provider>
|
248
345
|
</entry>
|
249
346
|
<entry file="file://$PROJECT_DIR$/lib/binky/builder.rb">
|
250
347
|
<provider selected="true" editor-type-id="text-editor">
|
251
|
-
<state relative-caret-position="
|
252
|
-
<caret line="
|
348
|
+
<state relative-caret-position="463">
|
349
|
+
<caret line="59" column="22" lean-forward="true" selection-start-line="59" selection-start-column="22" selection-end-line="59" selection-end-column="22" />
|
253
350
|
</state>
|
254
351
|
</provider>
|
255
352
|
</entry>
|
256
|
-
<entry file="file://$PROJECT_DIR$/
|
257
|
-
<provider selected="true" editor-type-id="text-editor"
|
258
|
-
|
259
|
-
|
260
|
-
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
|
261
|
-
<state split_layout="SPLIT">
|
262
|
-
<first_editor relative-caret-position="208">
|
263
|
-
<caret line="8" column="3" lean-forward="true" selection-start-line="8" selection-start-column="3" selection-end-line="8" selection-end-column="3" />
|
264
|
-
</first_editor>
|
265
|
-
<second_editor />
|
353
|
+
<entry file="file://$PROJECT_DIR$/binky-builder.gemspec">
|
354
|
+
<provider selected="true" editor-type-id="text-editor">
|
355
|
+
<state relative-caret-position="416">
|
356
|
+
<caret line="16" column="47" selection-start-line="16" selection-start-column="47" selection-end-line="16" selection-end-column="47" />
|
266
357
|
</state>
|
267
358
|
</provider>
|
268
359
|
</entry>
|
269
|
-
<entry file="file://$PROJECT_DIR$/binky
|
360
|
+
<entry file="file://$PROJECT_DIR$/lib/binky/builder/version.rb">
|
270
361
|
<provider selected="true" editor-type-id="text-editor">
|
271
|
-
<state relative-caret-position="
|
272
|
-
<caret line="
|
362
|
+
<state relative-caret-position="52">
|
363
|
+
<caret line="2" column="20" selection-start-line="2" selection-start-column="20" selection-end-line="2" selection-end-column="20" />
|
273
364
|
</state>
|
274
365
|
</provider>
|
275
366
|
</entry>
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Binky::Builder  [](https://rubygems.org/gems/binky-builder)
|
2
2
|
|
3
3
|
## Installation
|
4
4
|
|
data/lib/binky/builder.rb
CHANGED
@@ -1,7 +1,57 @@
|
|
1
1
|
require "binky/builder/version"
|
2
|
-
require "binky/builder/builder_helper"
|
3
2
|
|
4
3
|
module Binky
|
4
|
+
module BuilderHelper
|
5
|
+
|
6
|
+
# Builds an instance variable as well as its class method accessors from a key value pair.
|
7
|
+
def accessor_builder k, v
|
8
|
+
self.instance_variable_set("@#{k}", v)
|
9
|
+
self.class.send(:define_method, "#{k}", proc {self.instance_variable_get("@#{k}")})
|
10
|
+
self.class.send(:define_method, "#{k}=", proc {|v| self.instance_variable_set("@#{k}", v)})
|
11
|
+
end
|
12
|
+
|
13
|
+
#Goes through a complex Hash nest and gets the value of a passed key.
|
14
|
+
# First wil check whether the object has the key? method,
|
15
|
+
# which will mean it's a Hash and also if the Hash the method parameter key
|
16
|
+
# if obj.respond_to?(:key?) && obj.key?(key)
|
17
|
+
#
|
18
|
+
# If it's not a Hash will check if it's a Array instead,
|
19
|
+
# checking out whether it responds to a Array.each method or not.
|
20
|
+
# elsif obj.respond_to?(:each)
|
21
|
+
#
|
22
|
+
# For every Array found it make a recursive call to itself passing
|
23
|
+
# the last element of the array and the Key it's looking for.
|
24
|
+
# r = nested_hash_value(a.last, key)
|
25
|
+
def nested_hash_value(obj, key)
|
26
|
+
if obj.respond_to?(:key?) && obj.key?(key)
|
27
|
+
obj[key]
|
28
|
+
elsif obj.respond_to?(:each)
|
29
|
+
r = nil
|
30
|
+
#The asterisk "splat" operator means you can pass multiple parameters in its place and the block will see them as an array.
|
31
|
+
obj.find do |*a|
|
32
|
+
r = nested_hash_value(a.last, key)
|
33
|
+
end
|
34
|
+
r
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Parses a given json structure looking for specific keys inside the structure.
|
39
|
+
# The result of it it's stored on a instance variable called to_hash and accessible through accessors with same name.
|
40
|
+
def parse(json = {},keys = [])
|
41
|
+
accessor_builder('to_hash',{})
|
42
|
+
keys.each do |key|
|
43
|
+
@to_hash.merge!({key => nested_hash_value(json,key)})
|
44
|
+
end unless json.blank?
|
45
|
+
end
|
46
|
+
|
47
|
+
def attribute_from_inner_key(element, attribute, inner_key = nil)
|
48
|
+
{attribute.to_sym => nested_hash_value(element, inner_key.present? ? inner_key : attribute.to_s)}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
5
55
|
module Builder
|
6
56
|
class Error < StandardError; end
|
7
57
|
include BuilderHelper
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduard Garcia Castello
|
@@ -29,7 +29,6 @@ files:
|
|
29
29
|
- bin/setup
|
30
30
|
- binky-builder.gemspec
|
31
31
|
- lib/binky/builder.rb
|
32
|
-
- lib/binky/builder/builder_helper.rb
|
33
32
|
- lib/binky/builder/version.rb
|
34
33
|
homepage: https://github.com/eddygarcas/binky-builder
|
35
34
|
licenses:
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module BuilderHelper
|
2
|
-
|
3
|
-
# Builds an instance variable as well as its class method accessors from a key value pair.
|
4
|
-
def accessor_builder k, v
|
5
|
-
self.instance_variable_set("@#{k}", v)
|
6
|
-
self.class.send(:define_method, "#{k}", proc {self.instance_variable_get("@#{k}")})
|
7
|
-
self.class.send(:define_method, "#{k}=", proc {|v| self.instance_variable_set("@#{k}", v)})
|
8
|
-
end
|
9
|
-
|
10
|
-
#Goes through a complex Hash nest and gets the value of a passed key.
|
11
|
-
# First wil check whether the object has the key? method,
|
12
|
-
# which will mean it's a Hash and also if the Hash the method parameter key
|
13
|
-
# if obj.respond_to?(:key?) && obj.key?(key)
|
14
|
-
#
|
15
|
-
# If it's not a Hash will check if it's a Array instead,
|
16
|
-
# checking out whether it responds to a Array.each method or not.
|
17
|
-
# elsif obj.respond_to?(:each)
|
18
|
-
#
|
19
|
-
# For every Array found it make a recursive call to itself passing
|
20
|
-
# the last element of the array and the Key it's looking for.
|
21
|
-
# r = nested_hash_value(a.last, key)
|
22
|
-
def nested_hash_value(obj, key)
|
23
|
-
if obj.respond_to?(:key?) && obj.key?(key)
|
24
|
-
obj[key]
|
25
|
-
elsif obj.respond_to?(:each)
|
26
|
-
r = nil
|
27
|
-
#The asterisk "splat" operator means you can pass multiple parameters in its place and the block will see them as an array.
|
28
|
-
obj.find do |*a|
|
29
|
-
r = nested_hash_value(a.last, key)
|
30
|
-
end
|
31
|
-
r
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Parses a given json structure looking for specific keys inside the structure.
|
36
|
-
# The result of it it's stored on a instance variable called to_hash and accessible through accessors with same name.
|
37
|
-
def parse(json = {},keys = [])
|
38
|
-
accessor_builder('to_hash',{})
|
39
|
-
keys.each do |key|
|
40
|
-
@to_hash.merge!({key => nested_hash_value(json,key)})
|
41
|
-
end unless json.blank?
|
42
|
-
end
|
43
|
-
|
44
|
-
def attribute_from_inner_key(element, attribute, inner_key = nil)
|
45
|
-
{attribute.to_sym => nested_hash_value(element, inner_key.present? ? inner_key : attribute.to_s)}
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|