Class: Judojs::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path, name = 'JudoApplication') ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
17
18
19
# File 'lib/judojs/configuration.rb', line 13

def initialize(project_path, name = 'JudoApplication')
  @project_path = project_path
  @asset_root = project_path
  @name = name
  @output = 'expanded'
  @autoload = Array.new                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
end

Instance Attribute Details

#app_filenameObject (readonly)

Returns the value of attribute app_filename.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def app_filename
  @app_filename
end

#asset_rootObject (readonly)

Returns the value of attribute asset_root.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def asset_root
  @asset_root
end

#autoloadObject (readonly)

Returns the value of attribute autoload.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def autoload
  @autoload
end

#config_pathObject (readonly)

Returns the value of attribute config_path.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def config_path
  @config_path
end

#directoryObject (readonly)

Returns the value of attribute directory.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def directory
  @directory
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def output
  @output
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



4
5
6
# File 'lib/judojs/configuration.rb', line 4

def project_path
  @project_path
end

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/judojs/configuration.rb', line 21

def create
  conf_exists = File.exists? "#{@project_path}judojs.conf"
  
  if conf_exists
    autoload = @autoload.empty? ? 'autoload: []' : 'autoload: ["' << @autoload.join('", "') << '"]'
  else
    autoload = @autoload.empty? ? '#autoload: ["<judojs/utilities/all>", "../plugins/local_lib_file"]' : @autoload.join('", "')
  end
  
  conf_content = <<-CONF
project_path: #{@project_path}
asset_root: #{@project_path}
name: #{@name}
output: #{@output}
#{autoload}
  CONF
  
  File.open("#{@project_path}judojs.conf", "w+") do |conf_file|
    conf_file << conf_content
  end
  
  message = conf_exists ? "judojs.conf updated" : "judojs.conf created"
  puts message
end

#readObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/judojs/configuration.rb', line 46

def read
  begin
    raise IOError, "#{@project_path}judojs.conf does not exist", caller unless File.exists? "#{@project_path}judojs.conf"
    config_yaml = File.open("#{@project_path}judojs.conf", "r").readlines.join('')
    config = YAML::load config_yaml
    
    @project_path = config['project_path']
    @asset_root = config['asset_root']
    @name = config['name']
    @app_filename = config['name'].downcase
    @output = config['output']
    @autoload = config['autoload'] || Array.new
  rescue RuntimeError => e
    puts e.message
    puts e.backtrace.inspect
  end
end

#set_config(config) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/judojs/configuration.rb', line 68

def set_config(config)
  @name = config[:name] unless config[:name].nil?
  @app_filename = config[:app_filename] unless config[:app_filename].nil? 
  @directory = '/'
  @output = config[:output] unless config[:output].nil?
  @autoload = config[:autoload] || nil
end

#updateObject



64
65
66
# File 'lib/judojs/configuration.rb', line 64

def update
  create
end