Class: ExpressionEngine::Initializer

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

Constant Summary collapse

CONFIGURATION_FILENAME =
'rbee.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Initializer

Returns a new instance of Initializer.



13
14
15
# File 'lib/vendor/initializer.rb', line 13

def initialize(path)
  @current_path  = path
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



6
7
8
# File 'lib/vendor/initializer.rb', line 6

def configuration
  @configuration
end

Class Method Details

.root_directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/vendor/initializer.rb', line 8

def self.root_directory?(path)
  directory = Dir.new(path)
  directory.entries.include?('index.php') && directory.entries.include?('path.php')
end

Instance Method Details

#configuration_fileObject



33
34
35
# File 'lib/vendor/initializer.rb', line 33

def configuration_file
  "#{self.configuration_path}/#{CONFIGURATION_FILENAME}" unless self.configuration_path.nil?
end

#configuration_pathObject



23
24
25
# File 'lib/vendor/initializer.rb', line 23

def configuration_path
  find_in_path(@current_path) {|path| File.exist?("#{path}/#{CONFIGURATION_FILENAME}")}
end

#initialized?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vendor/initializer.rb', line 41

def initialized?
  !self.configuration_file.nil?
end

#root_pathObject



17
18
19
20
21
# File 'lib/vendor/initializer.rb', line 17

def root_path
  path = self.configuration_path
  path = find_in_path(@current_path) {|path| self.class.root_directory?(path) } if path.nil?
  path
end

#source_configuration_fileObject



37
38
39
# File 'lib/vendor/initializer.rb', line 37

def source_configuration_file
  "#{self.system_path}/config.php" if self.system_path
end

#system_pathObject



27
28
29
30
31
# File 'lib/vendor/initializer.rb', line 27

def system_path
  config_file = 'config.php'
  paths = Dir["#{self.root_path}/**/#{config_file}"]
  paths.first.sub(/\/#{Regexp.escape(config_file)}$/, '') unless paths.empty?
end

#write_configurationObject



45
46
47
# File 'lib/vendor/initializer.rb', line 45

def write_configuration
  File.open("#{self.root_path}/#{CONFIGURATION_FILENAME}", 'w') {|f| f << self.configuration.to_yaml }
end