Class: MySampler::FileRotating
- Inherits:
-
Object
- Object
- MySampler::FileRotating
- Defined in:
- lib/mysampler/file.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(params, *args) ⇒ FileRotating
constructor
A new instance of FileRotating.
Constructor Details
#initialize(params, *args) ⇒ FileRotating
Returns a new instance of FileRotating.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mysampler/file.rb', line 11 def initialize (params, *args) @interval = params[:interval] || DAY @header = params[:header] || nil # a header to put at the top of every file @args = args @root_fn = args[0] @stamp = get_date_stamp open_local do |f| f.puts @header if @header if block_given? return yield f else return f end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mysampler/file.rb', line 67 def method_missing(method, *args, &block) # check to see if we need to reopen stamp = get_date_stamp if @stamp != stamp @stamp = stamp close open_local @f.puts @header if @header end return @f.send(method, *args, &block) end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
9 10 11 |
# File 'lib/mysampler/file.rb', line 9 def header @header end |
Instance Method Details
#close ⇒ Object
28 29 30 31 32 33 |
# File 'lib/mysampler/file.rb', line 28 def close if @f @f.flock(File::LOCK_UN) @f.close end end |