Class: Completely::Completions
- Inherits:
-
Object
- Object
- Completely::Completions
- Defined in:
- lib/completely/completions.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #flat_config ⇒ Object
-
#initialize(config, function_name: nil) ⇒ Completions
constructor
A new instance of Completions.
- #patterns ⇒ Object
- #script ⇒ Object
- #tester ⇒ Object
- #valid? ⇒ Boolean
- #wrapper_function(name = nil) ⇒ Object
Constructor Details
#initialize(config, function_name: nil) ⇒ Completions
Returns a new instance of Completions.
15 16 17 18 |
# File 'lib/completely/completions.rb', line 15 def initialize(config, function_name: nil) @config = config.is_a?(Config) ? config : Config.new(config) @function_name = function_name end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/completely/completions.rb', line 6 def config @config end |
Class Method Details
Instance Method Details
#flat_config ⇒ Object
20 21 22 |
# File 'lib/completely/completions.rb', line 20 def flat_config @flat_config ||= config.flat_config end |
#patterns ⇒ Object
24 25 26 |
# File 'lib/completely/completions.rb', line 24 def patterns @patterns ||= patterns! end |
#script ⇒ Object
32 33 34 |
# File 'lib/completely/completions.rb', line 32 def script ERB.new(template, trim_mode: '%-').result(binding) end |
#tester ⇒ Object
47 48 49 |
# File 'lib/completely/completions.rb', line 47 def tester @tester ||= Tester.new script: script, function_name: function_name end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/completely/completions.rb', line 28 def valid? pattern_prefixes.uniq.count == 1 end |
#wrapper_function(name = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/completely/completions.rb', line 36 def wrapper_function(name = nil) name ||= 'send_completions' script_lines = script.split("\n").map do |line| clean_line = line.gsub("'") { "\\'" } " echo $'#{clean_line}'" end.join("\n") "#{name}() {\n#{script_lines}\n}" end |