Module: Fileable

Defined in:
lib/gems/facets-2.4.5/lib/more/facets/fileable.rb

Overview

Fileable

Make File-esque classes. Fileable makes it easy to create classes that can load from files.

Class level mixin for loading/opening file classes. You will generally want to use extend with this.

NOTE: This is an expiremental library, and is still

undergoing revision.

Defined Under Namespace

Modules: DSL

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

When included extend DSL too.



50
51
52
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileable.rb', line 50

def self.included(base)
  base.extend DSL
end

Instance Method Details

#initialize(content) ⇒ Object

New fileable object. By default this is called by #read passing the file contents. Override it if need is differnt.



62
63
64
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileable.rb', line 62

def initialize(content)
  @content = content
end

#read(file) ⇒ Object

Override this if reading is differnt.



68
69
70
71
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileable.rb', line 68

def read(file)
  self.file = file if defined?(:file=)
  initialize(File.read(file))
end