方法
- B
- C
- D
- E
- H
- N
- P
- U
已包含模組
類別公開方法
base_name() 連結
設定 base_name
,同時考量目前的類別命名空間。
Rails::Command::TestCommand.base_name # => 'rails'
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 106 def base_name @base_name ||= if base = name.to_s.split("::").first base.underscore end end
command_name() 連結
回傳不含命名空間的指令名稱。
Rails::Command::TestCommand.command_name # => 'test'
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 115 def command_name @command_name ||= if command = name.to_s.split("::").last command.chomp!("Command") command.underscore end end
default_command_root() 連結
預設的檔案根目錄,用於放置指令可能需要的額外檔案,位於指令檔案上一層的資料夾中。
例如,放置在 rails/command/test_command.rb
的 Rails::Command::TestCommand,會回傳 rails/test
。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 139 def default_command_root @default_command_root = resolve_path(".") unless defined?(@default_command_root) @default_command_root end
desc(usage = nil, description = nil, options = {}) 連結
嘗試從指令根目錄上一層的 USAGE 檔案中取得描述。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 34 def desc(usage = nil, description = nil, options = {}) if usage super else class_usage end end
engine?() 連結
當應用程式是 Rails 引擎時,回傳 true。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 28 def engine? defined?(ENGINE_ROOT) end
executable(command_name = self.command_name) 連結
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 82 def executable(command_name = self.command_name) "#{bin} #{namespaced_name(command_name)}" end
hide_command!() 連結
便捷方法,用於在執行 rails command 時隱藏此指令。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 55 def hide_command! Rails::Command.hidden_commands << self end
namespace(name = nil) 連結
便捷方法,用於從類別名稱中取得命名空間。它與 Thor 的預設值相同,只是類別名稱結尾的 Command
會被移除。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 45 def namespace(name = nil) if name super else @namespace ||= super.chomp("_command").sub(/:command:/, ":") end end
printing_commands() 連結
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 76 def printing_commands commands.filter_map do |name, command| [namespaced_name(name), command.description] unless command.hidden? end end
usage_path() 連結
在檔案中查詢 USAGE 描述的路徑。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 129 def usage_path @usage_path = resolve_path("USAGE") unless defined?(@usage_path) @usage_path end