Class: Matryoshka::Data

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Data

Returns a new instance of Data.



2
3
4
5
# File 'lib/matryoshka/data.rb', line 2

def initialize(*args) 
  # args = whatever is necessary to find correct dir
  # Right now that means nothing
end

Instance Method Details

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/matryoshka/data.rb', line 33

def exists?(path)
  File.exists? expand(path)
end

#expand(path) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/matryoshka/data.rb', line 7

def expand(path)
  if File.directory?('./templates')
    './templates' + path
  else
    Matryoshka::ROOT_DIR + '/templates' + path
  end
end

#find(path, extentions = ['']) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/matryoshka/data.rb', line 15

def find(path, extentions = [''])
  path = strip_extention(path)
  extentions.each do |extention|
    path_with_extention = "#{path}#{extention}"
    if exists? path_with_extention
      return [200,
         {:template_path => path_with_extention },
         read(path_with_extention)
        ]
    end
  end
  false # No results found.
end

#read(path_with_extention) ⇒ Object



29
30
31
# File 'lib/matryoshka/data.rb', line 29

def read(path_with_extention)
  IO.read(expand(path_with_extention))
end

#strip_extention(path) ⇒ Object

This may not be smart.



38
39
40
# File 'lib/matryoshka/data.rb', line 38

def strip_extention(path)
  path.sub(/\.[^.]{1,4}\Z/,'')
end