Class: Lightning::Bolt
- Inherits:
-
Object
- Object
- Lightning::Bolt
- Defined in:
- lib/lightning/bolt.rb
Overview
A Bolt object is mainly a user-defined set of globs required by a Function object to translate paths.
Globs
Globs are interpreted by Dir.glob and are fairly similar to shell globs. Some glob examples:
-
Files ending with specific file extensions for a given directory.
"/some/path/*.{rb,erb}"-> Matches files ending with .rb or .erb
-
Files and directories that don’t start with specific letters.
"[^ls]*" -> Matches anything not starting with l or s
-
All directories, however many levels deep, under the current directory.
"**/"
Instance Attribute Summary collapse
-
#aliases ⇒ Hash
readonly
Maps aliases to full paths.
-
#functions ⇒ Array<Hash, String>
Used to generate functions.
-
#global ⇒ Boolean
readonly
When true adds global commands to list of commands used to generate a bolt’s functions.
-
#globs ⇒ Array
User-defined globs that are translated by Dir.glob().
-
#name ⇒ String
readonly
Unique alphanumeric name.
Instance Method Summary collapse
-
#function_name(scmd) ⇒ Object
Creates function name for a bolt given a shell command.
-
#generate_functions ⇒ Array
Generates functions from a bolt’s functions and global shell commands.
-
#initialize(name) ⇒ Bolt
constructor
A new instance of Bolt.
Constructor Details
#initialize(name) ⇒ Bolt
Returns a new instance of Bolt.
27 28 29 30 31 32 33 34 35 |
# File 'lib/lightning/bolt.rb', line 27 def initialize(name) @name = name @globs = [] @functions = [] @aliases = {} config = Lightning.config.bolts[@name] || {} config.each { |k,v| instance_variable_set("@#{k}", v) } @globs = Generator.run(@name, :live => true) unless config.key?('globs') end |
Instance Attribute Details
#aliases ⇒ Hash (readonly)
Returns Maps aliases to full paths. Aliases are valid for a bolt’s functions.
19 20 21 |
# File 'lib/lightning/bolt.rb', line 19 def aliases @aliases end |
#functions ⇒ Array<Hash, String>
Used to generate functions.
26 27 28 |
# File 'lib/lightning/bolt.rb', line 26 def functions @functions end |
#global ⇒ Boolean (readonly)
Returns When true adds global commands to list of commands used to generate a bolt’s functions.
21 22 23 |
# File 'lib/lightning/bolt.rb', line 21 def global @global end |
#globs ⇒ Array
Returns User-defined globs that are translated by Dir.glob().
23 24 25 |
# File 'lib/lightning/bolt.rb', line 23 def globs @globs end |
#name ⇒ String (readonly)
Returns Unique alphanumeric name.
17 18 19 |
# File 'lib/lightning/bolt.rb', line 17 def name @name end |
Instance Method Details
#function_name(scmd) ⇒ Object
Creates function name for a bolt given a shell command
51 52 53 |
# File 'lib/lightning/bolt.rb', line 51 def function_name(scmd) Lightning.config.function_name(scmd, alias_or_name) end |
#generate_functions ⇒ Array
Generates functions from a bolt’s functions and global shell commands
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lightning/bolt.rb', line 39 def generate_functions @functions += Lightning.config.global_commands if @global @functions.inject({}) {|acc, e| cmd = e.is_a?(Hash) ? e.dup : {'shell_command'=>e} cmd['bolt'] = self cmd['name'] ||= function_name(cmd['shell_command']) acc[cmd['name']] ||= cmd if cmd['shell_command'] acc }.values end |