Class: Ready::ZshFunction
- Inherits:
-
Object
- Object
- Ready::ZshFunction
- Defined in:
- lib/ready/zsh_function.rb
Overview
Renders a zsh function that wraps an executable, using the bundled ERB template.
Constant Summary collapse
- DEFAULT_TEMPLATE_PATH =
Pathname(__dir__) / "fn.zsh.erb"
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#executable ⇒ Object
readonly
Returns the value of attribute executable.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Instance Method Summary collapse
-
#initialize(name, environment: {}, template_path: DEFAULT_TEMPLATE_PATH) ⇒ ZshFunction
constructor
A new instance of ZshFunction.
- #to_s ⇒ Object
Constructor Details
#initialize(name, environment: {}, template_path: DEFAULT_TEMPLATE_PATH) ⇒ ZshFunction
Returns a new instance of ZshFunction.
11 12 13 14 15 16 |
# File 'lib/ready/zsh_function.rb', line 11 def initialize(name, environment: {}, template_path: DEFAULT_TEMPLATE_PATH) @name = name @environment = environment @executable = Executable.new(name) @template_path = Pathname(template_path) end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/ready/zsh_function.rb', line 8 def environment @environment end |
#executable ⇒ Object (readonly)
Returns the value of attribute executable.
8 9 10 |
# File 'lib/ready/zsh_function.rb', line 8 def executable @executable end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/ready/zsh_function.rb', line 8 def name @name end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
8 9 10 |
# File 'lib/ready/zsh_function.rb', line 8 def template_path @template_path end |
Instance Method Details
#to_s ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ready/zsh_function.rb', line 18 def to_s template = ERB.new(@template_path.read) template.result_with_hash( name: name, ruby: executable.render, env: environment, ) end |