Class: Gitload::Config
- Inherits:
-
Object
- Object
- Gitload::Config
- Defined in:
- lib/gitload/config.rb
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#clear_cache ⇒ Object
Returns the value of attribute clear_cache.
-
#clone_url_type ⇒ Object
Returns the value of attribute clone_url_type.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #apply ⇒ Object
- #clone_options ⇒ Object
- #delete(relative_path) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #load(relative_path) ⇒ Object
- #load_or_cache_data(relative_path) ⇒ Object
- #save(relative_path, contents) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 |
# File 'lib/gitload/config.rb', line 11 def initialize = {} @root = [:root] @cache = .cache @clear_cache = .clear_cache @dry_run = .dry_run @clone_url_type = [:clone_url_type] end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
6 7 8 |
# File 'lib/gitload/config.rb', line 6 def cache @cache end |
#clear_cache ⇒ Object
Returns the value of attribute clear_cache.
7 8 9 |
# File 'lib/gitload/config.rb', line 7 def clear_cache @clear_cache end |
#clone_url_type ⇒ Object
Returns the value of attribute clone_url_type.
9 10 11 |
# File 'lib/gitload/config.rb', line 9 def clone_url_type @clone_url_type end |
#dry_run ⇒ Object
Returns the value of attribute dry_run.
8 9 10 |
# File 'lib/gitload/config.rb', line 8 def dry_run @dry_run end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/gitload/config.rb', line 5 def root @root end |
Instance Method Details
#apply ⇒ Object
19 20 21 22 |
# File 'lib/gitload/config.rb', line 19 def apply filename = File. '~/.gitload.rb' DSL.new(self).instance_eval File.read(filename), filename end |
#clone_options ⇒ Object
24 25 26 27 28 29 |
# File 'lib/gitload/config.rb', line 24 def { dry_run: @dry_run, clone_url_type: @clone_url_type } end |
#delete(relative_path) ⇒ Object
60 61 62 |
# File 'lib/gitload/config.rb', line 60 def delete relative_path FileUtils.rm_f data_file(relative_path) end |
#load(relative_path) ⇒ Object
49 50 51 52 |
# File 'lib/gitload/config.rb', line 49 def load relative_path file = data_file relative_path File.exist?(file) ? JSON.parse(File.read(file)) : nil end |
#load_or_cache_data(relative_path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gitload/config.rb', line 31 def load_or_cache_data relative_path delete relative_path if @clear_cache if @cache data = self.load relative_path end unless data data = yield end if @cache save relative_path, data end data end |
#save(relative_path, contents) ⇒ Object
54 55 56 57 58 |
# File 'lib/gitload/config.rb', line 54 def save relative_path, contents file = data_file relative_path FileUtils.mkdir_p File.dirname(file) File.open(file, 'w'){ |f| f.write JSON.dump(contents) } end |