class Config

Attributes

app[R]
core[R]
data[R]

Public Class Methods

default() click to toggle source
# File lib/ccios/config.rb, line 37
def self.default
  self.new default_config_hash
end
default_config_hash() click to toggle source
# File lib/ccios/config.rb, line 17
def self.default_config_hash
  project = "*.xcodeproj"
  {
    "app" => {
      "project" => project,
      "presenter" => {"group" => "Classes/App"},
      "coordinator" => {"group" => "Classes/Coordinator"}
    },
    "core" => {
      "project" => project,
      "interactor" => {"group" => "Classes/Core/Interactor"},
      "repository" => {"group" => "Classes/Core/Data"}
    },
    "data" => {
      "project" => project,
      "repository" => {"group" => "Classes/Data"}
    }
  }
end
new(config_hash, source_path = nil) click to toggle source
# File lib/ccios/config.rb, line 41
def initialize(config_hash, source_path = nil)
  @source_path = source_path
  validate config_hash
  @app = AppConfig.new config_hash["app"]
  @core = CoreConfig.new config_hash["core"]
  @data = DataConfig.new config_hash["data"]
end
parse(source_path) click to toggle source
# File lib/ccios/config.rb, line 7
def self.parse(source_path)
  if File.exist?(source_path)
    config = YAML.load_file(source_path)
    self.new config, source_path
  else
    puts "File #{source_path} does not exists. Using default config."
    self.default
  end
end

Public Instance Methods

validate(hash) click to toggle source
# File lib/ccios/config.rb, line 49
def validate(hash)
  validate_path hash, "app.project"
  validate_path hash, "app.presenter.group"
  validate_path hash, "app.coordinator.group"

  validate_path hash, "core.project"
  validate_path hash, "core.interactor.group"
  validate_path hash, "core.repository.group"

  validate_path hash, "data.project"
  validate_path hash, "data.repository.group"
end
validate_path(hash, path) click to toggle source
# File lib/ccios/config.rb, line 62
def validate_path(hash, path)
  components = path.split(".")
  keys = []
  components.each do |component|
    hash = hash[component]
    keys << component
    if hash.nil?
      message = "Key \"#{keys.join(".")}\" is missing"
      message += " in #{@source_path}" unless @source_path.nil?
      raise message
    end
  end
end