Class: Crafti::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/crafti.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, app_name = nil) ⇒ FileReader

Returns a new instance of FileReader.



102
103
104
105
# File 'lib/crafti.rb', line 102

def initialize(file, app_name = nil)
  ::Crafti::AppName.name(app_name)
  @content  = ::Pathname.new(file.to_s).expand_path.read
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



101
102
103
# File 'lib/crafti.rb', line 101

def content
  @content
end

Class Method Details

.generate(file, app_name = nil) ⇒ Object



96
97
98
99
# File 'lib/crafti.rb', line 96

def self.generate(file, app_name = nil)
  app = new(file, app_name)
  app.evaluate
end

Instance Method Details

#evaluateObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/crafti.rb', line 107

def evaluate
  klass = Class.new do
    Kernel.extend(Crafti::KernelExtension)
    Kernel.extend(Crafti::AppName)
    def self.execute(string)
      eval string
    end
  end

  klass.execute(content)
end