Class: Filewatcher::CLI::Env
- Inherits:
-
Object
- Object
- Filewatcher::CLI::Env
- Defined in:
- lib/filewatcher/cli/env.rb
Overview
Class for building ENV variables for executable
Instance Method Summary collapse
-
#initialize(filename, event) ⇒ Env
constructor
A new instance of Env.
- #to_h ⇒ Object
Constructor Details
#initialize(filename, event) ⇒ Env
Returns a new instance of Env.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/filewatcher/cli/env.rb', line 9 def initialize(filename, event) @filename = filename @event = event @path = Pathname.new(@filename) @realpath = @path.exist? ? @path.realpath : @path @current_dir = Pathname.new(Dir.pwd) # For safely `immediate` option with empty-strings arguments @relative_path = (@realpath.to_s.empty? ? @current_dir : @realpath) .relative_path_from(@current_dir) end |
Instance Method Details
#to_h ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/filewatcher/cli/env.rb', line 21 def to_h { 'FILEPATH' => (@realpath.to_s if @event != :deleted), 'FILENAME' => @filename, 'BASENAME' => @path.basename.to_s, 'EVENT' => @event.to_s, 'DIRNAME' => @path.parent.realpath.to_s, 'ABSOLUTE_FILENAME' => @realpath.to_s, 'RELATIVE_FILENAME' => @relative_path.to_s } end |