nucleon 0.2.2 → 0.2.3
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 +7 -7
- data/.gitignore +50 -0
- data/ARCHITECTURE.rdoc +12 -11
- data/Gemfile +7 -11
- data/Gemfile.lock +47 -70
- data/Rakefile +22 -20
- data/TODO.rdoc +1 -1
- data/VERSION +1 -1
- data/bin/nucleon +16 -15
- data/lib/core/codes.rb +65 -38
- data/lib/core/config.rb +774 -153
- data/lib/core/config/collection.rb +134 -25
- data/lib/core/config/options.rb +160 -36
- data/lib/core/core.rb +207 -45
- data/lib/core/environment.rb +626 -206
- data/lib/core/facade.rb +211 -185
- data/lib/core/gems.rb +60 -44
- data/lib/core/manager.rb +587 -237
- data/lib/core/mixin/colors.rb +66 -36
- data/lib/core/mixin/config/collection.rb +58 -23
- data/lib/core/mixin/config/options.rb +67 -24
- data/lib/core/mixin/macro/object_interface.rb +129 -135
- data/lib/core/mixin/macro/plugin_interface.rb +118 -124
- data/lib/core/mixin/settings.rb +7 -13
- data/lib/core/mixin/sub_config.rb +37 -43
- data/lib/core/mod/hash.rb +31 -10
- data/lib/core/plugin/action.rb +274 -238
- data/lib/core/plugin/base.rb +140 -132
- data/lib/core/plugin/project.rb +316 -311
- data/lib/core/util/cli.rb +146 -146
- data/lib/core/util/console.rb +567 -124
- data/lib/core/util/data.rb +654 -139
- data/lib/core/util/logger.rb +255 -66
- data/lib/nucleon.rb +6 -8
- data/lib/nucleon_base.rb +364 -106
- data/nucleon.gemspec +40 -389
- data/spec/core/codes_spec.rb +209 -0
- data/spec/core/config_spec.rb +810 -0
- data/spec/core/core_spec.rb +185 -0
- data/spec/core/environment_spec.rb +148 -0
- data/spec/core/util/console_spec.rb +254 -446
- data/spec/nucleon/test.rb +59 -0
- data/spec/nucleon/test/first.rb +28 -0
- data/spec/nucleon/test/second.rb +28 -0
- data/spec/nucleon_codes.rb +98 -0
- data/spec/nucleon_config.rb +523 -0
- data/spec/nucleon_plugin.rb +439 -0
- data/spec/nucleon_test.rb +34 -0
- data/spec/spec_helper.rb +6 -4
- metadata +157 -615
- data/.document +0 -5
- data/rdoc/site/0.1.19/ARCHITECTURE_rdoc.html +0 -634
- data/rdoc/site/0.1.19/Hash.html +0 -347
- data/rdoc/site/0.1.19/Kernel.html +0 -413
- data/rdoc/site/0.1.19/Nucleon.html +0 -570
- data/rdoc/site/0.1.19/Nucleon/Action.html +0 -280
- data/rdoc/site/0.1.19/Nucleon/Action/Add.html +0 -458
- data/rdoc/site/0.1.19/Nucleon/Action/Create.html +0 -415
- data/rdoc/site/0.1.19/Nucleon/Action/Extract.html +0 -413
- data/rdoc/site/0.1.19/Nucleon/Action/Remove.html +0 -461
- data/rdoc/site/0.1.19/Nucleon/Action/Save.html +0 -434
- data/rdoc/site/0.1.19/Nucleon/Action/Update.html +0 -381
- data/rdoc/site/0.1.19/Nucleon/Codes.html +0 -563
- data/rdoc/site/0.1.19/Nucleon/Command.html +0 -275
- data/rdoc/site/0.1.19/Nucleon/Command/Bash.html +0 -544
- data/rdoc/site/0.1.19/Nucleon/Config.html +0 -1623
- data/rdoc/site/0.1.19/Nucleon/Config/Collection.html +0 -509
- data/rdoc/site/0.1.19/Nucleon/Config/Options.html +0 -489
- data/rdoc/site/0.1.19/Nucleon/Core.html +0 -635
- data/rdoc/site/0.1.19/Nucleon/Errors.html +0 -275
- data/rdoc/site/0.1.19/Nucleon/Errors/BatchError.html +0 -281
- data/rdoc/site/0.1.19/Nucleon/Errors/NucleonError.html +0 -657
- data/rdoc/site/0.1.19/Nucleon/Errors/SSHUnavailable.html +0 -281
- data/rdoc/site/0.1.19/Nucleon/Event.html +0 -275
- data/rdoc/site/0.1.19/Nucleon/Event/Regex.html +0 -467
- data/rdoc/site/0.1.19/Nucleon/Facade.html +0 -2336
- data/rdoc/site/0.1.19/Nucleon/Gems.html +0 -635
- data/rdoc/site/0.1.19/Nucleon/Manager.html +0 -1828
- data/rdoc/site/0.1.19/Nucleon/Mixin.html +0 -284
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action.html +0 -277
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action/Commit.html +0 -381
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action/Project.html +0 -395
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action/Push.html +0 -371
- data/rdoc/site/0.1.19/Nucleon/Mixin/Colors.html +0 -545
- data/rdoc/site/0.1.19/Nucleon/Mixin/ConfigCollection.html +0 -481
- data/rdoc/site/0.1.19/Nucleon/Mixin/ConfigOptions.html +0 -449
- data/rdoc/site/0.1.19/Nucleon/Mixin/Macro.html +0 -276
- data/rdoc/site/0.1.19/Nucleon/Mixin/Macro/ObjectInterface.html +0 -695
- data/rdoc/site/0.1.19/Nucleon/Mixin/Macro/PluginInterface.html +0 -682
- data/rdoc/site/0.1.19/Nucleon/Mixin/Settings.html +0 -481
- data/rdoc/site/0.1.19/Nucleon/Mixin/SubConfig.html +0 -887
- data/rdoc/site/0.1.19/Nucleon/Parallel.html +0 -325
- data/rdoc/site/0.1.19/Nucleon/Parallel/ClassMethods.html +0 -325
- data/rdoc/site/0.1.19/Nucleon/Parallel/InstanceMethods.html +0 -334
- data/rdoc/site/0.1.19/Nucleon/Plugin.html +0 -282
- data/rdoc/site/0.1.19/Nucleon/Plugin/Action.html +0 -1368
- data/rdoc/site/0.1.19/Nucleon/Plugin/Action/Option.html +0 -459
- data/rdoc/site/0.1.19/Nucleon/Plugin/Base.html +0 -1737
- data/rdoc/site/0.1.19/Nucleon/Plugin/Command.html +0 -721
- data/rdoc/site/0.1.19/Nucleon/Plugin/Event.html +0 -442
- data/rdoc/site/0.1.19/Nucleon/Plugin/Extension.html +0 -281
- data/rdoc/site/0.1.19/Nucleon/Plugin/Project.html +0 -2864
- data/rdoc/site/0.1.19/Nucleon/Plugin/Template.html +0 -476
- data/rdoc/site/0.1.19/Nucleon/Plugin/Translator.html +0 -371
- data/rdoc/site/0.1.19/Nucleon/Project.html +0 -276
- data/rdoc/site/0.1.19/Nucleon/Project/Git.html +0 -1801
- data/rdoc/site/0.1.19/Nucleon/Project/Github.html +0 -549
- data/rdoc/site/0.1.19/Nucleon/Template.html +0 -277
- data/rdoc/site/0.1.19/Nucleon/Template/Json.html +0 -329
- data/rdoc/site/0.1.19/Nucleon/Template/Wrapper.html +0 -329
- data/rdoc/site/0.1.19/Nucleon/Template/Yaml.html +0 -329
- data/rdoc/site/0.1.19/Nucleon/Translator.html +0 -276
- data/rdoc/site/0.1.19/Nucleon/Translator/Json.html +0 -366
- data/rdoc/site/0.1.19/Nucleon/Translator/Yaml.html +0 -366
- data/rdoc/site/0.1.19/Nucleon/Util.html +0 -285
- data/rdoc/site/0.1.19/Nucleon/Util/CLI.html +0 -388
- data/rdoc/site/0.1.19/Nucleon/Util/CLI/Parser.html +0 -1183
- data/rdoc/site/0.1.19/Nucleon/Util/Cache.html +0 -780
- data/rdoc/site/0.1.19/Nucleon/Util/Console.html +0 -1294
- data/rdoc/site/0.1.19/Nucleon/Util/Data.html +0 -1399
- data/rdoc/site/0.1.19/Nucleon/Util/Disk.html +0 -522
- data/rdoc/site/0.1.19/Nucleon/Util/Git.html +0 -361
- data/rdoc/site/0.1.19/Nucleon/Util/Liquid.html +0 -365
- data/rdoc/site/0.1.19/Nucleon/Util/Logger.html +0 -806
- data/rdoc/site/0.1.19/Nucleon/Util/Package.html +0 -558
- data/rdoc/site/0.1.19/Nucleon/Util/SSH.html +0 -910
- data/rdoc/site/0.1.19/Nucleon/Util/SSH/Keypair.html +0 -453
- data/rdoc/site/0.1.19/Nucleon/Util/Shell.html +0 -686
- data/rdoc/site/0.1.19/Nucleon/Util/Shell/Result.html +0 -497
- data/rdoc/site/0.1.19/README_rdoc.html +0 -312
- data/rdoc/site/0.1.19/TODO_rdoc.html +0 -267
- data/rdoc/site/0.1.19/created.rid +0 -60
- data/rdoc/site/0.1.19/images/add.png +0 -0
- data/rdoc/site/0.1.19/images/brick.png +0 -0
- data/rdoc/site/0.1.19/images/brick_link.png +0 -0
- data/rdoc/site/0.1.19/images/bug.png +0 -0
- data/rdoc/site/0.1.19/images/bullet_black.png +0 -0
- data/rdoc/site/0.1.19/images/bullet_toggle_minus.png +0 -0
- data/rdoc/site/0.1.19/images/bullet_toggle_plus.png +0 -0
- data/rdoc/site/0.1.19/images/date.png +0 -0
- data/rdoc/site/0.1.19/images/delete.png +0 -0
- data/rdoc/site/0.1.19/images/find.png +0 -0
- data/rdoc/site/0.1.19/images/loadingAnimation.gif +0 -0
- data/rdoc/site/0.1.19/images/macFFBgHack.png +0 -0
- data/rdoc/site/0.1.19/images/package.png +0 -0
- data/rdoc/site/0.1.19/images/page_green.png +0 -0
- data/rdoc/site/0.1.19/images/page_white_text.png +0 -0
- data/rdoc/site/0.1.19/images/page_white_width.png +0 -0
- data/rdoc/site/0.1.19/images/plugin.png +0 -0
- data/rdoc/site/0.1.19/images/ruby.png +0 -0
- data/rdoc/site/0.1.19/images/tag_blue.png +0 -0
- data/rdoc/site/0.1.19/images/tag_green.png +0 -0
- data/rdoc/site/0.1.19/images/transparent.png +0 -0
- data/rdoc/site/0.1.19/images/wrench.png +0 -0
- data/rdoc/site/0.1.19/images/wrench_orange.png +0 -0
- data/rdoc/site/0.1.19/images/zoom.png +0 -0
- data/rdoc/site/0.1.19/index.html +0 -311
- data/rdoc/site/0.1.19/js/darkfish.js +0 -155
- data/rdoc/site/0.1.19/js/jquery.js +0 -18
- data/rdoc/site/0.1.19/js/navigation.js +0 -142
- data/rdoc/site/0.1.19/js/search.js +0 -94
- data/rdoc/site/0.1.19/js/search_index.js +0 -1
- data/rdoc/site/0.1.19/js/searcher.js +0 -228
- data/rdoc/site/0.1.19/rdoc.css +0 -543
- data/rdoc/site/0.1.19/table_of_contents.html +0 -1541
- data/rdoc/site/0.2.0/ARCHITECTURE_rdoc.html +0 -638
- data/rdoc/site/0.2.0/Hash.html +0 -351
- data/rdoc/site/0.2.0/Kernel.html +0 -416
- data/rdoc/site/0.2.0/Nucleon.html +0 -607
- data/rdoc/site/0.2.0/Nucleon/Action.html +0 -284
- data/rdoc/site/0.2.0/Nucleon/Action/Extract.html +0 -455
- data/rdoc/site/0.2.0/Nucleon/Action/Project.html +0 -283
- data/rdoc/site/0.2.0/Nucleon/Action/Project/Add.html +0 -500
- data/rdoc/site/0.2.0/Nucleon/Action/Project/Create.html +0 -457
- data/rdoc/site/0.2.0/Nucleon/Action/Project/Remove.html +0 -503
- data/rdoc/site/0.2.0/Nucleon/Action/Project/Save.html +0 -476
- data/rdoc/site/0.2.0/Nucleon/Action/Project/Update.html +0 -423
- data/rdoc/site/0.2.0/Nucleon/Codes.html +0 -567
- data/rdoc/site/0.2.0/Nucleon/Command.html +0 -279
- data/rdoc/site/0.2.0/Nucleon/Command/Bash.html +0 -548
- data/rdoc/site/0.2.0/Nucleon/Config.html +0 -1631
- data/rdoc/site/0.2.0/Nucleon/Config/Collection.html +0 -513
- data/rdoc/site/0.2.0/Nucleon/Config/Options.html +0 -493
- data/rdoc/site/0.2.0/Nucleon/Core.html +0 -639
- data/rdoc/site/0.2.0/Nucleon/Environment.html +0 -1208
- data/rdoc/site/0.2.0/Nucleon/Errors.html +0 -279
- data/rdoc/site/0.2.0/Nucleon/Errors/BatchError.html +0 -285
- data/rdoc/site/0.2.0/Nucleon/Errors/NucleonError.html +0 -661
- data/rdoc/site/0.2.0/Nucleon/Errors/SSHUnavailable.html +0 -285
- data/rdoc/site/0.2.0/Nucleon/Event.html +0 -279
- data/rdoc/site/0.2.0/Nucleon/Event/Regex.html +0 -471
- data/rdoc/site/0.2.0/Nucleon/Facade.html +0 -2409
- data/rdoc/site/0.2.0/Nucleon/Gems.html +0 -639
- data/rdoc/site/0.2.0/Nucleon/Manager.html +0 -1860
- data/rdoc/site/0.2.0/Nucleon/Mixin.html +0 -288
- data/rdoc/site/0.2.0/Nucleon/Mixin/Action.html +0 -281
- data/rdoc/site/0.2.0/Nucleon/Mixin/Action/Commit.html +0 -385
- data/rdoc/site/0.2.0/Nucleon/Mixin/Action/Project.html +0 -399
- data/rdoc/site/0.2.0/Nucleon/Mixin/Action/Push.html +0 -375
- data/rdoc/site/0.2.0/Nucleon/Mixin/Colors.html +0 -549
- data/rdoc/site/0.2.0/Nucleon/Mixin/ConfigCollection.html +0 -485
- data/rdoc/site/0.2.0/Nucleon/Mixin/ConfigOptions.html +0 -453
- data/rdoc/site/0.2.0/Nucleon/Mixin/Macro.html +0 -280
- data/rdoc/site/0.2.0/Nucleon/Mixin/Macro/ObjectInterface.html +0 -699
- data/rdoc/site/0.2.0/Nucleon/Mixin/Macro/PluginInterface.html +0 -686
- data/rdoc/site/0.2.0/Nucleon/Mixin/Settings.html +0 -485
- data/rdoc/site/0.2.0/Nucleon/Mixin/SubConfig.html +0 -891
- data/rdoc/site/0.2.0/Nucleon/Parallel.html +0 -330
- data/rdoc/site/0.2.0/Nucleon/Parallel/ClassMethods.html +0 -329
- data/rdoc/site/0.2.0/Nucleon/Parallel/InstanceMethods.html +0 -456
- data/rdoc/site/0.2.0/Nucleon/Plugin.html +0 -286
- data/rdoc/site/0.2.0/Nucleon/Plugin/Action.html +0 -1829
- data/rdoc/site/0.2.0/Nucleon/Plugin/Action/Option.html +0 -463
- data/rdoc/site/0.2.0/Nucleon/Plugin/Base.html +0 -1803
- data/rdoc/site/0.2.0/Nucleon/Plugin/Command.html +0 -725
- data/rdoc/site/0.2.0/Nucleon/Plugin/Event.html +0 -446
- data/rdoc/site/0.2.0/Nucleon/Plugin/Extension.html +0 -285
- data/rdoc/site/0.2.0/Nucleon/Plugin/Project.html +0 -2898
- data/rdoc/site/0.2.0/Nucleon/Plugin/Template.html +0 -480
- data/rdoc/site/0.2.0/Nucleon/Plugin/Translator.html +0 -375
- data/rdoc/site/0.2.0/Nucleon/Project.html +0 -280
- data/rdoc/site/0.2.0/Nucleon/Project/Git.html +0 -1805
- data/rdoc/site/0.2.0/Nucleon/Project/Github.html +0 -553
- data/rdoc/site/0.2.0/Nucleon/Template.html +0 -281
- data/rdoc/site/0.2.0/Nucleon/Template/JSON.html +0 -333
- data/rdoc/site/0.2.0/Nucleon/Template/Wrapper.html +0 -333
- data/rdoc/site/0.2.0/Nucleon/Template/YAML.html +0 -333
- data/rdoc/site/0.2.0/Nucleon/Translator.html +0 -280
- data/rdoc/site/0.2.0/Nucleon/Translator/JSON.html +0 -370
- data/rdoc/site/0.2.0/Nucleon/Translator/YAML.html +0 -370
- data/rdoc/site/0.2.0/Nucleon/Util.html +0 -289
- data/rdoc/site/0.2.0/Nucleon/Util/CLI.html +0 -392
- data/rdoc/site/0.2.0/Nucleon/Util/CLI/Parser.html +0 -1250
- data/rdoc/site/0.2.0/Nucleon/Util/Cache.html +0 -784
- data/rdoc/site/0.2.0/Nucleon/Util/Console.html +0 -1318
- data/rdoc/site/0.2.0/Nucleon/Util/Data.html +0 -1411
- data/rdoc/site/0.2.0/Nucleon/Util/Disk.html +0 -526
- data/rdoc/site/0.2.0/Nucleon/Util/Git.html +0 -365
- data/rdoc/site/0.2.0/Nucleon/Util/Liquid.html +0 -369
- data/rdoc/site/0.2.0/Nucleon/Util/Logger.html +0 -810
- data/rdoc/site/0.2.0/Nucleon/Util/Package.html +0 -562
- data/rdoc/site/0.2.0/Nucleon/Util/SSH.html +0 -1033
- data/rdoc/site/0.2.0/Nucleon/Util/SSH/Keypair.html +0 -605
- data/rdoc/site/0.2.0/Nucleon/Util/Shell.html +0 -693
- data/rdoc/site/0.2.0/Nucleon/Util/Shell/Result.html +0 -501
- data/rdoc/site/0.2.0/README_rdoc.html +0 -316
- data/rdoc/site/0.2.0/TODO_rdoc.html +0 -265
- data/rdoc/site/0.2.0/created.rid +0 -61
- data/rdoc/site/0.2.0/images/add.png +0 -0
- data/rdoc/site/0.2.0/images/brick.png +0 -0
- data/rdoc/site/0.2.0/images/brick_link.png +0 -0
- data/rdoc/site/0.2.0/images/bug.png +0 -0
- data/rdoc/site/0.2.0/images/bullet_black.png +0 -0
- data/rdoc/site/0.2.0/images/bullet_toggle_minus.png +0 -0
- data/rdoc/site/0.2.0/images/bullet_toggle_plus.png +0 -0
- data/rdoc/site/0.2.0/images/date.png +0 -0
- data/rdoc/site/0.2.0/images/delete.png +0 -0
- data/rdoc/site/0.2.0/images/find.png +0 -0
- data/rdoc/site/0.2.0/images/loadingAnimation.gif +0 -0
- data/rdoc/site/0.2.0/images/macFFBgHack.png +0 -0
- data/rdoc/site/0.2.0/images/package.png +0 -0
- data/rdoc/site/0.2.0/images/page_green.png +0 -0
- data/rdoc/site/0.2.0/images/page_white_text.png +0 -0
- data/rdoc/site/0.2.0/images/page_white_width.png +0 -0
- data/rdoc/site/0.2.0/images/plugin.png +0 -0
- data/rdoc/site/0.2.0/images/ruby.png +0 -0
- data/rdoc/site/0.2.0/images/tag_blue.png +0 -0
- data/rdoc/site/0.2.0/images/tag_green.png +0 -0
- data/rdoc/site/0.2.0/images/transparent.png +0 -0
- data/rdoc/site/0.2.0/images/wrench.png +0 -0
- data/rdoc/site/0.2.0/images/wrench_orange.png +0 -0
- data/rdoc/site/0.2.0/images/zoom.png +0 -0
- data/rdoc/site/0.2.0/index.html +0 -315
- data/rdoc/site/0.2.0/js/darkfish.js +0 -155
- data/rdoc/site/0.2.0/js/jquery.js +0 -18
- data/rdoc/site/0.2.0/js/navigation.js +0 -142
- data/rdoc/site/0.2.0/js/search.js +0 -94
- data/rdoc/site/0.2.0/js/search_index.js +0 -1
- data/rdoc/site/0.2.0/js/searcher.js +0 -228
- data/rdoc/site/0.2.0/rdoc.css +0 -543
- data/rdoc/site/0.2.0/table_of_contents.html +0 -1657
- data/rdoc/site/0.2.1/ARCHITECTURE_rdoc.html +0 -640
- data/rdoc/site/0.2.1/Hash.html +0 -353
- data/rdoc/site/0.2.1/Kernel.html +0 -420
- data/rdoc/site/0.2.1/Nucleon.html +0 -674
- data/rdoc/site/0.2.1/Nucleon/Action.html +0 -286
- data/rdoc/site/0.2.1/Nucleon/Action/Extract.html +0 -457
- data/rdoc/site/0.2.1/Nucleon/Action/Project.html +0 -285
- data/rdoc/site/0.2.1/Nucleon/Action/Project/Add.html +0 -502
- data/rdoc/site/0.2.1/Nucleon/Action/Project/Create.html +0 -459
- data/rdoc/site/0.2.1/Nucleon/Action/Project/Remove.html +0 -505
- data/rdoc/site/0.2.1/Nucleon/Action/Project/Save.html +0 -478
- data/rdoc/site/0.2.1/Nucleon/Action/Project/Update.html +0 -425
- data/rdoc/site/0.2.1/Nucleon/Codes.html +0 -569
- data/rdoc/site/0.2.1/Nucleon/Command.html +0 -281
- data/rdoc/site/0.2.1/Nucleon/Command/Bash.html +0 -550
- data/rdoc/site/0.2.1/Nucleon/Config.html +0 -1634
- data/rdoc/site/0.2.1/Nucleon/Config/Collection.html +0 -515
- data/rdoc/site/0.2.1/Nucleon/Config/Options.html +0 -495
- data/rdoc/site/0.2.1/Nucleon/Core.html +0 -641
- data/rdoc/site/0.2.1/Nucleon/Environment.html +0 -1210
- data/rdoc/site/0.2.1/Nucleon/Errors.html +0 -281
- data/rdoc/site/0.2.1/Nucleon/Errors/BatchError.html +0 -287
- data/rdoc/site/0.2.1/Nucleon/Errors/NucleonError.html +0 -663
- data/rdoc/site/0.2.1/Nucleon/Errors/SSHUnavailable.html +0 -287
- data/rdoc/site/0.2.1/Nucleon/Event.html +0 -281
- data/rdoc/site/0.2.1/Nucleon/Event/Regex.html +0 -473
- data/rdoc/site/0.2.1/Nucleon/Facade.html +0 -2452
- data/rdoc/site/0.2.1/Nucleon/Gems.html +0 -641
- data/rdoc/site/0.2.1/Nucleon/Manager.html +0 -1862
- data/rdoc/site/0.2.1/Nucleon/Mixin.html +0 -291
- data/rdoc/site/0.2.1/Nucleon/Mixin/Action.html +0 -284
- data/rdoc/site/0.2.1/Nucleon/Mixin/Action/Commit.html +0 -387
- data/rdoc/site/0.2.1/Nucleon/Mixin/Action/Project.html +0 -401
- data/rdoc/site/0.2.1/Nucleon/Mixin/Action/Push.html +0 -377
- data/rdoc/site/0.2.1/Nucleon/Mixin/Action/Registration.html +0 -575
- data/rdoc/site/0.2.1/Nucleon/Mixin/Colors.html +0 -551
- data/rdoc/site/0.2.1/Nucleon/Mixin/ConfigCollection.html +0 -487
- data/rdoc/site/0.2.1/Nucleon/Mixin/ConfigOptions.html +0 -455
- data/rdoc/site/0.2.1/Nucleon/Mixin/Macro.html +0 -282
- data/rdoc/site/0.2.1/Nucleon/Mixin/Macro/ObjectInterface.html +0 -701
- data/rdoc/site/0.2.1/Nucleon/Mixin/Macro/PluginInterface.html +0 -688
- data/rdoc/site/0.2.1/Nucleon/Mixin/Settings.html +0 -487
- data/rdoc/site/0.2.1/Nucleon/Mixin/SubConfig.html +0 -893
- data/rdoc/site/0.2.1/Nucleon/Parallel.html +0 -332
- data/rdoc/site/0.2.1/Nucleon/Parallel/ClassMethods.html +0 -331
- data/rdoc/site/0.2.1/Nucleon/Parallel/InstanceMethods.html +0 -458
- data/rdoc/site/0.2.1/Nucleon/Plugin.html +0 -288
- data/rdoc/site/0.2.1/Nucleon/Plugin/Action.html +0 -2133
- data/rdoc/site/0.2.1/Nucleon/Plugin/Action/Option.html +0 -465
- data/rdoc/site/0.2.1/Nucleon/Plugin/Base.html +0 -1988
- data/rdoc/site/0.2.1/Nucleon/Plugin/Command.html +0 -765
- data/rdoc/site/0.2.1/Nucleon/Plugin/Event.html +0 -448
- data/rdoc/site/0.2.1/Nucleon/Plugin/Extension.html +0 -287
- data/rdoc/site/0.2.1/Nucleon/Plugin/Project.html +0 -2900
- data/rdoc/site/0.2.1/Nucleon/Plugin/Template.html +0 -482
- data/rdoc/site/0.2.1/Nucleon/Plugin/Translator.html +0 -377
- data/rdoc/site/0.2.1/Nucleon/Project.html +0 -282
- data/rdoc/site/0.2.1/Nucleon/Project/Git.html +0 -1807
- data/rdoc/site/0.2.1/Nucleon/Project/Github.html +0 -555
- data/rdoc/site/0.2.1/Nucleon/Template.html +0 -283
- data/rdoc/site/0.2.1/Nucleon/Template/JSON.html +0 -335
- data/rdoc/site/0.2.1/Nucleon/Template/Wrapper.html +0 -335
- data/rdoc/site/0.2.1/Nucleon/Template/YAML.html +0 -335
- data/rdoc/site/0.2.1/Nucleon/Translator.html +0 -282
- data/rdoc/site/0.2.1/Nucleon/Translator/JSON.html +0 -372
- data/rdoc/site/0.2.1/Nucleon/Translator/YAML.html +0 -372
- data/rdoc/site/0.2.1/Nucleon/Util.html +0 -291
- data/rdoc/site/0.2.1/Nucleon/Util/CLI.html +0 -394
- data/rdoc/site/0.2.1/Nucleon/Util/CLI/Parser.html +0 -1404
- data/rdoc/site/0.2.1/Nucleon/Util/Cache.html +0 -824
- data/rdoc/site/0.2.1/Nucleon/Util/Console.html +0 -1330
- data/rdoc/site/0.2.1/Nucleon/Util/Data.html +0 -1423
- data/rdoc/site/0.2.1/Nucleon/Util/Disk.html +0 -528
- data/rdoc/site/0.2.1/Nucleon/Util/Git.html +0 -367
- data/rdoc/site/0.2.1/Nucleon/Util/Liquid.html +0 -371
- data/rdoc/site/0.2.1/Nucleon/Util/Logger.html +0 -822
- data/rdoc/site/0.2.1/Nucleon/Util/Package.html +0 -564
- data/rdoc/site/0.2.1/Nucleon/Util/SSH.html +0 -1036
- data/rdoc/site/0.2.1/Nucleon/Util/SSH/Keypair.html +0 -607
- data/rdoc/site/0.2.1/Nucleon/Util/Shell.html +0 -697
- data/rdoc/site/0.2.1/Nucleon/Util/Shell/Result.html +0 -503
- data/rdoc/site/0.2.1/README_rdoc.html +0 -318
- data/rdoc/site/0.2.1/TODO_rdoc.html +0 -267
- data/rdoc/site/0.2.1/created.rid +0 -62
- data/rdoc/site/0.2.1/images/add.png +0 -0
- data/rdoc/site/0.2.1/images/brick.png +0 -0
- data/rdoc/site/0.2.1/images/brick_link.png +0 -0
- data/rdoc/site/0.2.1/images/bug.png +0 -0
- data/rdoc/site/0.2.1/images/bullet_black.png +0 -0
- data/rdoc/site/0.2.1/images/bullet_toggle_minus.png +0 -0
- data/rdoc/site/0.2.1/images/bullet_toggle_plus.png +0 -0
- data/rdoc/site/0.2.1/images/date.png +0 -0
- data/rdoc/site/0.2.1/images/delete.png +0 -0
- data/rdoc/site/0.2.1/images/find.png +0 -0
- data/rdoc/site/0.2.1/images/loadingAnimation.gif +0 -0
- data/rdoc/site/0.2.1/images/macFFBgHack.png +0 -0
- data/rdoc/site/0.2.1/images/package.png +0 -0
- data/rdoc/site/0.2.1/images/page_green.png +0 -0
- data/rdoc/site/0.2.1/images/page_white_text.png +0 -0
- data/rdoc/site/0.2.1/images/page_white_width.png +0 -0
- data/rdoc/site/0.2.1/images/plugin.png +0 -0
- data/rdoc/site/0.2.1/images/ruby.png +0 -0
- data/rdoc/site/0.2.1/images/tag_blue.png +0 -0
- data/rdoc/site/0.2.1/images/tag_green.png +0 -0
- data/rdoc/site/0.2.1/images/transparent.png +0 -0
- data/rdoc/site/0.2.1/images/wrench.png +0 -0
- data/rdoc/site/0.2.1/images/wrench_orange.png +0 -0
- data/rdoc/site/0.2.1/images/zoom.png +0 -0
- data/rdoc/site/0.2.1/index.html +0 -317
- data/rdoc/site/0.2.1/js/darkfish.js +0 -155
- data/rdoc/site/0.2.1/js/jquery.js +0 -18
- data/rdoc/site/0.2.1/js/navigation.js +0 -142
- data/rdoc/site/0.2.1/js/search.js +0 -94
- data/rdoc/site/0.2.1/js/search_index.js +0 -1
- data/rdoc/site/0.2.1/js/searcher.js +0 -228
- data/rdoc/site/0.2.1/rdoc.css +0 -543
- data/rdoc/site/0.2.1/table_of_contents.html +0 -1718
- data/spec/coral_mock_input.rb +0 -29
- data/spec/coral_test_kernel.rb +0 -22
data/lib/core/util/data.rb
CHANGED
|
@@ -1,77 +1,193 @@
|
|
|
1
1
|
|
|
2
2
|
module Nucleon
|
|
3
3
|
module Util
|
|
4
|
+
#
|
|
5
|
+
# == Data utilities
|
|
6
|
+
#
|
|
7
|
+
# The Nucleon::Util::Data class defines various tools for working with data in
|
|
8
|
+
# the Nucleon system.
|
|
9
|
+
#
|
|
10
|
+
# It implements:
|
|
11
|
+
# 1. Type checkers
|
|
12
|
+
# 2. Basic data translators
|
|
13
|
+
# 3. Data transformations
|
|
14
|
+
# 4. Other utilities
|
|
15
|
+
#
|
|
4
16
|
class Data
|
|
5
|
-
|
|
6
|
-
|
|
17
|
+
|
|
18
|
+
#*****************************************************************************
|
|
7
19
|
# Type checking
|
|
8
|
-
|
|
20
|
+
|
|
21
|
+
# Check if given value is undefined.
|
|
22
|
+
#
|
|
23
|
+
# It currently checks for: (our definition of undefined)
|
|
24
|
+
# * *nil*
|
|
25
|
+
# * Symbols: *:undef*, *:undefined*
|
|
26
|
+
# * Strings: "*undef*", "*UNDEF*", "*Undef*", "*nil*", "*NIL*", "*Nil*"
|
|
27
|
+
#
|
|
28
|
+
# This method was created to provide an easy way for us to load and work with
|
|
29
|
+
# configurations from text formats, such as JSON.
|
|
30
|
+
#
|
|
31
|
+
# * *Parameters*
|
|
32
|
+
# - [ANY] *value* Value to check if undefined
|
|
33
|
+
#
|
|
34
|
+
# * *Returns*
|
|
35
|
+
# - [Boolean] Returns true if value is undefined, false otherwise
|
|
36
|
+
#
|
|
37
|
+
# * *Errors*
|
|
38
|
+
#
|
|
9
39
|
def self.undef?(value)
|
|
10
|
-
if value.nil? ||
|
|
11
|
-
(value.is_a?(Symbol) && value == :undef || value == :undefined) ||
|
|
40
|
+
if value.nil? ||
|
|
41
|
+
(value.is_a?(Symbol) && value == :undef || value == :undefined) ||
|
|
12
42
|
(value.is_a?(String) && value.match(/^\s*(undef|UNDEF|Undef|nil|NIL|Nil)\s*$/))
|
|
13
43
|
return true
|
|
14
44
|
end
|
|
15
|
-
return false
|
|
45
|
+
return false
|
|
16
46
|
end
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
|
|
48
|
+
# Check if given value is true.
|
|
49
|
+
#
|
|
50
|
+
# It currently checks for: (our definition of true)
|
|
51
|
+
# * *true*
|
|
52
|
+
# * Symbols: *:true*
|
|
53
|
+
# * Strings: "*true*", "*TRUE*", "*True*"
|
|
54
|
+
#
|
|
55
|
+
# This method was created to provide an easy way for us to load and work with
|
|
56
|
+
# configurations from text formats, such as JSON.
|
|
57
|
+
#
|
|
58
|
+
# * *Parameters*
|
|
59
|
+
# - [ANY] *value* Value to check if true
|
|
60
|
+
#
|
|
61
|
+
# * *Returns*
|
|
62
|
+
# - [Boolean] Returns true if value is true, false otherwise
|
|
63
|
+
#
|
|
64
|
+
# * *Errors*
|
|
65
|
+
#
|
|
20
66
|
def self.true?(value)
|
|
21
|
-
if value == true ||
|
|
67
|
+
if value == true ||
|
|
68
|
+
(value.is_a?(Symbol) && value == :true) ||
|
|
22
69
|
(value.is_a?(String) && value.match(/^\s*(true|TRUE|True)\s*$/))
|
|
23
70
|
return true
|
|
24
71
|
end
|
|
25
|
-
return false
|
|
72
|
+
return false
|
|
26
73
|
end
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
74
|
+
|
|
75
|
+
# Check if given value is false.
|
|
76
|
+
#
|
|
77
|
+
# It currently checks for: (our definition of false)
|
|
78
|
+
# * *false*
|
|
79
|
+
# * Symbols: *:false*
|
|
80
|
+
# * Strings: "*false*", "*FALSE*", "*False*"
|
|
81
|
+
#
|
|
82
|
+
# This method was created to provide an easy way for us to load and work with
|
|
83
|
+
# configurations from text formats, such as JSON.
|
|
84
|
+
#
|
|
85
|
+
# * *Parameters*
|
|
86
|
+
# - [ANY] *value* Value to check if false
|
|
87
|
+
#
|
|
88
|
+
# * *Returns*
|
|
89
|
+
# - [Boolean] Returns true if value is false, false otherwise
|
|
90
|
+
#
|
|
91
|
+
# * *Errors*
|
|
92
|
+
#
|
|
30
93
|
def self.false?(value)
|
|
31
|
-
if value == false ||
|
|
94
|
+
if value == false ||
|
|
95
|
+
(value.is_a?(Symbol) && value == :false) ||
|
|
32
96
|
(value.is_a?(String) && value.match(/^\s*(false|FALSE|False)\s*$/))
|
|
33
97
|
return true
|
|
34
98
|
end
|
|
35
|
-
return false
|
|
99
|
+
return false
|
|
36
100
|
end
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
101
|
+
|
|
102
|
+
# Check if given value is empty.
|
|
103
|
+
#
|
|
104
|
+
# It currently checks for: (our definition of empty)
|
|
105
|
+
# * ::undef?
|
|
106
|
+
# * ::false?
|
|
107
|
+
# * value.empty?
|
|
108
|
+
#
|
|
109
|
+
# This method was created to provide an easy way for us to load and work with
|
|
110
|
+
# configurations from text formats, such as JSON.
|
|
111
|
+
#
|
|
112
|
+
# * *Parameters*
|
|
113
|
+
# - [ANY] *value* Value to check if empty
|
|
114
|
+
#
|
|
115
|
+
# * *Returns*
|
|
116
|
+
# - [Boolean] Returns true if value is empty, false otherwise
|
|
117
|
+
#
|
|
118
|
+
# * *Errors*
|
|
119
|
+
#
|
|
40
120
|
def self.empty?(value)
|
|
41
121
|
if undef?(value) || false?(value) || (value.respond_to?('empty?') && value.empty?)
|
|
42
122
|
return true
|
|
43
123
|
end
|
|
44
124
|
return false
|
|
45
125
|
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
126
|
+
|
|
127
|
+
# Check if given keys exist in data hash.
|
|
128
|
+
#
|
|
129
|
+
# This method allows for the easy checking of nested keys. It takes care of
|
|
130
|
+
# traversing the data structure and checking for empty recursively.
|
|
131
|
+
#
|
|
132
|
+
# * *Parameters*
|
|
133
|
+
# - [Hash<String, Symbol|...|ANY>] *data* Data object to check
|
|
134
|
+
# - [Array<String, Symbol>] *keys* Hash key path (nested keys)
|
|
135
|
+
# - [Boolean] *check_empty* Whether to check element for emptiness
|
|
136
|
+
#
|
|
137
|
+
# * *Returns*
|
|
138
|
+
# - [Boolean] Returns true if keys exist and not empty, false otherwise if check_empty
|
|
139
|
+
# - [Boolean] Returns true if keys exist, false otherwise
|
|
140
|
+
#
|
|
141
|
+
# * *Errors*
|
|
142
|
+
#
|
|
143
|
+
# See:
|
|
144
|
+
# - ::empty?
|
|
145
|
+
#
|
|
49
146
|
def self.exists?(data, keys, check_empty = false)
|
|
50
147
|
if keys.is_a?(String) || keys.is_a?(Symbol)
|
|
51
148
|
keys = [ keys ]
|
|
52
|
-
end
|
|
149
|
+
end
|
|
53
150
|
key = keys.shift.to_sym
|
|
54
|
-
|
|
151
|
+
|
|
55
152
|
if data.has_key?(key)
|
|
56
153
|
value = data[key]
|
|
57
|
-
|
|
154
|
+
|
|
58
155
|
if keys.empty?
|
|
59
156
|
return false if check_empty && empty?(value)
|
|
60
157
|
return true
|
|
61
158
|
else
|
|
62
|
-
return exists?(data[key], keys)
|
|
159
|
+
return exists?(data[key], keys)
|
|
63
160
|
end
|
|
64
161
|
end
|
|
65
162
|
return false
|
|
66
163
|
end
|
|
67
|
-
|
|
68
|
-
|
|
164
|
+
|
|
165
|
+
#*****************************************************************************
|
|
69
166
|
# Translation
|
|
70
167
|
|
|
168
|
+
# Return hash as a symbol map.
|
|
169
|
+
#
|
|
170
|
+
# This method converts all hash keys to symbols. Nested hashes are
|
|
171
|
+
# recursively translated as well.
|
|
172
|
+
#
|
|
173
|
+
# This comes in really handy when performing operations across hashes in Ruby
|
|
174
|
+
# because of the distinction between symbols and strings.
|
|
175
|
+
#
|
|
176
|
+
# * *Parameters*
|
|
177
|
+
# - [Hash<String, Symbol|...|ANY>] *data* Hash data to symbolize keys
|
|
178
|
+
#
|
|
179
|
+
# * *Returns*
|
|
180
|
+
# - [Hash<Symbol|...|ANY>] Returns data structure symbolized
|
|
181
|
+
#
|
|
182
|
+
# * *Errors*
|
|
183
|
+
#
|
|
184
|
+
# See also:
|
|
185
|
+
# - ::string_map
|
|
186
|
+
#
|
|
71
187
|
def self.symbol_map(data)
|
|
72
188
|
results = {}
|
|
73
189
|
return data unless data
|
|
74
|
-
|
|
190
|
+
|
|
75
191
|
case data
|
|
76
192
|
when Hash
|
|
77
193
|
data.each do |key, value|
|
|
@@ -79,16 +195,33 @@ class Data
|
|
|
79
195
|
end
|
|
80
196
|
else
|
|
81
197
|
results = data
|
|
82
|
-
end
|
|
198
|
+
end
|
|
83
199
|
return results
|
|
84
200
|
end
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
201
|
+
|
|
202
|
+
# Return hash as a string map.
|
|
203
|
+
#
|
|
204
|
+
# This method converts all hash keys to strings. Nested hashes are
|
|
205
|
+
# recursively translated as well.
|
|
206
|
+
#
|
|
207
|
+
# This comes in really handy when performing operations across hashes in Ruby
|
|
208
|
+
# because of the distinction between symbols and strings.
|
|
209
|
+
#
|
|
210
|
+
# * *Parameters*
|
|
211
|
+
# - [Hash<String, Symbol|...|ANY>] *data* Hash data to stringify keys
|
|
212
|
+
#
|
|
213
|
+
# * *Returns*
|
|
214
|
+
# - [Hash<String|...|ANY>] Returns data structure grouped by string keys
|
|
215
|
+
#
|
|
216
|
+
# * *Errors*
|
|
217
|
+
#
|
|
218
|
+
# See also:
|
|
219
|
+
# - ::symbol_map
|
|
220
|
+
#
|
|
88
221
|
def self.string_map(data)
|
|
89
222
|
results = {}
|
|
90
223
|
return data unless data
|
|
91
|
-
|
|
224
|
+
|
|
92
225
|
case data
|
|
93
226
|
when Hash
|
|
94
227
|
data.each do |key, value|
|
|
@@ -96,36 +229,111 @@ class Data
|
|
|
96
229
|
end
|
|
97
230
|
else
|
|
98
231
|
results = data
|
|
99
|
-
end
|
|
232
|
+
end
|
|
100
233
|
return results
|
|
101
234
|
end
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
235
|
+
|
|
236
|
+
# Parse a JSON string into a Ruby data object.
|
|
237
|
+
#
|
|
238
|
+
# This method uses the MultiJson gem to carry out the heavy lifting. We just
|
|
239
|
+
# sit back and enjoy the ride.
|
|
240
|
+
#
|
|
241
|
+
# * *Parameters*
|
|
242
|
+
# - [String] *json_text* JSON text string to parse into Ruby data
|
|
243
|
+
#
|
|
244
|
+
# * *Returns*
|
|
245
|
+
# - [nil, true, false, String, Array, Hash<String|...|ANY>] Returns parsed data object
|
|
246
|
+
#
|
|
247
|
+
# * *Errors*
|
|
248
|
+
#
|
|
249
|
+
# See also:
|
|
250
|
+
# - ::to_json
|
|
251
|
+
#
|
|
105
252
|
def self.parse_json(json_text)
|
|
106
253
|
return MultiJson.load(json_text)
|
|
107
254
|
end
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
255
|
+
|
|
256
|
+
# Dump a Ruby object to a JSON string.
|
|
257
|
+
#
|
|
258
|
+
# This method uses the MultiJson gem to carry out the heavy lifting. We just
|
|
259
|
+
# sit back and enjoy the ride.
|
|
260
|
+
#
|
|
261
|
+
# * *Parameters*
|
|
262
|
+
# - [ANY] *data* Ruby data to render JSON string
|
|
263
|
+
#
|
|
264
|
+
# * *Returns*
|
|
265
|
+
# - [String] Returns JSON rendered data object
|
|
266
|
+
#
|
|
267
|
+
# * *Errors*
|
|
268
|
+
#
|
|
269
|
+
# See also:
|
|
270
|
+
# - ::parse_json
|
|
271
|
+
#
|
|
111
272
|
def self.to_json(data, pretty = true)
|
|
112
273
|
return MultiJson.dump(data, :pretty => pretty)
|
|
113
274
|
end
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
275
|
+
|
|
276
|
+
# Parse a YAML string into a Ruby data object.
|
|
277
|
+
#
|
|
278
|
+
# This method uses the Ruby YAML module to carry out the heavy lifting. We
|
|
279
|
+
# just sit back and enjoy the ride.
|
|
280
|
+
#
|
|
281
|
+
# * *Parameters*
|
|
282
|
+
# - [String] *yaml_text* YAML text string to parse into Ruby data
|
|
283
|
+
#
|
|
284
|
+
# * *Returns*
|
|
285
|
+
# - [nil, true, false, String, Array, Hash<String|...|ANY>] Returns parsed data object
|
|
286
|
+
#
|
|
287
|
+
# * *Errors*
|
|
288
|
+
#
|
|
289
|
+
# See also:
|
|
290
|
+
# - ::to_yaml
|
|
291
|
+
#
|
|
117
292
|
def self.parse_yaml(yaml_text)
|
|
118
293
|
return YAML.load(yaml_text)
|
|
119
294
|
end
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
295
|
+
|
|
296
|
+
# Dump a Ruby object to a YAML string.
|
|
297
|
+
#
|
|
298
|
+
# This method uses the Ruby YAML module to carry out the heavy lifting. We
|
|
299
|
+
# just sit back and enjoy the ride.
|
|
300
|
+
#
|
|
301
|
+
# * *Parameters*
|
|
302
|
+
# - [ANY] *data* Ruby data to render YAML string
|
|
303
|
+
#
|
|
304
|
+
# * *Returns*
|
|
305
|
+
# - [String] Returns YAML rendered data object
|
|
306
|
+
#
|
|
307
|
+
# * *Errors*
|
|
308
|
+
#
|
|
309
|
+
# See also:
|
|
310
|
+
# - ::parse_yaml
|
|
311
|
+
#
|
|
123
312
|
def self.to_yaml(data)
|
|
124
313
|
return YAML.dump(data)
|
|
125
314
|
end
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
315
|
+
|
|
316
|
+
# Translate a value to internally standardized form.
|
|
317
|
+
#
|
|
318
|
+
# It currently translates:
|
|
319
|
+
# * ::undef? to *undefined_value*
|
|
320
|
+
# * ::true? to *true*
|
|
321
|
+
# * ::false? to *false*
|
|
322
|
+
# * Array (recursively)
|
|
323
|
+
# * Hash (recursively)
|
|
324
|
+
#
|
|
325
|
+
# This method was created to provide an easy way for us to load and work with
|
|
326
|
+
# configurations from text formats, such as JSON.
|
|
327
|
+
#
|
|
328
|
+
# * *Parameters*
|
|
329
|
+
# - [ANY] *value* Value to internalize
|
|
330
|
+
# - [ANY] *undefined_value* Value that represents undefined (*nil*)
|
|
331
|
+
#
|
|
332
|
+
# * *Returns*
|
|
333
|
+
# - [ANY] Returns internalized value object
|
|
334
|
+
#
|
|
335
|
+
# * *Errors*
|
|
336
|
+
#
|
|
129
337
|
def self.value(value, undefined_value = nil)
|
|
130
338
|
case value
|
|
131
339
|
when String
|
|
@@ -136,34 +344,89 @@ class Data
|
|
|
136
344
|
elsif false?(value)
|
|
137
345
|
value = false
|
|
138
346
|
end
|
|
139
|
-
|
|
347
|
+
|
|
140
348
|
when Array
|
|
141
349
|
value.each_with_index do |item, index|
|
|
142
350
|
value[index] = value(item, undefined_value)
|
|
143
351
|
end
|
|
144
|
-
|
|
352
|
+
|
|
145
353
|
when Hash
|
|
146
354
|
value.each do |key, data|
|
|
147
355
|
value[key] = value(data, undefined_value)
|
|
148
356
|
end
|
|
149
357
|
end
|
|
150
|
-
return value
|
|
358
|
+
return value
|
|
151
359
|
end
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
360
|
+
|
|
361
|
+
# Run a defined filter on a data object.
|
|
362
|
+
#
|
|
363
|
+
# This method ensures that a given data object meets some criteria or else
|
|
364
|
+
# an empty value for that type is returned that matches the criteria.
|
|
365
|
+
#
|
|
366
|
+
# Currently implemented filters:
|
|
367
|
+
# 1. ::array Ensure result is an array (non arrays are converted)
|
|
368
|
+
# 2. ::hash Ensure result is a hash (non hashes are converted)
|
|
369
|
+
# 3. ::string Ensure result is a string (non strings are converted)
|
|
370
|
+
# 4. ::symbol Ensure result is a symbol (non symbols are converted)
|
|
371
|
+
# 5. ::test Ensure result is not empty (runs a boolean ::empty? check)
|
|
372
|
+
#
|
|
373
|
+
# More filters can be added by adding methods to the Nucleon::Util::Data class.
|
|
374
|
+
#
|
|
375
|
+
# For example:
|
|
376
|
+
#
|
|
377
|
+
# module Nucleon::Util::Data
|
|
378
|
+
# def my_filter(data, default = '')
|
|
379
|
+
# # Return data modified or default
|
|
380
|
+
# end
|
|
381
|
+
# end
|
|
382
|
+
#
|
|
383
|
+
# my_data = Nucleon::Util::Data.filter(my_data, :my_filter)
|
|
384
|
+
#
|
|
385
|
+
# * *Parameters*
|
|
386
|
+
# - [ANY] *data* Ruby data object to run through filter
|
|
387
|
+
# - [false, String] *method* Filter method to execute or false for none
|
|
388
|
+
#
|
|
389
|
+
# * *Returns*
|
|
390
|
+
# - [ANY] Returns filtered data object
|
|
391
|
+
#
|
|
392
|
+
# * *Errors*
|
|
393
|
+
#
|
|
155
394
|
def self.filter(data, method = false)
|
|
156
|
-
if method && method.
|
|
157
|
-
|
|
158
|
-
return send(method, data)
|
|
395
|
+
if method && respond_to?(method.to_sym)
|
|
396
|
+
return send(method.to_sym, data)
|
|
159
397
|
end
|
|
160
398
|
return data
|
|
161
399
|
end
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
400
|
+
|
|
401
|
+
# Ensure a data object is an array.
|
|
402
|
+
#
|
|
403
|
+
# It converts:
|
|
404
|
+
# 1. Symbols to arrays
|
|
405
|
+
# 2. Strings to arrays
|
|
406
|
+
# 3. Splits strings on commas (if *split_string* requested)
|
|
407
|
+
# 4. If no array found, returns *default*
|
|
408
|
+
#
|
|
409
|
+
# TODO: Parameter for string separator split
|
|
410
|
+
#
|
|
411
|
+
# * *Parameters*
|
|
412
|
+
# - [ANY] *data* Ruby data to ensure array
|
|
413
|
+
# - [Array] *default* Default value if no array is found
|
|
414
|
+
# - [Boolean] *split_string* Whether to split strings on comma
|
|
415
|
+
#
|
|
416
|
+
# * *Returns*
|
|
417
|
+
# - [Array] Returns an array
|
|
418
|
+
#
|
|
419
|
+
# * *Errors*
|
|
420
|
+
#
|
|
421
|
+
# See also:
|
|
422
|
+
# - ::filter (switch)
|
|
423
|
+
# - ::hash
|
|
424
|
+
# - ::string
|
|
425
|
+
# - ::symbol
|
|
426
|
+
# - ::test
|
|
427
|
+
#
|
|
165
428
|
def self.array(data, default = [], split_string = false)
|
|
166
|
-
result = default
|
|
429
|
+
result = default
|
|
167
430
|
if data
|
|
168
431
|
case data
|
|
169
432
|
when Array
|
|
@@ -176,11 +439,30 @@ class Data
|
|
|
176
439
|
end
|
|
177
440
|
return result
|
|
178
441
|
end
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
442
|
+
|
|
443
|
+
# Ensure a data object is a hash.
|
|
444
|
+
#
|
|
445
|
+
# If data is given and it is not a hash, an empty hash is returned in it's
|
|
446
|
+
# place.
|
|
447
|
+
#
|
|
448
|
+
# * *Parameters*
|
|
449
|
+
# - [ANY] *data* Ruby data to ensure hash
|
|
450
|
+
# - [Hash] *default* Default value if no data is given (nil)
|
|
451
|
+
#
|
|
452
|
+
# * *Returns*
|
|
453
|
+
# - [Hash] Returns a hash
|
|
454
|
+
#
|
|
455
|
+
# * *Errors*
|
|
456
|
+
#
|
|
457
|
+
# See also:
|
|
458
|
+
# - ::filter (switch)
|
|
459
|
+
# - ::array
|
|
460
|
+
# - ::string
|
|
461
|
+
# - ::symbol
|
|
462
|
+
# - ::test
|
|
463
|
+
#
|
|
182
464
|
def self.hash(data, default = {})
|
|
183
|
-
result = default
|
|
465
|
+
result = default
|
|
184
466
|
if data
|
|
185
467
|
case data
|
|
186
468
|
when Hash
|
|
@@ -191,11 +473,30 @@ class Data
|
|
|
191
473
|
end
|
|
192
474
|
return result
|
|
193
475
|
end
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
476
|
+
|
|
477
|
+
# Ensure a data object is a string.
|
|
478
|
+
#
|
|
479
|
+
# If data is given and it is not a string, the data.to_s method is called to
|
|
480
|
+
# get the rendered string.
|
|
481
|
+
#
|
|
482
|
+
# * *Parameters*
|
|
483
|
+
# - [ANY] *data* Ruby data to ensure string
|
|
484
|
+
# - [String] *default* Default value if no data is given (nil)
|
|
485
|
+
#
|
|
486
|
+
# * *Returns*
|
|
487
|
+
# - [String] Returns a string
|
|
488
|
+
#
|
|
489
|
+
# * *Errors*
|
|
490
|
+
#
|
|
491
|
+
# See also:
|
|
492
|
+
# - ::filter (switch)
|
|
493
|
+
# - ::array
|
|
494
|
+
# - ::hash
|
|
495
|
+
# - ::symbol
|
|
496
|
+
# - ::test
|
|
497
|
+
#
|
|
197
498
|
def self.string(data, default = '')
|
|
198
|
-
result = default
|
|
499
|
+
result = default
|
|
199
500
|
if data
|
|
200
501
|
case data
|
|
201
502
|
when String
|
|
@@ -206,13 +507,35 @@ class Data
|
|
|
206
507
|
end
|
|
207
508
|
return result
|
|
208
509
|
end
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
510
|
+
|
|
511
|
+
# Ensure a data object is a symbol.
|
|
512
|
+
#
|
|
513
|
+
# If data is given and it is not a symbol, the data.to_sym method is called to
|
|
514
|
+
# get the generated symbol. If data is not a string or symbol, it's class name
|
|
515
|
+
# is symbolized.
|
|
516
|
+
#
|
|
517
|
+
# * *Parameters*
|
|
518
|
+
# - [ANY] *data* Ruby data to ensure symbol
|
|
519
|
+
# - [Symbol] *default* Default value if no data is given (:undefined)
|
|
520
|
+
#
|
|
521
|
+
# * *Returns*
|
|
522
|
+
# - [Symbol] Returns a symbol
|
|
523
|
+
#
|
|
524
|
+
# * *Errors*
|
|
525
|
+
#
|
|
526
|
+
# See also:
|
|
527
|
+
# - ::filter (switch)
|
|
528
|
+
# - ::array
|
|
529
|
+
# - ::hash
|
|
530
|
+
# - ::string
|
|
531
|
+
# - ::test
|
|
532
|
+
#
|
|
212
533
|
def self.symbol(data, default = :undefined)
|
|
213
|
-
result = default
|
|
534
|
+
result = default
|
|
214
535
|
if data
|
|
215
536
|
case data
|
|
537
|
+
when TrueClass, FalseClass
|
|
538
|
+
result = data ? :true : :false
|
|
216
539
|
when Symbol
|
|
217
540
|
result = data
|
|
218
541
|
when String
|
|
@@ -223,17 +546,48 @@ class Data
|
|
|
223
546
|
end
|
|
224
547
|
return result
|
|
225
548
|
end
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
549
|
+
|
|
550
|
+
# Test a data object for emptiness and return boolean result.
|
|
551
|
+
#
|
|
552
|
+
# Uses the ::empty? method to check for emptiness.
|
|
553
|
+
#
|
|
554
|
+
# * *Parameters*
|
|
555
|
+
# - [ANY] *data* Ruby data to test for emptiness
|
|
556
|
+
#
|
|
557
|
+
# * *Returns*
|
|
558
|
+
# - [Boolean] Returns true if data not empty, false otherwise
|
|
559
|
+
#
|
|
560
|
+
# * *Errors*
|
|
561
|
+
#
|
|
562
|
+
# See also:
|
|
563
|
+
# - ::filter (switch)
|
|
564
|
+
# - ::array
|
|
565
|
+
# - ::hash
|
|
566
|
+
# - ::string
|
|
567
|
+
# - ::symbol
|
|
568
|
+
#
|
|
229
569
|
def self.test(data)
|
|
230
570
|
return false if Util::Data.empty?(data)
|
|
231
571
|
return true
|
|
232
572
|
end
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
#
|
|
236
|
-
|
|
573
|
+
|
|
574
|
+
#*****************************************************************************
|
|
575
|
+
# Transformation
|
|
576
|
+
|
|
577
|
+
# Clean nil or empty values out of a hash object.
|
|
578
|
+
#
|
|
579
|
+
# * *Parameters*
|
|
580
|
+
# - [Hash] *data* Ruby data to clean properties
|
|
581
|
+
# - [Boolean] *remove_empty* Whether or not to remove empty values or just nil
|
|
582
|
+
#
|
|
583
|
+
# * *Returns*
|
|
584
|
+
# - [Hash] Returns hash with all nil or empty values scrubbed (depending on *remove_empty*)
|
|
585
|
+
#
|
|
586
|
+
# * *Errors*
|
|
587
|
+
#
|
|
588
|
+
# See also:
|
|
589
|
+
# - ::deep_clean (recursive clean)
|
|
590
|
+
#
|
|
237
591
|
def self.clean(data, remove_empty = true)
|
|
238
592
|
data.keys.each do |key|
|
|
239
593
|
obj = data[key]
|
|
@@ -241,178 +595,327 @@ class Data
|
|
|
241
595
|
end
|
|
242
596
|
data
|
|
243
597
|
end
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
598
|
+
|
|
599
|
+
# Recursively clean nil or empty values out of a hash object.
|
|
600
|
+
#
|
|
601
|
+
# * *Parameters*
|
|
602
|
+
# - [Hash] *data* Ruby data to clean properties
|
|
603
|
+
# - [Boolean] *remove_empty* Whether or not to remove empty values or just nil
|
|
604
|
+
#
|
|
605
|
+
# * *Returns*
|
|
606
|
+
# - [Hash] Returns hash with all nil or empty values scrubbed (depending on *remove_empty*)
|
|
607
|
+
#
|
|
608
|
+
# * *Errors*
|
|
609
|
+
#
|
|
610
|
+
# See also:
|
|
611
|
+
# - ::clean (shallow clean)
|
|
612
|
+
#
|
|
247
613
|
def self.deep_clean(data, remove_empty = true)
|
|
248
614
|
data.keys.each do |key|
|
|
249
615
|
obj = data[key]
|
|
250
|
-
|
|
616
|
+
|
|
251
617
|
if obj.nil? || ( remove_empty && obj.is_a?(Hash) && obj.empty? )
|
|
252
618
|
data.delete(key)
|
|
253
|
-
|
|
619
|
+
|
|
254
620
|
elsif data[key].is_a?(Hash)
|
|
255
621
|
deep_clean(data[key], remove_empty)
|
|
256
622
|
end
|
|
257
623
|
end
|
|
258
624
|
data
|
|
259
625
|
end
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
626
|
+
|
|
627
|
+
# Recursively clone an array or tree based hash object.
|
|
628
|
+
#
|
|
629
|
+
# * *Parameters*
|
|
630
|
+
# - [Hash, Array] *data* Ruby data to recursively clone
|
|
631
|
+
#
|
|
632
|
+
# * *Returns*
|
|
633
|
+
# - [Hash] Returns completely new nested hash if hash data given
|
|
634
|
+
# - [Array] Returns completely new array if array data given
|
|
635
|
+
#
|
|
636
|
+
# * *Errors*
|
|
637
|
+
#
|
|
638
|
+
#
|
|
639
|
+
def self.clone(data)
|
|
640
|
+
if data.is_a?(Array)
|
|
641
|
+
new_data = []
|
|
642
|
+
data.each do |item|
|
|
643
|
+
new_data << clone(item)
|
|
644
|
+
end
|
|
645
|
+
elsif data.is_a?(Hash)
|
|
646
|
+
new_data = {}
|
|
647
|
+
data.each do |key, value|
|
|
648
|
+
new_data[key] = clone(value)
|
|
649
|
+
end
|
|
650
|
+
else
|
|
651
|
+
new_data = data
|
|
652
|
+
end
|
|
653
|
+
new_data
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
# Merge data objects together.
|
|
657
|
+
#
|
|
658
|
+
# This method relies on the merging capabilities of the deep_merge gem. It
|
|
659
|
+
# switches between core Ruby shallow merge and deep_merge merges based on
|
|
660
|
+
# the *basic* boolean.
|
|
661
|
+
#
|
|
662
|
+
# Elements at the end of the array override values for data at the beginning.
|
|
663
|
+
#
|
|
664
|
+
# * *Parameters*
|
|
665
|
+
# - [Array<nil, String, Symbol, Array, Hash>] *data* Ruby data objects to merge
|
|
666
|
+
# - [Boolean] *force* Whether or not to force override of values where types don't match
|
|
667
|
+
# - [Boolean] *basic* Whether or not to perform a basic merge or deep (recursive) merge
|
|
668
|
+
#
|
|
669
|
+
# * *Returns*
|
|
670
|
+
# - [nil, String, Symbol, Array, Hash] Returns merged data object
|
|
671
|
+
#
|
|
672
|
+
# * *Errors*
|
|
673
|
+
#
|
|
674
|
+
# See also:
|
|
675
|
+
# - ::undef?
|
|
676
|
+
#
|
|
263
677
|
def self.merge(data, force = true, basic = true)
|
|
264
678
|
value = data
|
|
265
|
-
|
|
266
|
-
# Special case because this method is called from within Config.new so we
|
|
679
|
+
|
|
680
|
+
# Special case because this method is called from within Config.new so we
|
|
267
681
|
# can not use Config.ensure, as that would cause an infinite loop.
|
|
268
682
|
if force.is_a?(Nucleon::Config)
|
|
269
683
|
basic = force.get(:basic, true)
|
|
270
|
-
force = force.get(:force, true)
|
|
684
|
+
force = force.get(:force, true)
|
|
271
685
|
end
|
|
272
|
-
|
|
686
|
+
|
|
273
687
|
if data.is_a?(Array)
|
|
274
688
|
value = undef?(data[0]) ? nil : data.shift.clone
|
|
275
|
-
|
|
689
|
+
|
|
276
690
|
data.each do |item|
|
|
277
691
|
item = undef?(item) ? nil : item.clone
|
|
278
|
-
|
|
692
|
+
|
|
279
693
|
case value
|
|
280
694
|
when Hash
|
|
281
695
|
if basic
|
|
282
696
|
if item.is_a?(Hash)
|
|
283
|
-
value = value.merge(item)
|
|
697
|
+
value = value.merge(item)
|
|
284
698
|
elsif force
|
|
285
699
|
value = item
|
|
286
|
-
end
|
|
700
|
+
end
|
|
287
701
|
else
|
|
288
702
|
begin
|
|
289
703
|
require 'deep_merge'
|
|
290
704
|
value = force ? value.deep_merge!(item) : value.deep_merge(item)
|
|
291
|
-
|
|
705
|
+
|
|
292
706
|
rescue LoadError
|
|
293
707
|
if item.is_a?(Hash) # Non recursive top level by default.
|
|
294
|
-
value = value.merge(item)
|
|
708
|
+
value = value.merge(item)
|
|
295
709
|
elsif force
|
|
296
710
|
value = item
|
|
297
711
|
end
|
|
298
712
|
end
|
|
299
|
-
end
|
|
713
|
+
end
|
|
300
714
|
when Array
|
|
301
715
|
if item.is_a?(Array)
|
|
302
716
|
value = value.concat(item).uniq
|
|
303
717
|
elsif force
|
|
304
718
|
value = item
|
|
305
719
|
end
|
|
306
|
-
|
|
720
|
+
|
|
307
721
|
else
|
|
308
722
|
value = item if force || item.is_a?(String) || item.is_a?(Symbol)
|
|
309
723
|
end
|
|
310
|
-
end
|
|
724
|
+
end
|
|
311
725
|
end
|
|
312
726
|
return value
|
|
313
727
|
end
|
|
314
728
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
729
|
+
# Interpolate values into data objects based on patterns.
|
|
730
|
+
#
|
|
731
|
+
# This method interpolates values into either a single string or a hash of
|
|
732
|
+
# strings that are recursively processed.
|
|
733
|
+
#
|
|
734
|
+
# This method requires our Hash#search method defined in the mod folder.
|
|
735
|
+
#
|
|
736
|
+
# * *Parameters*
|
|
737
|
+
# - [String, Hash] *value* Value to interpolate properties into
|
|
738
|
+
# - [Hash] *scope* Property values for text replacements
|
|
739
|
+
# - [Hash] *options* Method options
|
|
740
|
+
# - [String] *:pattern* Regexp pattern to match intepolated properties against
|
|
741
|
+
# - [Integer] *:var_group* Regexp group match for property name
|
|
742
|
+
# - [String] *:flags* Optional Regexp flags
|
|
743
|
+
#
|
|
744
|
+
# * *Returns*
|
|
745
|
+
# - [String, Hash] Returns interpolated string or hash of strings
|
|
746
|
+
#
|
|
747
|
+
# * *Errors*
|
|
748
|
+
#
|
|
749
|
+
# See also:
|
|
750
|
+
# - Hash#search
|
|
751
|
+
#
|
|
752
|
+
def self.interpolate(value, scope, options = {})
|
|
753
|
+
|
|
319
754
|
pattern = ( options.has_key?(:pattern) ? options[:pattern] : '\$(\{)?([a-zA-Z0-9\_\-]+)(\})?' )
|
|
320
755
|
group = ( options.has_key?(:var_group) ? options[:var_group] : 2 )
|
|
321
756
|
flags = ( options.has_key?(:flags) ? options[:flags] : '' )
|
|
322
|
-
|
|
757
|
+
|
|
323
758
|
if scope.is_a?(Hash)
|
|
324
759
|
regexp = Regexp.new(pattern, flags.split(''))
|
|
325
|
-
|
|
760
|
+
|
|
326
761
|
replace = lambda do |item|
|
|
327
762
|
matches = item.match(regexp)
|
|
328
763
|
result = nil
|
|
329
|
-
|
|
764
|
+
|
|
330
765
|
unless matches.nil?
|
|
331
766
|
replacement = scope.search(matches[group], options)
|
|
332
767
|
result = item.gsub(matches[0], replacement) unless replacement.nil?
|
|
333
768
|
end
|
|
334
769
|
return result
|
|
335
770
|
end
|
|
336
|
-
|
|
771
|
+
|
|
337
772
|
case value
|
|
338
773
|
when String
|
|
339
774
|
while (temp = replace.call(value))
|
|
340
775
|
value = temp
|
|
341
776
|
end
|
|
342
|
-
|
|
777
|
+
|
|
343
778
|
when Hash
|
|
344
779
|
value.each do |key, data|
|
|
345
780
|
value[key] = interpolate(data, scope, options)
|
|
346
781
|
end
|
|
347
782
|
end
|
|
348
783
|
end
|
|
349
|
-
return value
|
|
784
|
+
return value
|
|
350
785
|
end
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
786
|
+
|
|
787
|
+
# Remove keys from a given hash.
|
|
788
|
+
#
|
|
789
|
+
# This method first symbolizes all keys of the hash and then deletes any
|
|
790
|
+
# matching elements if the *symbolize* option is given.
|
|
791
|
+
#
|
|
792
|
+
# * *Parameters*
|
|
793
|
+
# - [Hash] *data* Ruby hash to remove keys from
|
|
794
|
+
# - [String, Symbol, Array] *keys* Keys to remove from
|
|
795
|
+
# - [Boolean] *symbolize* Whether or not to symbolize data keys before removal
|
|
796
|
+
#
|
|
797
|
+
# * *Returns*
|
|
798
|
+
# - [Hash] Returns cleaned data object
|
|
799
|
+
#
|
|
800
|
+
# * *Errors*
|
|
801
|
+
#
|
|
802
|
+
# See also:
|
|
803
|
+
# - ::hash
|
|
804
|
+
# - ::symbol_map
|
|
805
|
+
#
|
|
354
806
|
def self.rm_keys(data, keys, symbolize = false)
|
|
355
807
|
keys = [ keys ] unless keys.is_a?(Array)
|
|
356
808
|
data = hash(data)
|
|
357
809
|
data = symbol_map(data) if symbolize
|
|
358
|
-
|
|
810
|
+
|
|
359
811
|
keys.each do |key|
|
|
360
812
|
key = key.to_sym if symbolize
|
|
361
813
|
data.delete(key)
|
|
362
814
|
end
|
|
363
815
|
data
|
|
364
816
|
end
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
817
|
+
|
|
818
|
+
# Select specific keys from a given hash.
|
|
819
|
+
#
|
|
820
|
+
# This method first symbolizes all keys of the hash and then deletes any
|
|
821
|
+
# matching elements if the *symbolize* option is given.
|
|
822
|
+
#
|
|
823
|
+
# * *Parameters*
|
|
824
|
+
# - [Hash] *data* Ruby hash to select keys from
|
|
825
|
+
# - [String, Symbol, Array] *keys* Keys to select
|
|
826
|
+
# - [Boolean] *symbolize* Whether or not to symbolize data keys before selection
|
|
827
|
+
#
|
|
828
|
+
# * *Returns*
|
|
829
|
+
# - [Hash] Returns data object with selected keys
|
|
830
|
+
#
|
|
831
|
+
# * *Errors*
|
|
832
|
+
#
|
|
833
|
+
# See also:
|
|
834
|
+
# - ::hash
|
|
835
|
+
# - ::symbol_map
|
|
836
|
+
#
|
|
368
837
|
def self.subset(data, keys, symbolize = false)
|
|
369
838
|
keys = [ keys ] unless keys.is_a?(Array)
|
|
370
839
|
data = hash(data)
|
|
371
840
|
data = symbol_map(data) if symbolize
|
|
372
841
|
new_data = {}
|
|
373
|
-
|
|
842
|
+
|
|
374
843
|
keys.each do |key|
|
|
375
844
|
key = key.to_sym if symbolize
|
|
376
845
|
new_data[key] = data[key] if data.has_key?(key)
|
|
377
846
|
end
|
|
378
|
-
new_data
|
|
847
|
+
new_data
|
|
379
848
|
end
|
|
380
|
-
|
|
381
|
-
|
|
849
|
+
|
|
850
|
+
#*****************************************************************************
|
|
382
851
|
# Utilities
|
|
383
|
-
|
|
852
|
+
|
|
853
|
+
# Prefix every element in data with prefix separated by pad.
|
|
854
|
+
#
|
|
855
|
+
# This method basically just does bulk prefixing. This has come in useful in
|
|
856
|
+
# quite a few applications, particularly with dealing with configurations.
|
|
857
|
+
#
|
|
858
|
+
# This method can recursively set prefixes for hash keys as well.
|
|
859
|
+
#
|
|
860
|
+
# * *Parameters*
|
|
861
|
+
# - [String] *prefix* Prefix string to prepend to data elements
|
|
862
|
+
# - [String, Symbol, Array, Hash] *data* Data elements to prefix
|
|
863
|
+
# - [String] *pad* Whether or not to symbolize data keys before selection
|
|
864
|
+
#
|
|
865
|
+
# * *Returns*
|
|
866
|
+
# - [String, Symbol, Array, Hash] Returns prefixed data object
|
|
867
|
+
#
|
|
868
|
+
# * *Errors*
|
|
869
|
+
#
|
|
870
|
+
# See also:
|
|
871
|
+
# - ::empty?
|
|
872
|
+
#
|
|
384
873
|
def self.prefix(prefix, data, pad = '_')
|
|
385
874
|
result = nil
|
|
386
|
-
|
|
387
|
-
unless prefix.is_a?(String) && ! empty?(prefix)
|
|
875
|
+
|
|
876
|
+
unless prefix.is_a?(Symbol) || ( prefix.is_a?(String) && ! empty?(prefix) )
|
|
388
877
|
prefix = ''
|
|
389
878
|
end
|
|
390
|
-
|
|
879
|
+
prefix = prefix.to_s
|
|
880
|
+
|
|
391
881
|
case data
|
|
392
882
|
when String, Symbol
|
|
393
883
|
result = ( prefix.empty? ? data.to_s : prefix + pad + data.to_s )
|
|
394
|
-
|
|
884
|
+
|
|
395
885
|
when Array
|
|
396
886
|
result = []
|
|
397
887
|
data.each do |value|
|
|
398
888
|
result << prefix(prefix, value, pad)
|
|
399
889
|
end
|
|
400
|
-
|
|
890
|
+
|
|
401
891
|
when Hash
|
|
402
892
|
result = {}
|
|
403
893
|
data.each do |key, value|
|
|
404
|
-
result[prefix(prefix, key, pad)] = value
|
|
405
|
-
end
|
|
894
|
+
result[prefix(prefix, key, pad)] = value
|
|
895
|
+
end
|
|
406
896
|
end
|
|
407
897
|
return result
|
|
408
898
|
end
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
899
|
+
|
|
900
|
+
# Ensure a value is set one way or another depending on a test condition.
|
|
901
|
+
#
|
|
902
|
+
# * *Parameters*
|
|
903
|
+
# - [Boolean] *test* Test for success / failure
|
|
904
|
+
# - [ANY] *success_value* Value returned if test is not empty
|
|
905
|
+
# - [ANY] *failure_value* Value returned if test is empty
|
|
906
|
+
#
|
|
907
|
+
# * *Returns*
|
|
908
|
+
# - [ANY] Success or failure values depending on the outcome of test
|
|
909
|
+
#
|
|
910
|
+
# * *Errors*
|
|
911
|
+
#
|
|
912
|
+
# See also:
|
|
913
|
+
# - ::empty?
|
|
914
|
+
#
|
|
412
915
|
def self.ensure(test, success_value = nil, failure_value = nil)
|
|
413
916
|
success_value = (success_value ? success_value : test)
|
|
414
917
|
failure_value = (failure_value ? failure_value : nil)
|
|
415
|
-
|
|
918
|
+
|
|
416
919
|
if empty?(test)
|
|
417
920
|
value = failure_value
|
|
418
921
|
else
|
|
@@ -420,9 +923,21 @@ class Data
|
|
|
420
923
|
end
|
|
421
924
|
return value
|
|
422
925
|
end
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
926
|
+
|
|
927
|
+
# Return value if not empty or else return failure value.
|
|
928
|
+
#
|
|
929
|
+
# * *Parameters*
|
|
930
|
+
# - [ANY] *value* Test for success / failure
|
|
931
|
+
# - [ANY] *failure_value* Value returned if value is empty
|
|
932
|
+
#
|
|
933
|
+
# * *Returns*
|
|
934
|
+
# - [ANY] Value or failure value depending on the emptiness of value
|
|
935
|
+
#
|
|
936
|
+
# * *Errors*
|
|
937
|
+
#
|
|
938
|
+
# See:
|
|
939
|
+
# - ::ensure
|
|
940
|
+
#
|
|
426
941
|
def self.ensure_value(value, failure_value = nil)
|
|
427
942
|
return self.ensure(value, nil, failure_value)
|
|
428
943
|
end
|