Class: Ready::ZshFunction

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#environmentObject (readonly)

Returns the value of attribute environment.



8
9
10
# File 'lib/ready/zsh_function.rb', line 8

def environment
  @environment
end

#executableObject (readonly)

Returns the value of attribute executable.



8
9
10
# File 'lib/ready/zsh_function.rb', line 8

def executable
  @executable
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/ready/zsh_function.rb', line 8

def name
  @name
end

#template_pathObject (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_sObject



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