Class: Cameleon

Inherits:
Object
  • Object
show all
Defined in:
lib/cameleon.rb,
lib/cameleon/app.rb,
lib/cameleon/action.rb,
lib/cameleon/renderer.rb

Defined Under Namespace

Classes: Action, App, Renderer, ValidationError

Constant Summary collapse

@@imported =
{}
@@config =
nil

Class Method Summary collapse

Class Method Details

.configObject

import



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cameleon.rb', line 35

def config
  @config ||= begin
    path = "./cameleon.yml"
    unless File.exist? path
      return nil
    end
    Hashie::Mash.new YAML.load(File.read(path))
  end
  load_setup
  @config
end

.import(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cameleon.rb', line 16

def import(file)
  raise "file not found" unless File.exists? file
  crnt_timestamp = File::stat(file).mtime
  if @@imported.include?(file)
    prev_timestamp = @@imported[file]
    if (crnt_timestamp > prev_timestamp)
      @@imported[file] = crnt_timestamp
      load(file)
      return true
    else
      return false
    end
  else
    @@imported[file] = crnt_timestamp
    load(file)
    return true
  end
end

.load_setupObject

config



47
48
49
50
# File 'lib/cameleon.rb', line 47

def load_setup
  path = './initializer.rb'
  require path if File.exist? path
end

.rootObject



12
13
14
# File 'lib/cameleon.rb', line 12

def root
  File.join File.dirname(__FILE__), "../"
end

.setup(&block) ⇒ Object

call from initializer.rb



53
54
55
# File 'lib/cameleon.rb', line 53

def setup(&block)
  block.call(@config)
end

.versionObject



57
58
59
# File 'lib/cameleon.rb', line 57

def version
  File.read(File.join(Cameleon.root, "VERSION")).chomp
end