garcun 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +197 -0
- data/.rspec +2 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +521 -0
- data/Rakefile +47 -0
- data/garcun.gemspec +83 -0
- data/lib/garcon.rb +290 -0
- data/lib/garcon/chef/chef_helpers.rb +343 -0
- data/lib/garcon/chef/coerce/coercer.rb +134 -0
- data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
- data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
- data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
- data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
- data/lib/garcon/chef/handler/devreporter.rb +127 -0
- data/lib/garcon/chef/log.rb +64 -0
- data/lib/garcon/chef/node.rb +100 -0
- data/lib/garcon/chef/provider/civilize.rb +209 -0
- data/lib/garcon/chef/provider/development.rb +159 -0
- data/lib/garcon/chef/provider/download.rb +420 -0
- data/lib/garcon/chef/provider/house_keeping.rb +265 -0
- data/lib/garcon/chef/provider/node_cache.rb +31 -0
- data/lib/garcon/chef/provider/partial.rb +183 -0
- data/lib/garcon/chef/provider/recovery.rb +80 -0
- data/lib/garcon/chef/provider/zip_file.rb +271 -0
- data/lib/garcon/chef/resource/attribute.rb +52 -0
- data/lib/garcon/chef/resource/base_dsl.rb +174 -0
- data/lib/garcon/chef/resource/blender.rb +140 -0
- data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
- data/lib/garcon/chef/resource/resource_name.rb +109 -0
- data/lib/garcon/chef/secret_bag.rb +204 -0
- data/lib/garcon/chef/validations.rb +76 -0
- data/lib/garcon/chef_inclusions.rb +151 -0
- data/lib/garcon/configuration.rb +138 -0
- data/lib/garcon/core_ext.rb +39 -0
- data/lib/garcon/core_ext/array.rb +27 -0
- data/lib/garcon/core_ext/binding.rb +64 -0
- data/lib/garcon/core_ext/boolean.rb +66 -0
- data/lib/garcon/core_ext/duration.rb +271 -0
- data/lib/garcon/core_ext/enumerable.rb +34 -0
- data/lib/garcon/core_ext/file.rb +127 -0
- data/lib/garcon/core_ext/filetest.rb +62 -0
- data/lib/garcon/core_ext/hash.rb +279 -0
- data/lib/garcon/core_ext/kernel.rb +159 -0
- data/lib/garcon/core_ext/lazy.rb +222 -0
- data/lib/garcon/core_ext/method_access.rb +243 -0
- data/lib/garcon/core_ext/module.rb +92 -0
- data/lib/garcon/core_ext/nil.rb +53 -0
- data/lib/garcon/core_ext/numeric.rb +44 -0
- data/lib/garcon/core_ext/object.rb +342 -0
- data/lib/garcon/core_ext/pathname.rb +152 -0
- data/lib/garcon/core_ext/process.rb +41 -0
- data/lib/garcon/core_ext/random.rb +497 -0
- data/lib/garcon/core_ext/string.rb +312 -0
- data/lib/garcon/core_ext/struct.rb +49 -0
- data/lib/garcon/core_ext/symbol.rb +170 -0
- data/lib/garcon/core_ext/time.rb +234 -0
- data/lib/garcon/exceptions.rb +101 -0
- data/lib/garcon/inflections.rb +237 -0
- data/lib/garcon/inflections/defaults.rb +79 -0
- data/lib/garcon/inflections/inflections.rb +182 -0
- data/lib/garcon/inflections/rules_collection.rb +37 -0
- data/lib/garcon/secret.rb +271 -0
- data/lib/garcon/stash/format.rb +114 -0
- data/lib/garcon/stash/journal.rb +226 -0
- data/lib/garcon/stash/queue.rb +83 -0
- data/lib/garcon/stash/serializer.rb +86 -0
- data/lib/garcon/stash/store.rb +435 -0
- data/lib/garcon/task.rb +31 -0
- data/lib/garcon/task/atomic.rb +151 -0
- data/lib/garcon/task/atomic_boolean.rb +127 -0
- data/lib/garcon/task/condition.rb +99 -0
- data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
- data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
- data/lib/garcon/task/count_down_latch.rb +92 -0
- data/lib/garcon/task/delay.rb +196 -0
- data/lib/garcon/task/dereferenceable.rb +144 -0
- data/lib/garcon/task/event.rb +119 -0
- data/lib/garcon/task/executor.rb +275 -0
- data/lib/garcon/task/executor_options.rb +59 -0
- data/lib/garcon/task/future.rb +107 -0
- data/lib/garcon/task/immediate_executor.rb +84 -0
- data/lib/garcon/task/ivar.rb +171 -0
- data/lib/garcon/task/lazy_reference.rb +74 -0
- data/lib/garcon/task/monotonic_time.rb +69 -0
- data/lib/garcon/task/obligation.rb +256 -0
- data/lib/garcon/task/observable.rb +101 -0
- data/lib/garcon/task/priority_queue.rb +234 -0
- data/lib/garcon/task/processor_count.rb +128 -0
- data/lib/garcon/task/read_write_lock.rb +304 -0
- data/lib/garcon/task/safe_task_executor.rb +58 -0
- data/lib/garcon/task/single_thread_executor.rb +97 -0
- data/lib/garcon/task/thread_pool/cached.rb +71 -0
- data/lib/garcon/task/thread_pool/executor.rb +294 -0
- data/lib/garcon/task/thread_pool/fixed.rb +61 -0
- data/lib/garcon/task/thread_pool/worker.rb +90 -0
- data/lib/garcon/task/timer.rb +44 -0
- data/lib/garcon/task/timer_set.rb +194 -0
- data/lib/garcon/task/timer_task.rb +377 -0
- data/lib/garcon/task/waitable_list.rb +58 -0
- data/lib/garcon/utility/ansi.rb +199 -0
- data/lib/garcon/utility/at_random.rb +77 -0
- data/lib/garcon/utility/crypto.rb +292 -0
- data/lib/garcon/utility/equalizer.rb +146 -0
- data/lib/garcon/utility/faker/extensions/array.rb +22 -0
- data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
- data/lib/garcon/utility/faker/faker.rb +164 -0
- data/lib/garcon/utility/faker/faker/company.rb +17 -0
- data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
- data/lib/garcon/utility/faker/faker/version.rb +3 -0
- data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
- data/lib/garcon/utility/faker/locales/en.yml +21 -0
- data/lib/garcon/utility/file_helper.rb +170 -0
- data/lib/garcon/utility/hookers.rb +178 -0
- data/lib/garcon/utility/interpolation.rb +90 -0
- data/lib/garcon/utility/memstash.rb +364 -0
- data/lib/garcon/utility/misc.rb +54 -0
- data/lib/garcon/utility/msg_from_god.rb +62 -0
- data/lib/garcon/utility/retry.rb +238 -0
- data/lib/garcon/utility/timeout.rb +58 -0
- data/lib/garcon/utility/uber/builder.rb +91 -0
- data/lib/garcon/utility/uber/callable.rb +7 -0
- data/lib/garcon/utility/uber/delegates.rb +13 -0
- data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
- data/lib/garcon/utility/uber/options.rb +101 -0
- data/lib/garcon/utility/uber/uber_version.rb +3 -0
- data/lib/garcon/utility/uber/version.rb +33 -0
- data/lib/garcon/utility/url_helper.rb +100 -0
- data/lib/garcon/utils.rb +29 -0
- data/lib/garcon/version.rb +62 -0
- data/lib/garcun.rb +24 -0
- metadata +680 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
en:
|
|
2
|
+
faker:
|
|
3
|
+
separator: ' & '
|
|
4
|
+
company:
|
|
5
|
+
# Buzzword wordlist from http://www.1728.com/buzzword.htm
|
|
6
|
+
buzzwords:
|
|
7
|
+
- ["Adaptive", "Advanced", "Ameliorated", "Assimilated", "Automated", "Balanced", "Business-focused", "Centralized", "Cloned", "Compatible", "Configurable", "Cross-group", "Cross-platform", "Customer-focused", "Customizable", "Decentralized", "De-engineered", "Devolved", "Digitized", "Distributed", "Diverse", "Down-sized", "Enhanced", "Enterprise-wide", "Ergonomic", "Exclusive", "Expanded", "Extended", "Face to face", "Focused", "Front-line", "Fully-configurable", "Function-based", "Fundamental", "Future-proofed", "Grass-roots", "Horizontal", "Implemented", "Innovative", "Integrated", "Intuitive", "Inverse", "Managed", "Mandatory", "Monitored", "Multi-channelled", "Multi-lateral", "Multi-layered", "Multi-tiered", "Networked", "Object-based", "Open-architected", "Open-source", "Operative", "Optimized", "Optional", "Organic", "Organized", "Persevering", "Persistent", "Phased", "Polarised", "Pre-emptive", "Proactive", "Profit-focused", "Profound", "Programmable", "Progressive", "Public-key", "Quality-focused", "Reactive", "Realigned", "Re-contextualized", "Re-engineered", "Reduced", "Reverse-engineered", "Right-sized", "Robust", "Seamless", "Secured", "Self-enabling", "Sharable", "Stand-alone", "Streamlined", "Switchable", "Synchronised", "Synergistic", "Synergized", "Team-oriented", "Total", "Triple-buffered", "Universal", "Up-sized", "Upgradable", "User-centric", "User-friendly", "Versatile", "Virtual", "Visionary", "Vision-oriented"]
|
|
8
|
+
- ["24 hour", "24/7", "3rd generation", "4th generation", "5th generation", "6th generation", "actuating", "analyzing", "asymmetric", "asynchronous", "attitude-oriented", "background", "bandwidth-monitored", "bi-directional", "bifurcated", "bottom-line", "clear-thinking", "client-driven", "client-server", "coherent", "cohesive", "composite", "context-sensitive", "contextually-based", "content-based", "dedicated", "demand-driven", "didactic", "directional", "discrete", "disintermediate", "dynamic", "eco-centric", "empowering", "encompassing", "even-keeled", "executive", "explicit", "exuding", "fault-tolerant", "foreground", "fresh-thinking", "full-range", "global", "grid-enabled", "heuristic", "high-level", "holistic", "homogeneous", "human-resource", "hybrid", "impactful", "incremental", "intangible", "interactive", "intermediate", "leading edge", "local", "logistical", "maximized", "methodical", "mission-critical", "mobile", "modular", "motivating", "multimedia", "multi-state", "multi-tasking", "national", "needs-based", "neutral", "next generation", "non-volatile", "object-oriented", "optimal", "optimizing", "radical", "real-time", "reciprocal", "regional", "responsive", "scalable", "secondary", "solution-oriented", "stable", "static", "systematic", "systemic", "system-worthy", "tangible", "tertiary", "transitional", "uniform", "upward-trending", "user-facing", "value-added", "web-enabled", "well-modulated", "zero administration", "zero defect", "zero tolerance"]
|
|
9
|
+
- ["ability", "access", "adapter", "algorithm", "alliance", "analyzer", "application", "approach", "architecture", "archive", "artificial intelligence", "array", "attitude", "benchmark", "budgetary management", "capability", "capacity", "challenge", "circuit", "collaboration", "complexity", "concept", "conglomeration", "contingency", "core", "customer loyalty", "database", "data-warehouse", "definition", "emulation", "encoding", "encryption", "extranet", "firmware", "flexibility", "focus group", "forecast", "frame", "framework", "function", "functionalities", "Graphic Interface", "groupware", "Graphical User Interface", "hardware", "help-desk", "hierarchy", "hub", "implementation", "info-mediaries", "infrastructure", "initiative", "installation", "instruction set", "interface", "internet solution", "intranet", "knowledge user", "knowledge base", "local area network", "leverage", "matrices", "matrix", "methodology", "middleware", "migration", "model", "moderator", "monitoring", "moratorium", "neural-net", "open architecture", "open system", "orchestration", "paradigm", "parallelism", "policy", "portal", "pricing structure", "process improvement", "product", "productivity", "project", "projection", "protocol", "secured line", "service-desk", "software", "solution", "standardization", "strategy", "structure", "success", "superstructure", "support", "synergy", "system engine", "task-force", "throughput", "time-frame", "toolset", "utilisation", "website", "workforce"]
|
|
10
|
+
# BS wordlist from http://dack.com/web/bullshit.html
|
|
11
|
+
bs:
|
|
12
|
+
- ["implement", "utilize", "integrate", "streamline", "optimize", "evolve", "transform", "embrace", "enable", "orchestrate", "leverage", "reinvent", "aggregate", "architect", "enhance", "incentivize", "morph", "empower", "envisioneer", "monetize", "harness", "facilitate", "seize", "disintermediate", "synergize", "strategize", "deploy", "brand", "grow", "target", "syndicate", "synthesize", "deliver", "mesh", "incubate", "engage", "maximize", "benchmark", "expedite", "reintermediate", "whiteboard", "visualize", "repurpose", "innovate", "scale", "unleash", "drive", "extend", "engineer", "revolutionize", "generate", "exploit", "transition", "e-enable", "iterate", "cultivate", "matrix", "productize", "redefine", "recontextualize"]
|
|
13
|
+
- ["clicks-and-mortar", "value-added", "vertical", "proactive", "robust", "revolutionary", "scalable", "leading-edge", "innovative", "intuitive", "strategic", "e-business", "mission-critical", "sticky", "one-to-one", "24/7", "end-to-end", "global", "B2B", "B2C", "granular", "frictionless", "virtual", "viral", "dynamic", "24/365", "best-of-breed", "killer", "magnetic", "bleeding-edge", "web-enabled", "interactive", "dot-com", "sexy", "back-end", "real-time", "efficient", "front-end", "distributed", "seamless", "extensible", "turn-key", "world-class", "open-source", "cross-platform", "cross-media", "synergistic", "bricks-and-clicks", "out-of-the-box", "enterprise", "integrated", "impactful", "wireless", "transparent", "next-generation", "cutting-edge", "user-centric", "visionary", "customized", "ubiquitous", "plug-and-play", "collaborative", "compelling", "holistic", "rich"]
|
|
14
|
+
- ["synergies", "web-readiness", "paradigms", "markets", "partnerships", "infrastructures", "platforms", "initiatives", "channels", "eyeballs", "communities", "ROI", "solutions", "e-tailers", "e-services", "action-items", "portals", "niches", "technologies", "content", "vortals", "supply-chains", "convergence", "relationships", "architectures", "interfaces", "e-markets", "e-commerce", "systems", "bandwidth", "infomediaries", "models", "mindshare", "deliverables", "users", "schemas", "networks", "applications", "metrics", "e-business", "functionalities", "experiences", "web services", "methodologies"]
|
|
15
|
+
|
|
16
|
+
hacker:
|
|
17
|
+
abbreviation: [TCP,HTTP,SDD,RAM,GB,CSS,SSL,AGP,SQL,FTP,PCI,AI,ADP,RSS,XML,EXE,COM,HDD,THX,SMTP,SMS,USB,PNG,SAS,IB,SCSI,JSON,XSS,JBOD]
|
|
18
|
+
adjective: [auxiliary,primary,back-end,digital,open-source,virtual,cross-platform,redundant,online,haptic,multi-byte,bluetooth,wireless,1080p,neural, optical,solid state,mobile]
|
|
19
|
+
noun: [driver,protocol,bandwidth,panel,microchip,program,port,card,array, interface,system,sensor,firewall,hard drive,pixel,alarm,feed,monitor,application,transmitter,bus,circuit,capacitor,matrix]
|
|
20
|
+
verb: [back up,bypass,hack,override,compress,copy,navigate,index,connect,generate,quantify,calculate,synthesize,input,transmit,program,reboot,parse]
|
|
21
|
+
ingverb: [backing up,bypassing,hacking,overriding,compressing,copying, navigating,indexing,connecting,generating,quantifying,calculating, synthesizing,transmitting,programming,parsing]
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
module Garcon
|
|
21
|
+
# Class methods that are added when you include Garcon
|
|
22
|
+
#
|
|
23
|
+
module FileHelper
|
|
24
|
+
# Methods are also available as module-level methods as well as a mixin.
|
|
25
|
+
extend self
|
|
26
|
+
|
|
27
|
+
# Checks in PATH returns true if the command is found.
|
|
28
|
+
#
|
|
29
|
+
# @param [String] command
|
|
30
|
+
# The name of the command to look for.
|
|
31
|
+
#
|
|
32
|
+
# @return [Boolean]
|
|
33
|
+
# True if the command is found in the path.
|
|
34
|
+
#
|
|
35
|
+
def command_in_path?(command)
|
|
36
|
+
found = ENV['PATH'].split(File::PATH_SEPARATOR).map do |p|
|
|
37
|
+
File.exist?(File.join(p, command))
|
|
38
|
+
end
|
|
39
|
+
found.include?(true)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Looks for the first occurrence of program within path.
|
|
43
|
+
#
|
|
44
|
+
# @param [String] cmd
|
|
45
|
+
# The name of the command to find.
|
|
46
|
+
#
|
|
47
|
+
# @param [String] path
|
|
48
|
+
# The path to search for the command.
|
|
49
|
+
#
|
|
50
|
+
# @return [String, NilClass]
|
|
51
|
+
#
|
|
52
|
+
# @api public
|
|
53
|
+
def which(prog, path = ENV['PATH'])
|
|
54
|
+
path.split(File::PATH_SEPARATOR).each do |dir|
|
|
55
|
+
file = File.join(dir, prog)
|
|
56
|
+
return file if File.executable?(file) && !File.directory?(file)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# In block form, yields each program within path. In non-block form,
|
|
63
|
+
# returns an array of each program within path. Returns nil if not found
|
|
64
|
+
# found.
|
|
65
|
+
#
|
|
66
|
+
# @example
|
|
67
|
+
# whereis('ruby')
|
|
68
|
+
# # => [
|
|
69
|
+
# [0] "/opt/chefdk/embedded/bin/ruby",
|
|
70
|
+
# [1] "/usr/bin/ruby",
|
|
71
|
+
# [2] "/Users/sharding/.rvm/rubies/ruby-2.2.0/bin/ruby",
|
|
72
|
+
# [3] "/usr/bin/ruby"
|
|
73
|
+
# ]
|
|
74
|
+
#
|
|
75
|
+
# @param [String] cmd
|
|
76
|
+
# The name of the command to find.
|
|
77
|
+
#
|
|
78
|
+
# @param [String] path
|
|
79
|
+
# The path to search for the command.
|
|
80
|
+
#
|
|
81
|
+
# @return [String, Array, NilClass]
|
|
82
|
+
#
|
|
83
|
+
# @api public
|
|
84
|
+
def whereis(prog, path = ENV['PATH'])
|
|
85
|
+
dirs = []
|
|
86
|
+
path.split(File::PATH_SEPARATOR).each do |dir|
|
|
87
|
+
f = File.join(dir,prog)
|
|
88
|
+
if File.executable?(f) && !File.directory?(f)
|
|
89
|
+
if block_given?
|
|
90
|
+
yield f
|
|
91
|
+
else
|
|
92
|
+
dirs << f
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
dirs.empty? ? nil : dirs
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Get a recusive list of files inside a path.
|
|
101
|
+
#
|
|
102
|
+
# @param [String] path
|
|
103
|
+
# some path string or Pathname
|
|
104
|
+
# @param [Block] ignore
|
|
105
|
+
# a proc/block that returns true if a given path should be ignored, if a
|
|
106
|
+
# path is ignored, nothing below it will be searched either.
|
|
107
|
+
#
|
|
108
|
+
# @return [Array<Pathname>]
|
|
109
|
+
# array of Pathnames for each file (no directories)
|
|
110
|
+
#
|
|
111
|
+
def all_files_under(path, &ignore)
|
|
112
|
+
path = Pathname(path)
|
|
113
|
+
|
|
114
|
+
if path.directory?
|
|
115
|
+
path.children.flat_map do |child|
|
|
116
|
+
all_files_under(child, &ignore)
|
|
117
|
+
end.compact
|
|
118
|
+
elsif path.file?
|
|
119
|
+
if block_given? && ignore.call(path)
|
|
120
|
+
[]
|
|
121
|
+
else
|
|
122
|
+
[path]
|
|
123
|
+
end
|
|
124
|
+
else
|
|
125
|
+
[]
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Takes an object, which can be a literal string or a string containing
|
|
130
|
+
# glob expressions, or a regexp, or a proc, or anything else that responds
|
|
131
|
+
# to #match or #call, and returns whether or not the given path matches
|
|
132
|
+
# that matcher.
|
|
133
|
+
#
|
|
134
|
+
# @param [String, #match, #call] matcher
|
|
135
|
+
# a matcher String, RegExp, Proc, etc.
|
|
136
|
+
#
|
|
137
|
+
# @param [String] path
|
|
138
|
+
# a path as a string
|
|
139
|
+
#
|
|
140
|
+
# @return [Boolean]
|
|
141
|
+
# whether the path matches the matcher
|
|
142
|
+
#
|
|
143
|
+
def path_match(matcher, path)
|
|
144
|
+
case
|
|
145
|
+
when matcher.is_a?(String)
|
|
146
|
+
if matcher.include? '*'
|
|
147
|
+
File.fnmatch(matcher, path)
|
|
148
|
+
else
|
|
149
|
+
path == matcher
|
|
150
|
+
end
|
|
151
|
+
when matcher.respond_to?(:match)
|
|
152
|
+
!matcher.match(path).nil?
|
|
153
|
+
when matcher.respond_to?(:call)
|
|
154
|
+
matcher.call(path)
|
|
155
|
+
else
|
|
156
|
+
File.fnmatch(matcher.to_s, path)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Normalize a path to not include a leading slash
|
|
161
|
+
#
|
|
162
|
+
# @param [String] path
|
|
163
|
+
#
|
|
164
|
+
# @return [String]
|
|
165
|
+
#
|
|
166
|
+
def normalize_path(path)
|
|
167
|
+
path.sub(%r{^/}, '').tr('', '')
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
require_relative 'uber/options'
|
|
21
|
+
require_relative 'uber/inheritable_attr'
|
|
22
|
+
|
|
23
|
+
# No not that kind! callback hooks.
|
|
24
|
+
#
|
|
25
|
+
module Garcon
|
|
26
|
+
module Hookers
|
|
27
|
+
module ClassMethods
|
|
28
|
+
def define_hookers(*names)
|
|
29
|
+
options = extract_options!(names)
|
|
30
|
+
names.each { |name| setup_hooker(name, options) }
|
|
31
|
+
end
|
|
32
|
+
alias_method :define_hooker, :define_hookers
|
|
33
|
+
|
|
34
|
+
def run_hooker(name, *args)
|
|
35
|
+
run_hooker_for(name, self, *args)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def run_hooker_for(name, scope, *args)
|
|
39
|
+
_hookers[name].run(scope, *args)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def callbacks_for_hooker(name)
|
|
43
|
+
_hookers[name]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
47
|
+
|
|
48
|
+
def setup_hooker(name, options)
|
|
49
|
+
_hookers[name] = Hooker.new(options)
|
|
50
|
+
define_hooker_writer(name)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def define_hooker_writer(name)
|
|
54
|
+
instance_eval(*hooker_writer_args(name))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def hooker_writer_args(name)
|
|
58
|
+
str = <<-RUBY_EVAL
|
|
59
|
+
def #{name}(method=nil, &block)
|
|
60
|
+
_hookers[:#{name}] << (block || method)
|
|
61
|
+
end
|
|
62
|
+
RUBY_EVAL
|
|
63
|
+
|
|
64
|
+
[str, __FILE__, __LINE__ + 1]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def extract_options!(args)
|
|
68
|
+
args.last.is_a?(Hash) ? args.pop : {}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def included(descendant)
|
|
72
|
+
descendant.class_eval do
|
|
73
|
+
extend Uber::InheritableAttr
|
|
74
|
+
extend ClassMethods
|
|
75
|
+
inheritable_attr :_hookers
|
|
76
|
+
self._hookers = BunchOfHookers.new
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
extend ClassMethods
|
|
82
|
+
|
|
83
|
+
def run_hooker(name, *args)
|
|
84
|
+
self.class.run_hooker_for(name, self, *args)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class BunchOfHookers < Hash
|
|
88
|
+
def [](name)
|
|
89
|
+
super(name.to_sym)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def []=(name, values)
|
|
93
|
+
super(name.to_sym, values)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def clone
|
|
97
|
+
super.tap do |cloned|
|
|
98
|
+
each { |name, callbacks| cloned[name] = callbacks.clone }
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class Hooker < Array
|
|
104
|
+
def initialize(options)
|
|
105
|
+
super()
|
|
106
|
+
@options = options
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def run(scope, *args)
|
|
110
|
+
inject(Results.new) do |results, callback|
|
|
111
|
+
executed = execute_callback(scope, callback, *args)
|
|
112
|
+
|
|
113
|
+
return results.halted! unless continue_execution?(executed)
|
|
114
|
+
results << executed
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def <<(callback)
|
|
119
|
+
super Uber::Options::Value.new(callback, dynamic: true)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
123
|
+
|
|
124
|
+
def execute_callback(scope, callback, *args)
|
|
125
|
+
callback.evaluate(scope, *args)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def continue_execution?(result)
|
|
129
|
+
@options[:halts_on_falsey] ? result : true
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
class Results < Array
|
|
133
|
+
def initialize(*)
|
|
134
|
+
super
|
|
135
|
+
@halted = false
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def halted!
|
|
139
|
+
@halted = true
|
|
140
|
+
self
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def halted?
|
|
144
|
+
@halted
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def not_halted?
|
|
148
|
+
not @halted
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
module InstanceHookers
|
|
154
|
+
include ClassMethods
|
|
155
|
+
|
|
156
|
+
def run_hooker(name, *args)
|
|
157
|
+
run_hooker_for(name, self, *args)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
161
|
+
|
|
162
|
+
def _hookers
|
|
163
|
+
@_hookers ||= self.class._hookers.clone
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
module ClassMethods
|
|
167
|
+
def define_hooker_writer(name)
|
|
168
|
+
super
|
|
169
|
+
class_eval(*hooker_writer_args(name))
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def self.included(descendant)
|
|
174
|
+
descendant.extend(ClassMethods)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
module Garcon
|
|
21
|
+
module Interpolation
|
|
22
|
+
# Methods are also available as module-level methods as well as a mixin.
|
|
23
|
+
extend self
|
|
24
|
+
|
|
25
|
+
# Interpolate provides a means of externally using Ruby string
|
|
26
|
+
# interpolation mechinism.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# node[:ldap][:basedir] = '/opt'
|
|
30
|
+
# node[:ldap][:homedir] = '%{basedir}/openldap/slap/happy'
|
|
31
|
+
#
|
|
32
|
+
# interpolate(node[:ldap])[:homedir] # => "/opt/openldap/slap/happy"
|
|
33
|
+
#
|
|
34
|
+
# @param [String] item
|
|
35
|
+
# The string to interpolate.
|
|
36
|
+
#
|
|
37
|
+
# @param [String, Hash] parent
|
|
38
|
+
# The string used for substitution.
|
|
39
|
+
#
|
|
40
|
+
# @return [String]
|
|
41
|
+
# The interpolated string.
|
|
42
|
+
#
|
|
43
|
+
# @api public
|
|
44
|
+
def interpolate(item = self, parent = nil)
|
|
45
|
+
item = render item, parent
|
|
46
|
+
item.is_a?(Hash) ? ::Mash.new(item) : item
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
50
|
+
|
|
51
|
+
# Return a symbol if key is a symbol using duck quacking.
|
|
52
|
+
#
|
|
53
|
+
# @param [Object] key
|
|
54
|
+
# The object to duck quack for a :to_sym method.
|
|
55
|
+
#
|
|
56
|
+
# @return [Boolean]
|
|
57
|
+
# True if object reponds to :to_sym quack duck, else false.
|
|
58
|
+
#
|
|
59
|
+
# @api private
|
|
60
|
+
def sym(key)
|
|
61
|
+
key.respond_to?(:to_sym) ? key.to_sym : key
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Provides recursive interpolation of node objects, using standard
|
|
65
|
+
# string interpolation methods.
|
|
66
|
+
#
|
|
67
|
+
# @param [String] item
|
|
68
|
+
# The string to interpolate.
|
|
69
|
+
#
|
|
70
|
+
# @param [String, Hash] parent
|
|
71
|
+
# The string used for substitution.
|
|
72
|
+
#
|
|
73
|
+
# @return [String]
|
|
74
|
+
#
|
|
75
|
+
# @api private
|
|
76
|
+
def render(item, parent = nil)
|
|
77
|
+
item = item.to_hash if item.respond_to?(:to_hash)
|
|
78
|
+
if item.is_a?(Hash)
|
|
79
|
+
item = item.inject({}) { |memo, (k,v)| memo[sym(k)] = v; memo }
|
|
80
|
+
item.inject({}) {|memo, (k,v)| memo[sym(k)] = render(v, item); memo}
|
|
81
|
+
elsif item.is_a?(Array)
|
|
82
|
+
item.map { |i| render(i, parent) }
|
|
83
|
+
elsif item.is_a?(String)
|
|
84
|
+
item % parent rescue item
|
|
85
|
+
else
|
|
86
|
+
item
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|