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/codes.rb
CHANGED
|
@@ -1,107 +1,134 @@
|
|
|
1
1
|
|
|
2
2
|
module Nucleon
|
|
3
3
|
class Codes
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
#-----------------------------------------------------------------------------
|
|
6
6
|
# Code index
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
@@registry = {}
|
|
9
9
|
@@status_index = {}
|
|
10
10
|
@@next_code = 0
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
#---
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
def self.registry
|
|
15
15
|
@@registry
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
#---
|
|
19
|
+
|
|
20
|
+
def self.status_index
|
|
21
|
+
@@status_index
|
|
22
|
+
end
|
|
23
|
+
|
|
18
24
|
#---
|
|
19
|
-
|
|
25
|
+
|
|
20
26
|
def self.index(status_code = nil)
|
|
21
27
|
if status_code.nil? || ! status_code.integer?
|
|
22
28
|
@@status_index
|
|
23
29
|
else
|
|
24
30
|
status_code = status_code.to_i
|
|
25
|
-
|
|
31
|
+
|
|
26
32
|
if @@status_index.has_key?(status_code)
|
|
27
33
|
@@status_index[status_code]
|
|
28
34
|
else
|
|
29
35
|
@@status_index[registry[:unknown_status]]
|
|
30
|
-
end
|
|
31
|
-
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#---
|
|
41
|
+
|
|
42
|
+
def self.render_status(status_code = nil)
|
|
43
|
+
if ! status_code.nil? && @@status_index.has_key?(status_code)
|
|
44
|
+
status_name = @@status_index[status_code]
|
|
45
|
+
else
|
|
46
|
+
status_name = @@status_index[registry[:unknown_status]]
|
|
47
|
+
end
|
|
48
|
+
sprintf(" [ %3i ] - %s\n", status_code, status_name.gsub(/_/, ' ').capitalize)
|
|
32
49
|
end
|
|
33
|
-
|
|
50
|
+
|
|
34
51
|
#---
|
|
35
|
-
|
|
52
|
+
|
|
36
53
|
def self.render_index(status_code = nil)
|
|
37
54
|
output = "Status index:\n"
|
|
38
55
|
@@status_index.each do |code, name|
|
|
39
56
|
name = name.gsub(/_/, ' ').capitalize
|
|
40
|
-
|
|
57
|
+
|
|
41
58
|
if ! status_code.nil? && status_code == code
|
|
42
59
|
output << sprintf(" [ %3i ] - %s\n", code, name)
|
|
43
60
|
else
|
|
44
61
|
output << sprintf(" %3i - %s\n", code, name)
|
|
45
|
-
end
|
|
62
|
+
end
|
|
46
63
|
end
|
|
47
64
|
output << "\n"
|
|
48
65
|
output
|
|
49
66
|
end
|
|
50
|
-
|
|
67
|
+
|
|
51
68
|
#-----------------------------------------------------------------------------
|
|
52
69
|
# Code construction
|
|
53
|
-
|
|
70
|
+
|
|
54
71
|
def self.code(name)
|
|
55
72
|
name = name.to_sym
|
|
56
|
-
|
|
73
|
+
|
|
57
74
|
unless registry.has_key?(name)
|
|
58
|
-
status_code = @@next_code
|
|
75
|
+
status_code = @@next_code
|
|
59
76
|
@@next_code = @@next_code + 1
|
|
60
|
-
|
|
77
|
+
|
|
61
78
|
# TODO: Add more information to the index (like a help message)
|
|
62
79
|
@@registry[name] = status_code
|
|
63
80
|
@@status_index[status_code] = name.to_s
|
|
64
81
|
end
|
|
65
82
|
end
|
|
66
|
-
|
|
83
|
+
|
|
67
84
|
#---
|
|
68
|
-
|
|
85
|
+
|
|
69
86
|
def self.codes(*codes)
|
|
70
87
|
codes.each do |name|
|
|
71
88
|
code(name)
|
|
72
89
|
end
|
|
73
90
|
end
|
|
74
91
|
|
|
92
|
+
#--
|
|
93
|
+
|
|
94
|
+
def self.reset
|
|
95
|
+
@@registry = {}
|
|
96
|
+
@@status_index = {}
|
|
97
|
+
@@next_code = 0
|
|
98
|
+
|
|
99
|
+
code(:success) # This must be added first (needs to be 0)
|
|
100
|
+
code(:help_wanted)
|
|
101
|
+
code(:unknown_status)
|
|
102
|
+
|
|
103
|
+
code(:action_unprocessed)
|
|
104
|
+
code(:batch_error)
|
|
105
|
+
|
|
106
|
+
code(:validation_failed)
|
|
107
|
+
code(:access_denied)
|
|
108
|
+
end
|
|
109
|
+
|
|
75
110
|
#-----------------------------------------------------------------------------
|
|
76
111
|
# Return status codes on demand
|
|
77
|
-
|
|
112
|
+
|
|
78
113
|
def [](name)
|
|
79
114
|
name = name.to_sym
|
|
80
|
-
|
|
115
|
+
|
|
81
116
|
if @@registry.has_key?(name)
|
|
82
|
-
@@registry[name]
|
|
117
|
+
@@registry[name]
|
|
83
118
|
else
|
|
84
119
|
@@registry[:unknown_status]
|
|
85
120
|
end
|
|
86
121
|
end
|
|
87
|
-
|
|
122
|
+
|
|
88
123
|
#---
|
|
89
|
-
|
|
124
|
+
|
|
90
125
|
def method_missing(method, *args, &block)
|
|
91
126
|
self[method]
|
|
92
127
|
end
|
|
93
|
-
|
|
128
|
+
|
|
94
129
|
#-----------------------------------------------------------------------------
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
code(:unknown_status)
|
|
100
|
-
|
|
101
|
-
code(:action_unprocessed)
|
|
102
|
-
code(:batch_error)
|
|
103
|
-
|
|
104
|
-
code(:validation_failed)
|
|
105
|
-
code(:access_denied)
|
|
130
|
+
# Initialize status codes
|
|
131
|
+
|
|
132
|
+
reset
|
|
133
|
+
end
|
|
106
134
|
end
|
|
107
|
-
end
|
data/lib/core/config.rb
CHANGED
|
@@ -1,53 +1,247 @@
|
|
|
1
|
-
|
|
2
1
|
module Nucleon
|
|
2
|
+
#
|
|
3
|
+
# == Base configuration object
|
|
4
|
+
#
|
|
5
|
+
# The Nucleon::Config class defines a tree data container that can easily be
|
|
6
|
+
# merged and persisted to different mediums.
|
|
7
|
+
#
|
|
8
|
+
# The configuration is at the core of the Nucleon framework. The configuration
|
|
9
|
+
# allows us to store, lookup, and perform other operations (such as merge) on
|
|
10
|
+
# our class data by treating a subset of class properties as a tree based data
|
|
11
|
+
# structure.
|
|
12
|
+
#
|
|
13
|
+
# Four main goals with this object:
|
|
14
|
+
#
|
|
15
|
+
# 1. Centralized property trees for objects
|
|
16
|
+
# 2. Easy access and management of nested properties
|
|
17
|
+
# 3. Mergeable objects (deep or shallow merges of tree based data)
|
|
18
|
+
# 4. Provide basic data translation utilities to sub classes
|
|
19
|
+
#
|
|
20
|
+
# == Global interface
|
|
21
|
+
#
|
|
22
|
+
# The Nucleon::Config class uses two *static* mixins that provide a central
|
|
23
|
+
# registry for option groups and property collections.
|
|
24
|
+
#
|
|
25
|
+
# Option groups are contextualized collections of properties
|
|
26
|
+
#
|
|
27
|
+
# - see Nucleon::Config::Options (collection implementation)
|
|
28
|
+
# - see Nucleon::Mixin::ConfigOptions (embeddable method interface)
|
|
29
|
+
#
|
|
30
|
+
# Property collections are flexible groups of properties that can be logged
|
|
31
|
+
# to file system.
|
|
32
|
+
#
|
|
33
|
+
# - see Nucleon::Config::Collection (collection implementation)
|
|
34
|
+
# - see Nucleon::Mixin::ConfigCollection (embeddable method interface)
|
|
35
|
+
#
|
|
36
|
+
# == Instance generators
|
|
37
|
+
#
|
|
38
|
+
# The core configuration object provides a few instance generators that allow
|
|
39
|
+
# for easier initialization of configurations.
|
|
40
|
+
#
|
|
3
41
|
class Config
|
|
4
|
-
|
|
5
|
-
|
|
42
|
+
|
|
43
|
+
#*****************************************************************************
|
|
6
44
|
# Global interface
|
|
7
45
|
|
|
46
|
+
# Include global contextual configuration option interface
|
|
47
|
+
#
|
|
48
|
+
# See:
|
|
49
|
+
# - Nucleon::Mixin::ConfigOptions
|
|
50
|
+
# - Nucleon::Config::Options
|
|
51
|
+
#
|
|
8
52
|
extend Mixin::ConfigOptions
|
|
53
|
+
|
|
54
|
+
# Include global configuration log interface
|
|
55
|
+
#
|
|
56
|
+
# See:
|
|
57
|
+
# - Nucleon::Mixin::ConfigCollection
|
|
58
|
+
# - Nucleon::Config::Collection
|
|
59
|
+
#
|
|
9
60
|
extend Mixin::ConfigCollection
|
|
10
|
-
|
|
11
|
-
|
|
61
|
+
|
|
62
|
+
#*****************************************************************************
|
|
12
63
|
# Instance generators
|
|
13
|
-
|
|
64
|
+
|
|
65
|
+
# Ensure the return of a Nucleon::Config object based on different inputs.
|
|
66
|
+
#
|
|
67
|
+
# This method can also initialize defaults for the configuration object if
|
|
68
|
+
# the configurations do not exist yet.
|
|
69
|
+
#
|
|
70
|
+
# For example: (you will see variants of this pattern everywhere)
|
|
71
|
+
#
|
|
72
|
+
# def some_method(options = {})
|
|
73
|
+
# # Options might be a Config object or Hash?
|
|
74
|
+
# config = Config.ensure(options, { :my_property => 'default value' })
|
|
75
|
+
# prop = config[:my_property]
|
|
76
|
+
# end
|
|
77
|
+
#
|
|
78
|
+
# * *Parameters*
|
|
79
|
+
# - [nil, Hash, Nucleon::Config] *config* Configurations to evaluate and possibly convert
|
|
80
|
+
# - [Hash] *defaults* Configuration defaults that may be overridden by config data
|
|
81
|
+
# - [Boolean] *force* Whether or not to force override of values where types don't match during merge
|
|
82
|
+
# - [Boolean] *basic_merge* Whether or not to perform a basic merge or deep (recursive) merge
|
|
83
|
+
#
|
|
84
|
+
# * *Returns*
|
|
85
|
+
# - [Nucleon::Config] Returns configuration object
|
|
86
|
+
#
|
|
87
|
+
# * *Errors*
|
|
88
|
+
#
|
|
89
|
+
# See:
|
|
90
|
+
# - ::new
|
|
91
|
+
# - #defaults
|
|
92
|
+
#
|
|
14
93
|
def self.ensure(config, defaults = {}, force = true, basic_merge = true)
|
|
15
94
|
case config
|
|
16
95
|
when Nucleon::Config
|
|
17
|
-
return config.defaults(defaults)
|
|
96
|
+
return config.defaults(defaults, { :force => force, :basic => basic_merge })
|
|
18
97
|
when Hash
|
|
19
|
-
return new(config, defaults, force, basic_merge)
|
|
98
|
+
return new(config, defaults, force, basic_merge)
|
|
20
99
|
end
|
|
21
100
|
return new({}, defaults, force, basic_merge)
|
|
22
101
|
end
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
102
|
+
|
|
103
|
+
# Initialize a new configuration object with contextualized defaults from the
|
|
104
|
+
# global configuration option collection.
|
|
105
|
+
#
|
|
106
|
+
# This method is not really used much within Nucleon itself, but is used to
|
|
107
|
+
# help create the corl gem Puppet interface that forms the provisioner
|
|
108
|
+
# configurations for resource creation based on options defined in Puppet.
|
|
109
|
+
#
|
|
110
|
+
# This method supports hierarchical lookup of context properties.
|
|
111
|
+
#
|
|
112
|
+
# Example:
|
|
113
|
+
#
|
|
114
|
+
# Nucleon::Config::set_options([ :context1, :prefix_context2 ], { :my_property => 'value' })
|
|
115
|
+
#
|
|
116
|
+
# config = Nucleon::Config.init({ :other_property => 'something' }, :context2, :prefix)
|
|
117
|
+
# config.export
|
|
118
|
+
# # {
|
|
119
|
+
# # :my_property => 'value',
|
|
120
|
+
# # :other_property => 'something'
|
|
121
|
+
# # }
|
|
122
|
+
#
|
|
123
|
+
# * *Parameters*
|
|
124
|
+
# - [nil, Hash, Nucleon::Config] *config* Configurations to evaluate and possibly convert
|
|
125
|
+
# - [Array<String, Symbol>, String, Symbol] *contexts* Context names to include in list
|
|
126
|
+
# - [Array<String, Symbol>, String, Symbol] *hierarchy* Hierarchy of prefixes to apply to given contexts
|
|
127
|
+
# - [Hash] *defaults* Configuration defaults that may be overridden by config data
|
|
128
|
+
# - [Boolean] *force* Whether or not to force override of values where types don't match during merge
|
|
129
|
+
# - [Boolean] *basic_merge* Whether or not to perform a basic merge or deep (recursive) merge
|
|
130
|
+
#
|
|
131
|
+
# * *Returns*
|
|
132
|
+
# - [Nucleon::Config] Returns configuration object
|
|
133
|
+
#
|
|
134
|
+
# * *Errors*
|
|
135
|
+
#
|
|
136
|
+
# See also:
|
|
137
|
+
# - Nucleon::Config::Options
|
|
138
|
+
# - Nucleon::Mixin::ConfigOptions#contexts
|
|
139
|
+
# - Nucleon::Mixin::ConfigOptions#get_options
|
|
140
|
+
# - ::new
|
|
141
|
+
# - #import
|
|
142
|
+
# - Util::Data::empty?
|
|
143
|
+
#
|
|
26
144
|
def self.init(options, contexts = [], hierarchy = [], defaults = {}, force = true, basic_merge = true)
|
|
27
145
|
contexts = contexts(contexts, hierarchy)
|
|
28
146
|
config = new(get_options(contexts), defaults, force, basic_merge)
|
|
29
147
|
config.import(options) unless Util::Data.empty?(options)
|
|
30
148
|
return config
|
|
31
149
|
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
150
|
+
|
|
151
|
+
# Initialize a new configuration object with contextualized defaults from the
|
|
152
|
+
# global configuration option collection (no hierarchical support).
|
|
153
|
+
#
|
|
154
|
+
# This method is not really used much within Nucleon itself, but is used to
|
|
155
|
+
# help create the corl gem Puppet interface that forms the provisioner
|
|
156
|
+
# configurations for resource creation based on options defined in Puppet.
|
|
157
|
+
#
|
|
158
|
+
# Example:
|
|
159
|
+
#
|
|
160
|
+
# Nucleon::Config::set_options([ :context1, :context2 ], { :my_property => 'value' })
|
|
161
|
+
#
|
|
162
|
+
# config = Nucleon::Config.init_flat({ :other_property => 'something' }, :context2)
|
|
163
|
+
# config.export
|
|
164
|
+
# # {
|
|
165
|
+
# # :my_property => 'value',
|
|
166
|
+
# # :other_property => 'something'
|
|
167
|
+
# # }
|
|
168
|
+
#
|
|
169
|
+
# * *Parameters*
|
|
170
|
+
# - [nil, Hash, Nucleon::Config] *config* Configurations to evaluate and possibly convert
|
|
171
|
+
# - [Array<String, Symbol>, String, Symbol] *contexts* Context names to include in list
|
|
172
|
+
# - [Hash] *defaults* Configuration defaults that may be overridden by config data
|
|
173
|
+
# - [Boolean] *force* Whether or not to force override of values where types don't match during merge
|
|
174
|
+
# - [Boolean] *basic_merge* Whether or not to perform a basic merge or deep (recursive) merge
|
|
175
|
+
#
|
|
176
|
+
# * *Returns*
|
|
177
|
+
# - [Nucleon::Config] Returns configuration object
|
|
178
|
+
#
|
|
179
|
+
# * *Errors*
|
|
180
|
+
#
|
|
181
|
+
# See:
|
|
182
|
+
# - ::init
|
|
183
|
+
#
|
|
35
184
|
def self.init_flat(options, contexts = [], defaults = {}, force = true, basic_merge = true)
|
|
36
185
|
return init(options, contexts, [], defaults, force, basic_merge)
|
|
37
186
|
end
|
|
38
|
-
|
|
39
|
-
|
|
187
|
+
|
|
188
|
+
#*****************************************************************************
|
|
40
189
|
# Constructor / Destructor
|
|
41
|
-
|
|
190
|
+
|
|
191
|
+
# Initialize a new configuration object with given options and defaults.
|
|
192
|
+
#
|
|
193
|
+
# The defaults are split out from the original options because we have found
|
|
194
|
+
# it handy to have them initialized from two different data objects. Defaults
|
|
195
|
+
# are only set if the original data lacks the default property name.
|
|
196
|
+
#
|
|
197
|
+
# The configuration object is ultimately designed to provide a starting point
|
|
198
|
+
# for creating distributed objects, which are easily loaded, dumped, and merged
|
|
199
|
+
# to form composite objects.
|
|
200
|
+
#
|
|
201
|
+
# The configuration serves as the framework base class to all Nucleon plugins,
|
|
202
|
+
# core objects, and a few utilities. This class is the most important object
|
|
203
|
+
# in the entire Nucleon framework, as it is used the most.
|
|
204
|
+
#
|
|
205
|
+
# Example:
|
|
206
|
+
#
|
|
207
|
+
# config = Nucleon::Config.new({ :other_property => 'something' }, {
|
|
208
|
+
# :my_property => 'default',
|
|
209
|
+
# :other_property => 'default'
|
|
210
|
+
# })
|
|
211
|
+
# config.export
|
|
212
|
+
# # {
|
|
213
|
+
# # :my_property => 'default',
|
|
214
|
+
# # :other_property => 'something'
|
|
215
|
+
# # }
|
|
216
|
+
#
|
|
217
|
+
# * *Parameters*
|
|
218
|
+
# - [nil, Hash, Nucleon::Config] *data* Configurations to evaluate and possibly convert
|
|
219
|
+
# - [Hash] *defaults* Configuration defaults that may be overridden by config data
|
|
220
|
+
# - [Boolean] *force* Whether or not to force override of values where types don't match during merge
|
|
221
|
+
# - [Boolean] *basic_merge* Whether or not to perform a basic merge or deep (recursive) merge
|
|
222
|
+
#
|
|
223
|
+
# * *Returns*
|
|
224
|
+
# - [Nucleon::Config] Returns configuration object
|
|
225
|
+
#
|
|
226
|
+
# * *Errors*
|
|
227
|
+
#
|
|
228
|
+
# See also:
|
|
229
|
+
# - ::ensure
|
|
230
|
+
# - ::init
|
|
231
|
+
# - ::init_flat
|
|
232
|
+
# - #symbol_map
|
|
233
|
+
# - #export
|
|
234
|
+
# - Nucleon::Util::Data::merge
|
|
235
|
+
#
|
|
42
236
|
def initialize(data = {}, defaults = {}, force = true, basic_merge = true)
|
|
43
237
|
@force = force
|
|
44
238
|
@basic_merge = basic_merge
|
|
45
239
|
@properties = {}
|
|
46
|
-
|
|
240
|
+
|
|
47
241
|
if defaults.is_a?(Hash) && ! defaults.empty?
|
|
48
242
|
defaults = symbol_map(defaults.clone)
|
|
49
243
|
end
|
|
50
|
-
|
|
244
|
+
|
|
51
245
|
case data
|
|
52
246
|
when Nucleon::Config
|
|
53
247
|
@properties = Util::Data.merge([ defaults, data.export ], force, basic_merge)
|
|
@@ -56,296 +250,723 @@ class Config
|
|
|
56
250
|
if data.is_a?(Hash)
|
|
57
251
|
@properties = Util::Data.merge([ defaults, symbol_map(data.clone) ], force, basic_merge)
|
|
58
252
|
end
|
|
253
|
+
else
|
|
254
|
+
@properties = defaults if defaults.is_a?(Hash)
|
|
59
255
|
end
|
|
60
256
|
end
|
|
61
|
-
|
|
62
|
-
|
|
257
|
+
|
|
258
|
+
#*****************************************************************************
|
|
63
259
|
# Checks
|
|
64
|
-
|
|
260
|
+
|
|
261
|
+
# Check whether or not this configuration object is empty.
|
|
262
|
+
#
|
|
263
|
+
# * *Parameters*
|
|
264
|
+
#
|
|
265
|
+
# * *Returns*
|
|
266
|
+
# - [Boolean] Whether or not configuration object is empty
|
|
267
|
+
#
|
|
268
|
+
# * *Errors*
|
|
269
|
+
#
|
|
65
270
|
def empty?
|
|
66
271
|
@properties.empty?
|
|
67
272
|
end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
273
|
+
|
|
274
|
+
# Check whether or not this configuration object has a specific key.
|
|
275
|
+
#
|
|
276
|
+
# The purpose of this method is to provide a complimentary has_key? method to
|
|
277
|
+
# the Hash class so we can check either interchangeably.
|
|
278
|
+
#
|
|
279
|
+
# * *Parameters*
|
|
280
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to check
|
|
281
|
+
#
|
|
282
|
+
# * *Returns*
|
|
283
|
+
# - [Boolean] Whether or not configuration object has a specific key
|
|
284
|
+
#
|
|
285
|
+
# * *Errors*
|
|
286
|
+
#
|
|
287
|
+
# See:
|
|
288
|
+
# - #get
|
|
289
|
+
#
|
|
71
290
|
def has_key?(keys)
|
|
72
291
|
get(keys).nil? ? false : true
|
|
73
292
|
end
|
|
74
|
-
|
|
75
|
-
|
|
293
|
+
|
|
294
|
+
#*****************************************************************************
|
|
76
295
|
# Property accessors / modifiers
|
|
77
|
-
|
|
296
|
+
|
|
297
|
+
# Return all of the keys for the configuration properties hash.
|
|
298
|
+
#
|
|
299
|
+
# The purpose of this method is to provide a complimentary keys method to
|
|
300
|
+
# the Hash class so we can return either interchangeably.
|
|
301
|
+
#
|
|
302
|
+
# * *Parameters*
|
|
303
|
+
#
|
|
304
|
+
# * *Returns*
|
|
305
|
+
# - [Array<Symbol>] Array of existing configuration properties
|
|
306
|
+
#
|
|
307
|
+
# * *Errors*
|
|
308
|
+
#
|
|
78
309
|
def keys
|
|
79
310
|
@properties.keys
|
|
80
311
|
end
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
312
|
+
|
|
313
|
+
# Recursively fetch value for key path in the configuration object.
|
|
314
|
+
#
|
|
315
|
+
# This method serves as a base accessor to the properties that are defined in
|
|
316
|
+
# the central property collection. It is used and built upon by other
|
|
317
|
+
# accessors defined in the class.
|
|
318
|
+
#
|
|
319
|
+
# Hash data is assumed to already be symbolized.
|
|
320
|
+
#
|
|
321
|
+
# * *Parameters*
|
|
322
|
+
# - [Hash] *data* Configuration property data
|
|
323
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to fetch
|
|
324
|
+
# - [ANY] *default* Default value is no value is found for key path
|
|
325
|
+
# - [false, Symbol, String] *format* Format to filter final returned value or false for none
|
|
326
|
+
#
|
|
327
|
+
# * *Returns*
|
|
328
|
+
# - [ANY] Filtered value for key path from configuration object
|
|
329
|
+
#
|
|
330
|
+
# * *Errors*
|
|
331
|
+
#
|
|
332
|
+
# See:
|
|
333
|
+
# - #filter
|
|
334
|
+
# - Nucleon::Util::Data::filter
|
|
335
|
+
#
|
|
84
336
|
def fetch(data, keys, default = nil, format = false)
|
|
85
337
|
if keys.is_a?(String) || keys.is_a?(Symbol)
|
|
86
338
|
keys = [ keys ]
|
|
87
339
|
end
|
|
88
|
-
|
|
89
|
-
keys = keys.flatten.compact
|
|
340
|
+
|
|
341
|
+
keys = keys.flatten.compact
|
|
90
342
|
key = keys.shift.to_sym
|
|
91
|
-
|
|
343
|
+
|
|
92
344
|
if data.has_key?(key)
|
|
93
345
|
value = data[key]
|
|
94
|
-
|
|
346
|
+
|
|
95
347
|
if keys.empty?
|
|
96
348
|
return filter(value, format)
|
|
97
349
|
else
|
|
98
|
-
return fetch(data[key], keys, default, format) if data[key].is_a?(Hash)
|
|
350
|
+
return fetch(data[key], keys, default, format) if data[key].is_a?(Hash)
|
|
99
351
|
end
|
|
100
352
|
end
|
|
101
353
|
return filter(default, format)
|
|
102
354
|
end
|
|
103
355
|
protected :fetch
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
356
|
+
|
|
357
|
+
# Modify value for key path in the configuration object.
|
|
358
|
+
#
|
|
359
|
+
# This method serves as a base modifier to the properties that are defined in
|
|
360
|
+
# the central property collection. It is used and built upon by other
|
|
361
|
+
# modifiers defined in the class.
|
|
362
|
+
#
|
|
363
|
+
# Hash data is assumed to already be symbolized.
|
|
364
|
+
#
|
|
365
|
+
# * *Parameters*
|
|
366
|
+
# - [Hash] *data* Configuration property data
|
|
367
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
|
|
368
|
+
# - [ANY] *value* Value to set for key path
|
|
369
|
+
# - [Boolean] *delete_nil* Delete nil value (serves as an internal way to delete properties)
|
|
370
|
+
#
|
|
371
|
+
# * *Returns*
|
|
372
|
+
# - [ANY] Existing value for key path from configuration object (before update)
|
|
373
|
+
#
|
|
374
|
+
# * *Errors*
|
|
375
|
+
#
|
|
376
|
+
# * *Yields*
|
|
377
|
+
# - [Symbol] *key* Configuration key to modify
|
|
378
|
+
# - [ANY] *value* New value of configuration key
|
|
379
|
+
# - [ANY] *existing* Existing value being replaced for the configuration key
|
|
380
|
+
#
|
|
381
|
+
# See:
|
|
382
|
+
# - #symbol_map
|
|
383
|
+
# - Nucleon::Util::Data::symbol_map
|
|
384
|
+
#
|
|
385
|
+
def modify(data, keys, value = nil, delete_nil = false, &block) # :yields: key, value, existing
|
|
108
386
|
if keys.is_a?(String) || keys.is_a?(Symbol)
|
|
109
387
|
keys = [ keys ]
|
|
110
388
|
end
|
|
111
|
-
|
|
389
|
+
|
|
112
390
|
keys = keys.flatten.compact
|
|
113
391
|
key = keys.shift.to_sym
|
|
114
392
|
has_key = data.has_key?(key)
|
|
115
|
-
existing = {
|
|
116
|
-
:key => key,
|
|
117
|
-
:value => ( has_key ? data[key] : nil )
|
|
393
|
+
existing = {
|
|
394
|
+
:key => key,
|
|
395
|
+
:value => ( has_key ? data[key] : nil )
|
|
118
396
|
}
|
|
119
|
-
|
|
120
|
-
if keys.empty?
|
|
121
|
-
existing[:value] = data[key] if has_key
|
|
122
|
-
|
|
397
|
+
|
|
398
|
+
if keys.empty?
|
|
123
399
|
if value.nil? && delete_nil
|
|
124
400
|
data.delete(key) if has_key
|
|
125
401
|
else
|
|
126
|
-
|
|
402
|
+
value = symbol_map(value) if value.is_a?(Hash)
|
|
403
|
+
data[key] = block ? block.call(key, value, existing[:value]) : value
|
|
127
404
|
end
|
|
128
|
-
else
|
|
405
|
+
else
|
|
129
406
|
data[key] = {} unless has_key
|
|
130
|
-
|
|
407
|
+
|
|
131
408
|
if data[key].is_a?(Hash)
|
|
132
|
-
existing = modify(data[key], keys, value, delete_nil)
|
|
409
|
+
existing = modify(data[key], keys, value, delete_nil, &block)
|
|
133
410
|
else
|
|
134
|
-
existing[:value] = nil
|
|
135
|
-
end
|
|
411
|
+
existing[:value] = nil
|
|
412
|
+
end
|
|
136
413
|
end
|
|
137
|
-
|
|
414
|
+
|
|
138
415
|
return existing
|
|
139
416
|
end
|
|
140
417
|
protected :modify
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
418
|
+
|
|
419
|
+
# Fetch value for key path in the configuration object.
|
|
420
|
+
#
|
|
421
|
+
# * *Parameters*
|
|
422
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to fetch
|
|
423
|
+
# - [ANY] *default* Default value is no value is found for key path
|
|
424
|
+
# - [false, Symbol, String] *format* Format to filter final returned value or false for none
|
|
425
|
+
#
|
|
426
|
+
# * *Returns*
|
|
427
|
+
# - [ANY] Filtered value for key path from configuration object
|
|
428
|
+
#
|
|
429
|
+
# * *Errors*
|
|
430
|
+
#
|
|
431
|
+
# See:
|
|
432
|
+
# - #fetch
|
|
433
|
+
#
|
|
434
|
+
# See also:
|
|
435
|
+
# - #array
|
|
436
|
+
#
|
|
144
437
|
def get(keys, default = nil, format = false)
|
|
145
438
|
return fetch(@properties, array(keys).flatten, default, format)
|
|
146
439
|
end
|
|
147
440
|
|
|
148
|
-
|
|
149
|
-
|
|
441
|
+
# Fetch value for key path in the configuration object.
|
|
442
|
+
#
|
|
443
|
+
# This method is really just to provide an easier interface compatible with
|
|
444
|
+
# Hash access for simpler configuration groups.
|
|
445
|
+
#
|
|
446
|
+
# * *Parameters*
|
|
447
|
+
# - [String, Symbol] *name* Key to fetch
|
|
448
|
+
# - [ANY] *default* Default value is no value is found for key
|
|
449
|
+
# - [false, Symbol, String] *format* Format to filter final returned value or false for none
|
|
450
|
+
#
|
|
451
|
+
# * *Returns*
|
|
452
|
+
# - [ANY] Filtered value for key path from configuration object
|
|
453
|
+
#
|
|
454
|
+
# * *Errors*
|
|
455
|
+
#
|
|
456
|
+
# See:
|
|
457
|
+
# - #get
|
|
458
|
+
#
|
|
150
459
|
def [](name, default = nil, format = false)
|
|
151
460
|
get(name, default, format)
|
|
152
461
|
end
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
462
|
+
|
|
463
|
+
# Fetch filtered array value for key path in the configuration object.
|
|
464
|
+
#
|
|
465
|
+
# * *Parameters*
|
|
466
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to fetch
|
|
467
|
+
# - [Array] *default* Default value is no value is found for key path
|
|
468
|
+
#
|
|
469
|
+
# * *Returns*
|
|
470
|
+
# - [Array] Filtered array value for key path from configuration object
|
|
471
|
+
#
|
|
472
|
+
# * *Errors*
|
|
473
|
+
#
|
|
474
|
+
# See:
|
|
475
|
+
# - #get
|
|
476
|
+
#
|
|
477
|
+
# See also:
|
|
478
|
+
# - #array
|
|
479
|
+
# - Nucleon::Util::Data::array
|
|
480
|
+
#
|
|
156
481
|
def get_array(keys, default = [])
|
|
157
482
|
return get(keys, default, :array)
|
|
158
483
|
end
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
484
|
+
|
|
485
|
+
# Fetch filtered hash value for key path in the configuration object.
|
|
486
|
+
#
|
|
487
|
+
# * *Parameters*
|
|
488
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to fetch
|
|
489
|
+
# - [Hash] *default* Default hash value is no value is found for key path
|
|
490
|
+
#
|
|
491
|
+
# * *Returns*
|
|
492
|
+
# - [Hash] Filtered hash value for key path from configuration object
|
|
493
|
+
#
|
|
494
|
+
# * *Errors*
|
|
495
|
+
#
|
|
496
|
+
# See:
|
|
497
|
+
# - #get
|
|
498
|
+
#
|
|
499
|
+
# See also:
|
|
500
|
+
# - #hash
|
|
501
|
+
# - Nucleon::Util::Data::hash
|
|
502
|
+
#
|
|
162
503
|
def get_hash(keys, default = {})
|
|
163
504
|
return get(keys, default, :hash)
|
|
164
505
|
end
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
506
|
+
|
|
507
|
+
# Initialize value for key path in the configuration object if one does not
|
|
508
|
+
# exist yet.
|
|
509
|
+
#
|
|
510
|
+
# * *Parameters*
|
|
511
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
|
|
512
|
+
# - [ANY] *default* Default value to set for key path if it does not exist yet
|
|
513
|
+
#
|
|
514
|
+
# * *Returns*
|
|
515
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
516
|
+
#
|
|
517
|
+
# * *Errors*
|
|
518
|
+
#
|
|
519
|
+
# See:
|
|
520
|
+
# - #get
|
|
521
|
+
# - #set
|
|
522
|
+
#
|
|
168
523
|
def init(keys, default = nil)
|
|
169
524
|
return set(keys, get(keys, default))
|
|
170
525
|
end
|
|
171
526
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
527
|
+
# Set value for key path in the configuration object.
|
|
528
|
+
#
|
|
529
|
+
# * *Parameters*
|
|
530
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
|
|
531
|
+
# - [ANY] *value* Value to set for key path
|
|
532
|
+
# - [Boolean] *delete_nil* Delete nil value (serves as an internal way to delete properties)
|
|
533
|
+
#
|
|
534
|
+
# * *Returns*
|
|
535
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
536
|
+
#
|
|
537
|
+
# * *Errors*
|
|
538
|
+
#
|
|
539
|
+
# * *Yields*
|
|
540
|
+
# - [Symbol] *key* Configuration key to modify
|
|
541
|
+
# - [ANY] *value* New value of configuration key
|
|
542
|
+
# - [ANY] *existing* Existing value being replaced for the configuration key
|
|
543
|
+
#
|
|
544
|
+
# See:
|
|
545
|
+
# - #modify
|
|
546
|
+
#
|
|
547
|
+
# See also:
|
|
548
|
+
# - #array
|
|
549
|
+
#
|
|
550
|
+
def set(keys, value, delete_nil = false, &code) # :yields: key, value, existing
|
|
551
|
+
modify(@properties, array(keys).flatten, value, delete_nil, &code)
|
|
176
552
|
return self
|
|
177
553
|
end
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
554
|
+
|
|
555
|
+
# Append a value for an array key path in the configuration object.
|
|
556
|
+
#
|
|
557
|
+
# * *Parameters*
|
|
558
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
|
|
559
|
+
# - [ANY] *value* Value to set for key path
|
|
560
|
+
#
|
|
561
|
+
# * *Returns*
|
|
562
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
563
|
+
#
|
|
564
|
+
# * *Errors*
|
|
565
|
+
#
|
|
566
|
+
# See:
|
|
567
|
+
# - #modify
|
|
568
|
+
#
|
|
569
|
+
# See also:
|
|
570
|
+
# - #array
|
|
571
|
+
#
|
|
572
|
+
def append(keys, value)
|
|
573
|
+
modify(@properties, array(keys).flatten, value, false) do |key, processed_value, existing|
|
|
574
|
+
if existing.is_a?(Array)
|
|
575
|
+
[ existing, processed_value ].flatten
|
|
576
|
+
else
|
|
577
|
+
[ processed_value ]
|
|
578
|
+
end
|
|
579
|
+
end
|
|
580
|
+
return self
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
# Prepend a value to an array key path in the configuration object.
|
|
584
|
+
#
|
|
585
|
+
# * *Parameters*
|
|
586
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to modify
|
|
587
|
+
# - [ANY] *value* Value to set for key path
|
|
588
|
+
# - [Boolean] *reverse* Whether or not to reverse any input value arrays given before prepending
|
|
589
|
+
#
|
|
590
|
+
# * *Returns*
|
|
591
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
592
|
+
#
|
|
593
|
+
# * *Errors*
|
|
594
|
+
#
|
|
595
|
+
# See:
|
|
596
|
+
# - #modify
|
|
597
|
+
#
|
|
598
|
+
# See also:
|
|
599
|
+
# - #array
|
|
600
|
+
#
|
|
601
|
+
def prepend(keys, value, reverse = false)
|
|
602
|
+
modify(@properties, array(keys).flatten, value, false) do |key, processed_value, existing|
|
|
603
|
+
processed_value = processed_value.reverse if reverse && processed_value.is_a?(Array)
|
|
604
|
+
|
|
605
|
+
if existing.is_a?(Array)
|
|
606
|
+
[ processed_value, existing ].flatten
|
|
607
|
+
else
|
|
608
|
+
[ processed_value ]
|
|
609
|
+
end
|
|
610
|
+
end
|
|
611
|
+
return self
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
# Set value for key in the configuration object.
|
|
615
|
+
#
|
|
616
|
+
# This method is really just to provide an easier interface compatible with
|
|
617
|
+
# Hash access for simpler configuration groups.
|
|
618
|
+
#
|
|
619
|
+
# * *Parameters*
|
|
620
|
+
# - [String, Symbol] *name* Key to fetch
|
|
621
|
+
# - [ANY] *value* Value to set for key
|
|
622
|
+
#
|
|
623
|
+
# * *Returns*
|
|
624
|
+
# - [Void] Return value thrown away
|
|
625
|
+
#
|
|
626
|
+
# * *Errors*
|
|
627
|
+
#
|
|
628
|
+
# See:
|
|
629
|
+
# - #set
|
|
630
|
+
#
|
|
181
631
|
def []=(name, value)
|
|
182
632
|
set(name, value)
|
|
183
633
|
end
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
634
|
+
|
|
635
|
+
# Delete key path from the configuration object.
|
|
636
|
+
#
|
|
637
|
+
# * *Parameters*
|
|
638
|
+
# - [Array<String, Symbol>, String, Symbol] *keys* Key path to remove
|
|
639
|
+
# - [ANY] *default* Default value to return if no existing value found
|
|
640
|
+
#
|
|
641
|
+
# * *Returns*
|
|
642
|
+
# - [ANY] Returns default or last value removed from configuration object
|
|
643
|
+
#
|
|
644
|
+
# * *Errors*
|
|
645
|
+
#
|
|
646
|
+
# See:
|
|
647
|
+
# - #modify
|
|
648
|
+
#
|
|
649
|
+
# See also:
|
|
650
|
+
# - #array
|
|
651
|
+
#
|
|
187
652
|
def delete(keys, default = nil)
|
|
188
653
|
existing = modify(@properties, array(keys).flatten, nil, true)
|
|
189
654
|
return existing[:value] unless existing[:value].nil?
|
|
190
655
|
return default
|
|
191
656
|
end
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
657
|
+
|
|
658
|
+
# Clear all properties from the configuration object.
|
|
659
|
+
#
|
|
660
|
+
# * *Parameters*
|
|
661
|
+
#
|
|
662
|
+
# * *Returns*
|
|
663
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
664
|
+
#
|
|
665
|
+
# * *Errors*
|
|
666
|
+
#
|
|
195
667
|
def clear
|
|
196
668
|
@properties = {}
|
|
197
669
|
return self
|
|
198
670
|
end
|
|
199
671
|
|
|
200
|
-
|
|
672
|
+
#*****************************************************************************
|
|
201
673
|
# Import / Export
|
|
202
|
-
|
|
674
|
+
|
|
675
|
+
# Base import method for the configuration object.
|
|
676
|
+
#
|
|
677
|
+
# This method is used to perform merge overrides of new property values and to
|
|
678
|
+
# set defaults if no properties currently exist.
|
|
679
|
+
#
|
|
680
|
+
# If properties are given as a string or symbol and the configuration object
|
|
681
|
+
# has a lookup method implemented (corl gem) then the properties will be
|
|
682
|
+
# dynamically looked up and imported.
|
|
683
|
+
#
|
|
684
|
+
# * *Parameters*
|
|
685
|
+
# - [String, Symbol, Array, Hash] *properties* Data to import
|
|
686
|
+
# - [Hash] *options* Import options
|
|
687
|
+
# - [Symbol] *:import_type* Type of import to perform; *:override* or *:default*
|
|
688
|
+
# - Options to Nucleon::Util::Data::merge
|
|
689
|
+
#
|
|
690
|
+
# * *Returns*
|
|
691
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
692
|
+
#
|
|
693
|
+
# * *Errors*
|
|
694
|
+
#
|
|
695
|
+
# See also:
|
|
696
|
+
# - ::new
|
|
697
|
+
# - #get
|
|
698
|
+
# - #set
|
|
699
|
+
# - #export
|
|
700
|
+
# - #symbol_map
|
|
701
|
+
# - Nucleon::Util::Data::merge
|
|
702
|
+
#
|
|
203
703
|
def import_base(properties, options = {})
|
|
204
|
-
config = Config.new(options, { :force => @force, :basic => @basic_merge }).set(:context, :hash)
|
|
704
|
+
config = Config.new(options, { :force => @force, :basic => @basic_merge }).set(:context, :hash)
|
|
205
705
|
import_type = config.get(:import_type, :override)
|
|
206
|
-
|
|
706
|
+
|
|
207
707
|
properties = properties.export if properties.is_a?(Nucleon::Config)
|
|
208
|
-
|
|
708
|
+
|
|
209
709
|
case properties
|
|
210
710
|
when Hash
|
|
211
711
|
data = [ @properties, symbol_map(properties.clone) ]
|
|
212
712
|
data = data.reverse if import_type != :override
|
|
213
|
-
|
|
713
|
+
|
|
214
714
|
@properties = Util::Data.merge(data, config)
|
|
215
|
-
|
|
715
|
+
|
|
216
716
|
when String, Symbol
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
717
|
+
if respond_to?(:lookup)
|
|
718
|
+
properties = self.class.lookup(properties.to_s, {}, config)
|
|
719
|
+
|
|
720
|
+
data = [ @properties, symbol_map(properties) ]
|
|
721
|
+
data = data.reverse if import_type != :override
|
|
722
|
+
|
|
723
|
+
@properties = Util::Data.merge(data, config)
|
|
724
|
+
end
|
|
725
|
+
|
|
224
726
|
when Array
|
|
225
727
|
properties.clone.each do |item|
|
|
226
728
|
import_base(item, config)
|
|
227
729
|
end
|
|
228
730
|
end
|
|
229
|
-
|
|
731
|
+
|
|
230
732
|
return self
|
|
231
733
|
end
|
|
232
734
|
protected :import_base
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
735
|
+
|
|
736
|
+
# Import new property values into the configuration object. (override)
|
|
737
|
+
#
|
|
738
|
+
# If properties are given as a string or symbol and the configuration object
|
|
739
|
+
# has a lookup method implemented (corl gem) then the properties will be
|
|
740
|
+
# dynamically looked up and imported.
|
|
741
|
+
#
|
|
742
|
+
# * *Parameters*
|
|
743
|
+
# - [String, Symbol, Array, Hash] *properties* Data to import
|
|
744
|
+
# - [Hash] *options* Import options
|
|
745
|
+
#
|
|
746
|
+
# * *Returns*
|
|
747
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
748
|
+
#
|
|
749
|
+
# * *Errors*
|
|
750
|
+
#
|
|
751
|
+
# See:
|
|
752
|
+
# - #import_base
|
|
753
|
+
#
|
|
236
754
|
def import(properties, options = {})
|
|
237
755
|
return import_base(properties, options)
|
|
238
756
|
end
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
757
|
+
|
|
758
|
+
# Set default property values in the configuration object if they don't exist.
|
|
759
|
+
#
|
|
760
|
+
# If defaults are given as a string or symbol and the configuration object
|
|
761
|
+
# has a lookup method implemented (corl gem) then the defaults will be
|
|
762
|
+
# dynamically looked up and set.
|
|
763
|
+
#
|
|
764
|
+
# * *Parameters*
|
|
765
|
+
# - [String, Symbol, Array, Hash] *defaults* Data to set as defaults
|
|
766
|
+
# - [Hash] *options* Import options
|
|
767
|
+
#
|
|
768
|
+
# * *Returns*
|
|
769
|
+
# - [Nucleon::Config] Returns reference to self for compound operations
|
|
770
|
+
#
|
|
771
|
+
# * *Errors*
|
|
772
|
+
#
|
|
773
|
+
# See:
|
|
774
|
+
# - #import_base
|
|
775
|
+
#
|
|
776
|
+
# See also:
|
|
777
|
+
# - ::new
|
|
778
|
+
# - #set
|
|
779
|
+
#
|
|
242
780
|
def defaults(defaults, options = {})
|
|
243
781
|
config = Config.new(options).set(:import_type, :default)
|
|
244
782
|
return import_base(defaults, config)
|
|
245
783
|
end
|
|
246
784
|
|
|
247
|
-
|
|
248
|
-
|
|
785
|
+
# Export properties into a regular hash object (cloned)
|
|
786
|
+
#
|
|
787
|
+
# * *Parameters*
|
|
788
|
+
#
|
|
789
|
+
# * *Returns*
|
|
790
|
+
# - [Hash] Returns a hash of all the configuration properties
|
|
791
|
+
#
|
|
792
|
+
# * *Errors*
|
|
793
|
+
#
|
|
249
794
|
def export
|
|
250
795
|
return @properties.clone
|
|
251
796
|
end
|
|
252
|
-
|
|
253
|
-
|
|
797
|
+
|
|
798
|
+
#*****************************************************************************
|
|
254
799
|
# Utilities
|
|
255
800
|
|
|
801
|
+
# Return hash as a symbol map.
|
|
802
|
+
#
|
|
803
|
+
# This method converts all hash keys to symbols. Nested hashes are
|
|
804
|
+
# recursively translated as well.
|
|
805
|
+
#
|
|
806
|
+
# This comes in really handy when performing operations across hashes in Ruby
|
|
807
|
+
# because of the distinction between symbols and strings.
|
|
808
|
+
#
|
|
809
|
+
# See:
|
|
810
|
+
# - Nucleon::Util::Data::symbol_map
|
|
811
|
+
#
|
|
256
812
|
def self.symbol_map(data)
|
|
257
813
|
return Util::Data.symbol_map(data)
|
|
258
814
|
end
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
815
|
+
|
|
816
|
+
# Return hash as a symbol map.
|
|
817
|
+
#
|
|
818
|
+
# See:
|
|
819
|
+
# - ::symbol_map
|
|
820
|
+
#
|
|
262
821
|
def symbol_map(data)
|
|
263
822
|
return self.class.symbol_map(data)
|
|
264
823
|
end
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
824
|
+
|
|
825
|
+
# Return hash as a string map.
|
|
826
|
+
#
|
|
827
|
+
# This method converts all hash keys to strings. Nested hashes are
|
|
828
|
+
# recursively translated as well.
|
|
829
|
+
#
|
|
830
|
+
# This comes in really handy when performing operations across hashes in Ruby
|
|
831
|
+
# because of the distinction between symbols and strings.
|
|
832
|
+
#
|
|
833
|
+
# See:
|
|
834
|
+
# - Nucleon::Util::Data::string_map
|
|
835
|
+
#
|
|
268
836
|
def self.string_map(data)
|
|
269
837
|
return Util::Data.string_map(data)
|
|
270
838
|
end
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
839
|
+
|
|
840
|
+
# Return hash as a string map.
|
|
841
|
+
#
|
|
842
|
+
# See:
|
|
843
|
+
# - ::string_map
|
|
844
|
+
#
|
|
274
845
|
def string_map(data)
|
|
275
846
|
return self.class.string_map(data)
|
|
276
847
|
end
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
848
|
+
|
|
849
|
+
#*****************************************************************************
|
|
850
|
+
|
|
851
|
+
# Run a defined filter on a data object.
|
|
852
|
+
#
|
|
853
|
+
# This method ensures that a given data object meets some criteria or else
|
|
854
|
+
# an empty value for that type is returned that matches the criteria.
|
|
855
|
+
#
|
|
856
|
+
# Currently implemented filters:
|
|
857
|
+
# 1. ::array Ensure result is an array (non arrays are converted)
|
|
858
|
+
# 2. ::hash Ensure result is a hash (non hashes are converted)
|
|
859
|
+
# 3. ::string Ensure result is a string (non strings are converted)
|
|
860
|
+
# 4. ::symbol Ensure result is a symbol (non symbols are converted)
|
|
861
|
+
# 5. ::test Ensure result is not empty (runs a boolean ::empty? check)
|
|
862
|
+
#
|
|
863
|
+
# See:
|
|
864
|
+
# - Nucleon::Util::Data::filter
|
|
865
|
+
#
|
|
280
866
|
def self.filter(data, method = false)
|
|
281
867
|
return Util::Data.filter(data, method)
|
|
282
868
|
end
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
869
|
+
|
|
870
|
+
# Run a defined filter on a data object.
|
|
871
|
+
#
|
|
872
|
+
# See:
|
|
873
|
+
# - ::filter
|
|
874
|
+
#
|
|
286
875
|
def filter(data, method = false)
|
|
287
876
|
return self.class.filter(data, method)
|
|
288
877
|
end
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
878
|
+
|
|
879
|
+
#*****************************************************************************
|
|
880
|
+
|
|
881
|
+
# Ensure a data object is an array.
|
|
882
|
+
#
|
|
883
|
+
# See:
|
|
884
|
+
# - Nucleon::Util::Data::array
|
|
885
|
+
#
|
|
292
886
|
def self.array(data, default = [], split_string = false)
|
|
293
887
|
return Util::Data.array(data, default, split_string)
|
|
294
888
|
end
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
889
|
+
|
|
890
|
+
# Ensure a data object is an array.
|
|
891
|
+
#
|
|
892
|
+
# See:
|
|
893
|
+
# - ::array
|
|
894
|
+
#
|
|
298
895
|
def array(data, default = [], split_string = false)
|
|
299
896
|
return self.class.array(data, default, split_string)
|
|
300
897
|
end
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
898
|
+
|
|
899
|
+
# Ensure a data object is a hash.
|
|
900
|
+
#
|
|
901
|
+
# See:
|
|
902
|
+
# - Nucleon::Util::Data::hash
|
|
903
|
+
#
|
|
304
904
|
def self.hash(data, default = {})
|
|
305
905
|
data = data.export if data.is_a?(Nucleon::Config)
|
|
306
906
|
return Util::Data.hash(data, default)
|
|
307
907
|
end
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
908
|
+
|
|
909
|
+
# Ensure a data object is a hash
|
|
910
|
+
#
|
|
911
|
+
# See:
|
|
912
|
+
# - ::hash
|
|
913
|
+
#
|
|
311
914
|
def hash(data, default = {})
|
|
312
915
|
return self.class.hash(data, default)
|
|
313
916
|
end
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
917
|
+
|
|
918
|
+
# Ensure a data object is a string.
|
|
919
|
+
#
|
|
920
|
+
# See:
|
|
921
|
+
# - Nucleon::Util::Data::string
|
|
922
|
+
#
|
|
317
923
|
def self.string(data, default = '')
|
|
318
924
|
return Util::Data.string(data, default)
|
|
319
925
|
end
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
926
|
+
|
|
927
|
+
# Ensure a data object is a string.
|
|
928
|
+
#
|
|
929
|
+
# See:
|
|
930
|
+
# - ::string
|
|
931
|
+
#
|
|
323
932
|
def string(data, default = '')
|
|
324
933
|
return self.class.string(data, default)
|
|
325
934
|
end
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
935
|
+
|
|
936
|
+
# Ensure a data object is a symbol.
|
|
937
|
+
#
|
|
938
|
+
# See:
|
|
939
|
+
# - Nucleon::Util::Data::symbol
|
|
940
|
+
#
|
|
329
941
|
def self.symbol(data, default = :undefined)
|
|
330
942
|
return Util::Data.symbol(data, default)
|
|
331
943
|
end
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
944
|
+
|
|
945
|
+
# Ensure a data object is a symbol.
|
|
946
|
+
#
|
|
947
|
+
# See:
|
|
948
|
+
# - ::symbol
|
|
949
|
+
#
|
|
335
950
|
def symbol(data, default = :undefined)
|
|
336
951
|
return self.class.symbol(data, default)
|
|
337
952
|
end
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
953
|
+
|
|
954
|
+
# Test a data object for emptiness and return boolean result.
|
|
955
|
+
#
|
|
956
|
+
# See:
|
|
957
|
+
# - Nucleon::Util::Data::test
|
|
958
|
+
#
|
|
341
959
|
def self.test(data)
|
|
342
960
|
return Util::Data.test(data)
|
|
343
961
|
end
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
962
|
+
|
|
963
|
+
# Test a data object for emptiness and return boolean result.
|
|
964
|
+
#
|
|
965
|
+
# See:
|
|
966
|
+
# - ::test
|
|
967
|
+
#
|
|
347
968
|
def test(data)
|
|
348
969
|
return self.class.test(data)
|
|
349
|
-
end
|
|
970
|
+
end
|
|
350
971
|
end
|
|
351
972
|
end
|