diff options
author | 0xAB <0xAB@protonmail.com> | 2017-08-28 01:19:13 +0100 |
---|---|---|
committer | 0xAB <0xAB@protonmail.com> | 2017-08-28 01:22:16 +0100 |
commit | 870c61489b87803e0b7b01ee148c439c66f82c33 (patch) | |
tree | e72b827fcd968b96a8836121f859d4474d44437f | |
parent | 4039c98acff4cee3c18e6e9a7c6743949de7ab96 (diff) | |
download | pry-870c61489b87803e0b7b01ee148c439c66f82c33.tar.gz |
rename get_prompt as []
-rw-r--r-- | lib/pry/commands/alias_prompt.rb | 2 | ||||
-rw-r--r-- | lib/pry/commands/change_prompt.rb | 2 | ||||
-rw-r--r-- | lib/pry/prompt.rb | 15 | ||||
-rw-r--r-- | spec/prompt_spec.rb | 2 |
4 files changed, 10 insertions, 11 deletions
diff --git a/lib/pry/commands/alias_prompt.rb b/lib/pry/commands/alias_prompt.rb index 8fbb8702..a5f7a5ab 100644 --- a/lib/pry/commands/alias_prompt.rb +++ b/lib/pry/commands/alias_prompt.rb @@ -16,7 +16,7 @@ class Pry if not args_ok?([prompt_name, alias_name]) return output.puts help end - if Pry::Prompt.get_prompt(prompt_name) + if Pry::Prompt[prompt_name] Pry::Prompt.alias_prompt prompt_name, alias_name output.puts "Alias '#{alias_name}' created" else diff --git a/lib/pry/commands/change_prompt.rb b/lib/pry/commands/change_prompt.rb index 240cd63e..c6e72a20 100644 --- a/lib/pry/commands/change_prompt.rb +++ b/lib/pry/commands/change_prompt.rb @@ -11,7 +11,7 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand BANNER def process(prompt) - if new_prompt = Pry::Prompt.get_prompt(prompt) + if new_prompt = Pry::Prompt[prompt] _pry_.prompt = new_prompt.proc_array else raise Pry::CommandError, "'#{prompt}' isn't a known prompt!" diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb index f6287529..dfb533de 100644 --- a/lib/pry/prompt.rb +++ b/lib/pry/prompt.rb @@ -1,6 +1,7 @@ module Pry::Prompt extend self PROMPT_MAP = {} + private_constant :PROMPT_MAP AliasError = Class.new(RuntimeError) PromptInfo = Struct.new(:name, :description, :proc_array, :alias_for) do # @@ -61,15 +62,13 @@ module Pry::Prompt # @example # # # .pryrc - # Pry.config.prompt = Pry::Prompt.get_prompt('simple').proc_array + # Pry.config.prompt = Pry::Prompt['simple'].proc_array # # @return [PromptInfo] # Returns a prompt in the form of a PromptInfo object. # - def get_prompt(name) - all_prompts.find do |prompt| - prompt.name == name.to_s - end + def [](name) + all_prompts.find {|prompt| prompt.name == name.to_s } end # @@ -87,8 +86,8 @@ module Pry::Prompt # Returns truthy if a prompt was deleted, otherwise nil. # def remove_prompt(name) - prompt = get_prompt(name.to_s) - PROMPT_MAP.delete name if prompt + prompt = self[name.to_s] + PROMPT_MAP.delete name.to_s if prompt end # @@ -102,7 +101,7 @@ module Pry::Prompt # The name of the aliased prompt. # def alias_prompt(prompt_name, aliased_prompt) - prompt = get_prompt(prompt_name) + prompt = self[prompt_name.to_s] if not prompt raise AliasError, "prompt '#{prompt}' cannot be aliased because it doesn't exist" elsif prompt.alias? diff --git a/spec/prompt_spec.rb b/spec/prompt_spec.rb index f2a61604..034cfc78 100644 --- a/spec/prompt_spec.rb +++ b/spec/prompt_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Pry::Prompt do describe ".add_prompt" do specify "it adds a new prompt to Pry" do - new_prompt = described_class::PROMPT_MAP['prompt-name'] + new_prompt = described_class['prompt-name'] expect(pry_eval("list-prompts")).to include("prompt-name") expect(pry_eval("list-prompts")).to include("prompt description") expect(pry_eval("change-prompt prompt-name", "_pry_.prompt")).to eq(new_prompt.proc_array) |