Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/ccios/config.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config_hash, source_path = nil) ⇒ Config
constructor
A new instance of Config.
- #validate(hash) ⇒ Object
- #validate_path(hash, path) ⇒ Object
Constructor Details
#initialize(config_hash, source_path = nil) ⇒ Config
Returns a new instance of Config.
41 42 43 44 45 46 47 |
# 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 |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/ccios/config.rb', line 5 def app @app end |
#core ⇒ Object (readonly)
Returns the value of attribute core.
5 6 7 |
# File 'lib/ccios/config.rb', line 5 def core @core end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/ccios/config.rb', line 5 def data @data end |
Class Method Details
.default ⇒ Object
37 38 39 |
# File 'lib/ccios/config.rb', line 37 def self.default self.new default_config_hash end |
.default_config_hash ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
.parse(source_path) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# 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 |
Instance Method Details
#validate(hash) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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? = "Key \"#{keys.join(".")}\" is missing" += " in #{@source_path}" unless @source_path.nil? raise end end end |