lib/foreplay.rb in foreplay-0.11.1 vs lib/foreplay.rb in foreplay-0.11.2
- old
+ new
@@ -1,10 +1,11 @@
-require 'foreplay/version'
-require 'foreplay/engine'
-require 'foreplay/launcher'
-
module Foreplay
+ autoload :VERSION, 'foreplay/version'
+ autoload :Engine, 'foreplay/engine'
+ autoload :Launcher, 'foreplay/launcher'
+ autoload :Setup, 'foreplay/setup'
+
DEFAULT_PORT = 50_000
PORT_GAP = 1_000
def log(message, options = {})
Foreplay::Engine::Logger.new(message, options)
@@ -25,12 +26,11 @@
# h1 = { x: { y: [4,5,6] }, z: [7,8,9] }
# h2 = { x: { y: [7,8,9] }, z: 'xyz' }
# h1.supermerge(h2)
# #=> {:x=>{:y=>[4, 5, 6, 7, 8, 9]}, :z=>[7, 8, 9, "xyz"]}
def supermerge(other_hash)
- fail 'supermerge only works if you pass a hash. '\
- "You passed a #{self.class} and a #{other_hash.class}." unless other_hash.is_a?(Hash)
+ fail "supermerge needs a Hash, not a #{other_hash.class}." unless other_hash.is_a?(Hash)
new_hash = deep_dup
other_hash.each_pair do |k, v|
tv = new_hash[k]
@@ -65,7 +65,24 @@
"\e[#{args.join(';')}m#{self}\e[0m"
end
def fake_erb
gsub(/(<%=\s+([^%]+)\s+%>)/) { |e| eval "_ = #{e.split[1]}" }
+ end
+
+ def escape_double_quotes
+ gsub('"', '\\"')
+ end
+
+ def remove_trailing_newline
+ gsub(/\n\z/, '')
+ end
+end
+
+require 'yaml'
+
+module YAML
+ # Escape string so it's safe for a YAML value
+ def self.escape(string)
+ /^---\n__: ([^\n]*)$/.match(Psych.dump('__' => string))[1]
end
end