1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
require "guard/config"
fail "Deprecations disabled (strict mode)" if Guard::Config.new.strict?
require "forwardable"
require "guard/ui"
require "guard/internals/session"
require "guard/internals/state"
require "guard/guardfile/evaluator"
module Guard
# @deprecated Every method in this module is deprecated
module Deprecated
module Guard
def self.add_deprecated(klass)
klass.send(:extend, ClassMethods)
end
module ClassMethods
MORE_INFO_ON_UPGRADING_TO_GUARD_2 = <<-EOS.gsub(/^\s*/, "")
For more information on how to upgrade for Guard 2.0, please head
over to: https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0%s
EOS
# @deprecated Use `Guard.plugins(filter)` instead.
#
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
# upgrade for Guard 2.0
#
GUARDS = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.0 'Guard.guards(filter)' is deprecated.
Please use 'Guard.plugins(filter)' instead.
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % '#deprecated-methods'}
EOS
def guards(filter = nil)
::Guard::UI.deprecation(GUARDS)
::Guard.state.session.plugins.all(filter)
end
# @deprecated Use `Guard.add_plugin(name, options = {})` instead.
#
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
# upgrade for Guard 2.0
#
ADD_GUARD = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.0 'Guard.add_guard(name, options = {})' is
deprecated.
Please use 'Guard.add_plugin(name, options = {})' instead.
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % '#deprecated-methods'}
EOS
def add_guard(*args)
::Guard::UI.deprecation(ADD_GUARD)
add_plugin(*args)
end
# @deprecated Use
# `Guard::PluginUtil.new(name).plugin_class(fail_gracefully:
# fail_gracefully)` instead.
#
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
# upgrade for Guard 2.0
#
GET_GUARD_CLASS = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.0 'Guard.get_guard_class(name, fail_gracefully
= false)' is deprecated and is now always on.
Please use 'Guard::PluginUtil.new(name).plugin_class(fail_gracefully:
fail_gracefully)' instead.
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % '#deprecated-methods'}
EOS
def get_guard_class(name, fail_gracefully = false)
UI.deprecation(GET_GUARD_CLASS)
PluginUtil.new(name).plugin_class(fail_gracefully: fail_gracefully)
end
# @deprecated Use `Guard::PluginUtil.new(name).plugin_location` instead.
#
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
# upgrade for Guard 2.0
#
LOCATE_GUARD = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.0 'Guard.locate_guard(name)' is deprecated.
Please use 'Guard::PluginUtil.new(name).plugin_location' instead.
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % '#deprecated-methods'}
EOS
def locate_guard(name)
UI.deprecation(LOCATE_GUARD)
PluginUtil.new(name).plugin_location
end
# @deprecated Use `Guard::PluginUtil.plugin_names` instead.
#
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
# upgrade for Guard 2.0
#
# Deprecator message for the `Guard.guard_gem_names` method
GUARD_GEM_NAMES = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.0 'Guard.guard_gem_names' is deprecated.
Please use 'Guard::PluginUtil.plugin_names' instead.
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % '#deprecated-methods'}
EOS
def guard_gem_names
UI.deprecation(GUARD_GEM_NAMES)
PluginUtil.plugin_names
end
RUNNING = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.7.1 it was discovered that Guard.running was
never initialized or used internally.
EOS
def running
UI.deprecation(RUNNING)
nil
end
LOCK = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.7.1 it was discovered that this accessor was
never initialized or used internally.
EOS
def lock
UI.deprecation(LOCK)
end
LISTENER_ASSIGN = <<-EOS.gsub(/^\s*/, "")
listener= should not be used
EOS
def listener=(_)
UI.deprecation(LISTENER_ASSIGN)
::Guard.listener
end
EVALUATOR = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.8.2 this method shouldn't be used
EOS
def evaluator
UI.deprecation(EVALUATOR)
options = ::Guard.state.session.evaluator_options
::Guard::Guardfile::Evaluator.new(options)
end
RESET_EVALUATOR = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.8.2 this method shouldn't be used
EOS
def reset_evaluator(_options)
UI.deprecation(RESET_EVALUATOR)
end
RUNNER = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.8.2 this method shouldn't be used
EOS
def runner
UI.deprecation(RUNNER)
::Guard::Runner.new
end
EVALUATE_GUARDFILE = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.8.2 this method shouldn't be used
EOS
def evaluate_guardfile
UI.deprecation(EVALUATE_GUARDFILE)
options = ::Guard.state.session.evaluator_options
evaluator = ::Guard::Guardfile::Evaluator.new(options)
evaluator.evaluate
msg = "No plugins found in Guardfile, please add at least one."
::Guard::UI.error msg if _pluginless_guardfile?
end
OPTIONS = <<-EOS.gsub(/^\s*/, "")
Starting with Guard 2.9.0 Guard.options is deprecated and ideally you
should be able to set specific options through an API or a DSL
method. Feel free to add feature requests if there's something
missing.
EOS
def options
UI.deprecation(OPTIONS)
Class.new(Hash) do
def initialize
super(to_hash)
end
def to_hash
session = ::Guard.state.session
{
clear: session.clearing?,
debug: session.debug?,
watchdir: Array(session.watchdirs).map(&:to_s),
notify: session.notify_options[:notify],
no_interactions: (session.interactor_name == :sleep)
}
end
extend Forwardable
delegate [:to_a, :keys] => :to_hash
delegate [:include?] => :keys
def fetch(key, *args)
hash = to_hash
verify_key!(hash, key)
hash.fetch(key, *args)
end
def []=(key, value)
case key
when :clear
::Guard.state.session.clearing(value)
else
msg = "Oops! Guard.option[%s]= is unhandled or unsupported." \
"Please file an issue if you rely on this option working."
fail NotImplementedError, format(msg, key)
end
end
private
def verify_key!(hash, key)
return if hash.key?(key)
msg = "Oops! Guard.option[%s] is unhandled or unsupported." \
"Please file an issue if you rely on this option working."
fail NotImplementedError, format(msg, key)
end
end.new
end
ADD_GROUP = <<-EOS.gsub(/^\s*/, "")
add_group is deprecated since 2.10.0 in favor of
Guard.state.session.groups.add
EOS
def add_group(name, options = {})
UI.deprecation(ADD_GROUP)
::Guard.state.session.groups.add(name, options)
end
ADD_PLUGIN = <<-EOS.gsub(/^\s*/, "")
add_plugin is deprecated since 2.10.0 in favor of
Guard.state.session.plugins.add
EOS
def add_plugin(name, options = {})
UI.deprecation(ADD_PLUGIN)
::Guard.state.session.plugins.add(name, options)
end
GROUP = <<-EOS.gsub(/^\s*/, "")
group is deprecated since 2.10.0 in favor of
Guard.state.session.group.add(filter).first
EOS
def group(filter)
UI.deprecation(GROUP)
::Guard.state.session.groups.all(filter).first
end
PLUGIN = <<-EOS.gsub(/^\s*/, "")
plugin is deprecated since 2.10.0 in favor of
Guard.state.session.group.add(filter).first
EOS
def plugin(filter)
UI.deprecation(PLUGIN)
::Guard.state.session.plugins.all(filter).first
end
GROUPS = <<-EOS.gsub(/^\s*/, "")
group is deprecated since 2.10.0 in favor of
Guard.state.session.groups.all(filter)
EOS
def groups(filter)
UI.deprecation(GROUPS)
::Guard.state.session.groups.all(filter)
end
PLUGINS = <<-EOS.gsub(/^\s*/, "")
plugins is deprecated since 2.10.0 in favor of
Guard.state.session.plugins.all(filter)
EOS
def plugins(filter)
UI.deprecation(PLUGINS)
::Guard.state.session.plugins.all(filter)
end
SCOPE = <<-EOS.gsub(/^\s*/, "")
scope is deprecated since 2.10.0 in favor of
Guard.state.scope.to_hash
EOS
def scope
UI.deprecation(SCOPE)
::Guard.state.scope.to_hash
end
SCOPE_ASSIGN = <<-EOS.gsub(/^\s*/, "")
scope= is deprecated since 2.10.0 in favor of
Guard.state.scope.to_hash
EOS
def scope=(scope)
UI.deprecation(SCOPE_ASSIGN)
::Guard.state.scope.from_interactor(scope)
end
end
end
end
end
|