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.
18 19 20 21 |
# File 'lib/completely/completions.rb', line 18 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
23 24 25 |
# File 'lib/completely/completions.rb', line 23 def flat_config @flat_config ||= config.flat_config end |
#patterns ⇒ Object
27 28 29 |
# File 'lib/completely/completions.rb', line 27 def patterns @patterns ||= patterns! end |
#script ⇒ Object
35 36 37 |
# File 'lib/completely/completions.rb', line 35 def script ERB.new(template, trim_mode: '%-').result(binding) end |
#tester ⇒ Object
50 51 52 |
# File 'lib/completely/completions.rb', line 50 def tester @tester ||= Tester.new script: script, function_name: function_name end |
#valid? ⇒ Boolean
31 32 33 |
# File 'lib/completely/completions.rb', line 31 def valid? pattern_prefixes.uniq.one? end |
#wrapper_function(name = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/completely/completions.rb', line 39 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 |