Permalink
Browse files

Merge branch 'try'

  • Loading branch information...
2 parents a17a651 + 4440c87 commit 155f2d4201359a8a6a7a007c89690253670c77dd @benhoskings committed Mar 3, 2017
View
2 TODO
@@ -13,8 +13,6 @@ TODO
https://github.com/benhoskings/babushka/issues/197
https://github.com/benhoskings/babushka/issues/251
-* Remove Object#try and the associated reliance on nil.
-
KNOWN ISSUES
------------
View
@@ -38,7 +38,7 @@ class Cmdline
opt '-t', '--templates', "List templates instead of deps"
}.run {|cmd|
Base.sources.local_only {
- Helpers.generate_list_for(cmd.opts[:templates] ? :templates : :deps, cmd.argv.first)
+ Helpers.generate_list_for(cmd.opts[:templates] ? :templates : :deps, (cmd.argv.first || ""))
}
}
@@ -55,7 +55,7 @@ def self.github_autosource_regex
def self.generate_list_for to_list, filter_str
context = to_list == :deps ? Base.program_name : ':template =>'
- match_str = filter_str.try(:downcase)
+ match_str = filter_str.downcase
Base.sources.all_present.each {|source|
source.load!
}.map {|source|
@@ -5,11 +5,15 @@
# nil and just send like normal when called on any other object.
class Object
- alias_method :try, :__send__
+ def try(*args)
+ Babushka::LogHelpers.deprecated! '2017-09-01'
+ __send__(*args)
+ end
end
class NilClass
def try *args
+ Babushka::LogHelpers.deprecated! '2017-09-01'
nil
end
end
View
@@ -112,7 +112,7 @@ def suffix
end
def cache_key
- DepRequirement.new(name, @params.map {|p| @args[p].try(:current_value) })
+ DepRequirement.new(name, @params.map {|p| @args.fetch(p) { Parameter.new(name) }.current_value })
end
def with *args
View
@@ -84,14 +84,14 @@ def prompt_and_read_value message, opts, &block
def read_value_from_prompt message, opts, &block
value = nil
- value = read_from_prompt(opts[:prompt].end_with(' '), opts[:choices]).try(:chomp)
- value = opts[:default].to_s if value.blank? && !(opts[:default] && opts[:default].to_s.empty?)
+ value = read_from_prompt(opts[:prompt].end_with(' '), opts[:choices]).chomp
+ value = opts[:default].to_s if value.empty? && !(opts[:default] && opts[:default].to_s.empty?)
error = if opts[:choices] && !opts[:choices].include?(value)
"That's not a valid choice"
elsif block_given? && !yield(value)
opts[:retry] || "That wasn't valid"
- elsif value.blank? && !(opts[:default] && opts[:default].empty?)
+ elsif value.empty? && !(opts[:default] && opts[:default].empty?)
"That was blank"
elsif !opts[:confirmation] && %w[y yes].include?(value) && !confirm("Wait, do you mean the literal value '#{value}'?", :default => 'n')
"Thought so :) Hit enter for the [default]"
@@ -129,12 +129,12 @@ def read_from_prompt prompt, choices = nil
# interrupts to work during Readline calls.
Base.exit_on_interrupt!
- Readline.readline(prompt, true).try(:strip)
+ (Readline.readline(prompt, true) || '').strip
end
rescue LoadError
def read_from_prompt prompt, choices = nil
print prompt
- STDIN.gets.try(:strip)
+ (STDIN.gets || '').strip
end
end
end
View
@@ -41,7 +41,9 @@ def initialize path, name = nil, uri = nil
raise ArgumentError, "Sources with nil paths require a name (as the second argument)." if path.nil? && name.nil?
raise ArgumentError, "The source URI can only be supplied if the source doesn't exist already." if !uri.nil? && !path.nil? && path.p.exists?
init
- @path, @name, @uri = path.try(:p), name, uri
+ @path = path.p unless path.nil?
+ @name = name
+ @uri = uri
end
def path
@@ -152,7 +152,8 @@ def current_load_source
end
def current_load_path
- current_load_context[:path].try(:p)
+ path = current_load_context[:path]
+ path.p unless path.nil?
end
def current_load_opts
@@ -37,7 +37,7 @@ def hostname
ShellHelpers.shell('hostname -f')
end
- def pkg_helper_key; pkg_helper.try(:manager_key) end
+ def pkg_helper_key; pkg_helper.manager_key end
def pkg_helper_str; pkg_helper_key.to_s.capitalize end
def cpu_type
View
@@ -51,7 +51,7 @@ def log_path_for dep
def open_log! mode = 'a'
log_prefix.mkdir
- @persistent_log.try(:close) # If the log was already open, close it.
+ @persistent_log.close unless @persistent_log.nil? # If the log was already open, close it.
@persistent_log = log_path_for(current_dep).open(mode).tap {|f| f.sync = true }
end

0 comments on commit 155f2d4

Please sign in to comment.