Class: PomPomPom::Config
- Inherits:
-
Object
- Object
- PomPomPom::Config
- Defined in:
- lib/pompompom/config.rb
Constant Summary collapse
- REPOSITORIES =
%w(http://repo1.maven.org/maven2)
- TARGET_DIR =
'lib'
- CACHE_DIR =
File.('~/.pompompom')
- CONFIG_FILE =
File.('~/.pompompomrc')
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#repositories ⇒ Object
readonly
Returns the value of attribute repositories.
-
#target_dir ⇒ Object
readonly
Returns the value of attribute target_dir.
Instance Method Summary collapse
- #create_file! ⇒ Object
- #file_exists? ⇒ Boolean
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #load! ⇒ Object
- #symbolize_keys(h) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 |
# File 'lib/pompompom/config.rb', line 13 def initialize(={}) @options_set = .keys @repositories = [:repositories] || REPOSITORIES @target_dir = [:target_dir] || TARGET_DIR @cache_dir = [:cache_dir] || CACHE_DIR @config_file = [:config_file] || CONFIG_FILE end |
Instance Attribute Details
#cache_dir ⇒ Object (readonly)
Returns the value of attribute cache_dir.
11 12 13 |
# File 'lib/pompompom/config.rb', line 11 def cache_dir @cache_dir end |
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
11 12 13 |
# File 'lib/pompompom/config.rb', line 11 def config_file @config_file end |
#repositories ⇒ Object (readonly)
Returns the value of attribute repositories.
11 12 13 |
# File 'lib/pompompom/config.rb', line 11 def repositories @repositories end |
#target_dir ⇒ Object (readonly)
Returns the value of attribute target_dir.
11 12 13 |
# File 'lib/pompompom/config.rb', line 11 def target_dir @target_dir end |
Instance Method Details
#create_file! ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pompompom/config.rb', line 33 def create_file! return if file_exists? File.open(@config_file, 'w') do |f| f.write(YAML.dump( 'repositories' => @repositories, 'cache_dir' => @cache_dir, 'target_dir' => @target_dir )) end end |
#file_exists? ⇒ Boolean
29 30 31 |
# File 'lib/pompompom/config.rb', line 29 def file_exists? File.exists?(@config_file) end |
#load! ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/pompompom/config.rb', line 21 def load! return unless file_exists? = symbolize_keys(YAML.load(File.read(@config_file))) @repositories = [:repositories] || @repositories unless @options_set.include?(:repositories) @target_dir = [:target_dir] || @target_dir unless @options_set.include?(:target_dir) @cache_dir = [:cache_dir] || @cache_dir unless @options_set.include?(:cache_dir) end |
#symbolize_keys(h) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/pompompom/config.rb', line 44 def symbolize_keys(h) h.keys.inject({}) do |acc, k| acc[k.to_sym] = if Hash === h[k] then symbolize_keys(h[k]) else h[k] end acc end end |