Module: OldMaid::Instance
- Included in:
- OldMaid
- Defined in:
- lib/old-maid/instance.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #config_file ⇒ Object
- #contracts_fulfilled? ⇒ Boolean
- #env ⇒ Object
- #errors ⇒ Object
- #infrastructure ⇒ Object
- #initialize(options = {}) ⇒ Object
- #update_contracts ⇒ Object
- #update_own_contracts ⇒ Object
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/old-maid/instance.rb', line 11 def config @config end |
Instance Method Details
#cache_dir ⇒ Object
72 73 74 75 76 77 |
# File 'lib/old-maid/instance.rb', line 72 def cache_dir return @cache_dir if @cache_dir full_path = File.(config[:contracts_cache_path]) FileUtils.mkdir_p(full_path) @cache_dir = full_path end |
#config_file ⇒ Object
56 57 58 59 |
# File 'lib/old-maid/instance.rb', line 56 def config_file return File.(@options[:config_file]) if @options[:config_file] File.join(Dir.pwd, 'config', 'old-maid.yml') end |
#contracts_fulfilled? ⇒ Boolean
44 45 46 |
# File 'lib/old-maid/instance.rb', line 44 def contracts_fulfilled? infrastructure.contracts_fulfilled? end |
#env ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/old-maid/instance.rb', line 61 def env return @options[:env].to_sym if @options[:env] if Object.const_defined?('Rails') Rails.env.to_sym else guessed = ENV['RAILS_ENV'] || ENV['RACK_ENV'] raise "No environment given" unless guessed guessed end end |
#errors ⇒ Object
40 41 42 |
# File 'lib/old-maid/instance.rb', line 40 def errors infrastructure.errors end |
#infrastructure ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/old-maid/instance.rb', line 48 def infrastructure @mutex.synchronize do return @infrastructure if @infrastructure @infrastructure = MinimumTerm::Infrastructure.new(data_dir: cache_dir, verbose: verbose?) @infrastructure end end |
#initialize(options = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/old-maid/instance.rb', line 13 def initialize( = {}) @mutex = Mutex.new @options = puts "Using config file #{config_file}" if verbose? end |
#update_contracts ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/old-maid/instance.rb', line 19 def update_contracts i = infrastructure @mutex.synchronize do puts "Updating #{cache_dir}" if verbose? update_other_contracts update_own_contracts i.convert_all! end true end |
#update_own_contracts ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/old-maid/instance.rb', line 30 def update_own_contracts contract_files.each do |file| source_file = File.join(config[:contracts_path], file) target_file = File.join(cache_dir, config[:service_name], file) puts "cp #{source_file} #{target_file}" if verbose? FileUtils.rm_f(target_file) FileUtils.cp(source_file, target_file) if File.exists?(source_file) end end |