Class: Gloo::Objs::FileHandle
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::FileHandle
- Defined in:
- lib/gloo/objs/system/file_handle.rb
Constant Summary collapse
- KEYWORD =
'file'.freeze
- KEYWORD_SHORT =
'dir'.freeze
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#msg_check_exists ⇒ Object
Check to see if the file exists.
-
#msg_check_is_dir ⇒ Object
Check to see if the file is a directory.
-
#msg_check_is_file ⇒ Object
Check to see if the file is a file.
-
#msg_open ⇒ Object
Open the file in the default application for the file type.
-
#msg_page ⇒ Object
Show the contents of the file, paginated.
-
#msg_read ⇒ Object
Read the contents of the file into the object.
-
#msg_show ⇒ Object
Show the contents of the file.
-
#msg_write ⇒ Object
Write the given data out to the file.
Methods inherited from Core::Obj
#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #msg_unload, #multiline_value?, #pn, #remove_child, #root?, #send_message, #set_parent, #set_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
36 37 38 39 40 41 |
# File 'lib/gloo/objs/system/file_handle.rb', line 36 def self. basic = %w[read write] checks = %w[check_exists check_is_file check_is_dir] show = %w[show page open] return super + basic + show + checks end |
.short_typename ⇒ Object
The short name of the object type.
25 26 27 |
# File 'lib/gloo/objs/system/file_handle.rb', line 25 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
18 19 20 |
# File 'lib/gloo/objs/system/file_handle.rb', line 18 def self.typename return KEYWORD end |
Instance Method Details
#msg_check_exists ⇒ Object
Check to see if the file exists.
106 107 108 109 |
# File 'lib/gloo/objs/system/file_handle.rb', line 106 def msg_check_exists result = File.exist? value $engine.heap.it.set_to result end |
#msg_check_is_dir ⇒ Object
Check to see if the file is a directory.
122 123 124 125 |
# File 'lib/gloo/objs/system/file_handle.rb', line 122 def msg_check_is_dir result = File.directory? value $engine.heap.it.set_to result end |
#msg_check_is_file ⇒ Object
Check to see if the file is a file.
114 115 116 117 |
# File 'lib/gloo/objs/system/file_handle.rb', line 114 def msg_check_is_file result = File.file? value $engine.heap.it.set_to result end |
#msg_open ⇒ Object
Open the file in the default application for the file type.
46 47 48 49 50 51 52 |
# File 'lib/gloo/objs/system/file_handle.rb', line 46 def msg_open return unless value && File.exist?( value ) cmd = Gloo::Core::GlooSystem.open_for_platform cmd_with_param = "#{cmd} \"#{value}\"" `#{cmd_with_param}` end |
#msg_page ⇒ Object
Show the contents of the file, paginated.
57 58 59 60 61 62 |
# File 'lib/gloo/objs/system/file_handle.rb', line 57 def msg_page return unless value && File.file?( value ) pager = TTY::Pager.new pager.page( path: value ) end |
#msg_read ⇒ Object
Read the contents of the file into the object.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gloo/objs/system/file_handle.rb', line 76 def msg_read return unless value && File.file?( value ) data = File.read( value ) if @params&.token_count&.positive? pn = Gloo::Core::Pn.new @params.first o = pn.resolve o.set_value data else $engine.heap.it.set_to data end end |
#msg_show ⇒ Object
Show the contents of the file.
67 68 69 70 71 |
# File 'lib/gloo/objs/system/file_handle.rb', line 67 def msg_show return unless value && File.file?( value ) puts File.read( value ) end |
#msg_write ⇒ Object
Write the given data out to the file.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/gloo/objs/system/file_handle.rb', line 92 def msg_write data = '' return unless value if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @params.tokens ) data = expr.evaluate end File.write( value, data ) end |