Module: Greenhouse::Resources::FileResource::InstanceMethods
- Defined in:
- lib/greenhouse/resources/file_resource.rb
Class Method Summary collapse
Instance Method Summary collapse
- #chdir(&block) ⇒ Object
- #exists? ⇒ Boolean
- #initialize(path) ⇒ Object
- #lines(reload = false) ⇒ Object
- #open(mode, &block) ⇒ Object
- #read(&block) ⇒ Object
- #unlink ⇒ Object
Class Method Details
.included(base) ⇒ Object
12 13 14 |
# File 'lib/greenhouse/resources/file_resource.rb', line 12 def self.included(base) base.send :attr_reader, :path end |
Instance Method Details
#chdir(&block) ⇒ Object
39 40 41 |
# File 'lib/greenhouse/resources/file_resource.rb', line 39 def chdir(&block) Dir.chdir(File.("../", path), &block) end |
#exists? ⇒ Boolean
16 17 18 |
# File 'lib/greenhouse/resources/file_resource.rb', line 16 def exists? File.exists?(path) end |
#initialize(path) ⇒ Object
43 44 45 |
# File 'lib/greenhouse/resources/file_resource.rb', line 43 def initialize(path) @path = File.(path) end |
#lines(reload = false) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/greenhouse/resources/file_resource.rb', line 24 def lines(reload=false) @lines = nil if reload @lines ||= [] unless exists? @lines ||= File.read(path).split("\n") @lines end |
#open(mode, &block) ⇒ Object
20 21 22 |
# File 'lib/greenhouse/resources/file_resource.rb', line 20 def open(mode, &block) File.open(path, mode, &block) end |
#read(&block) ⇒ Object
31 32 33 |
# File 'lib/greenhouse/resources/file_resource.rb', line 31 def read(&block) lines(true).each_with_index(&block) end |
#unlink ⇒ Object
35 36 37 |
# File 'lib/greenhouse/resources/file_resource.rb', line 35 def unlink File.unlink(path) if exists? end |