Class: WatchedFile
- Inherits:
-
Object
- Object
- WatchedFile
- Defined in:
- lib/text_tunnel/watched_file.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
Instance Method Summary collapse
-
#initialize(name, data) ⇒ WatchedFile
constructor
A new instance of WatchedFile.
- #poll ⇒ Object
Constructor Details
#initialize(name, data) ⇒ WatchedFile
Returns a new instance of WatchedFile.
12 13 14 15 16 17 18 19 20 |
# File 'lib/text_tunnel/watched_file.rb', line 12 def initialize(name, data) @name = sanitize_name(name) @data = data @id = SecureRandom.hex @local_dir = "#{Dir.tmpdir}/text-tunnel/#{id}" @local_path = "#{@local_dir}/#{@name}" write_temp_file end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/text_tunnel/watched_file.rb', line 9 def data @data end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'lib/text_tunnel/watched_file.rb', line 10 def hash @hash end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/text_tunnel/watched_file.rb', line 7 def id @id end |
#local_path ⇒ Object (readonly)
Returns the value of attribute local_path.
8 9 10 |
# File 'lib/text_tunnel/watched_file.rb', line 8 def local_path @local_path end |
Instance Method Details
#poll ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/text_tunnel/watched_file.rb', line 22 def poll old_mtime = @mtime @mtime = File.mtime(local_path) if @mtime != old_mtime @mtime = old_mtime @data = File.read(local_path) hash_data end end |