Class: TddiumStatus::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tddium_status/configuration.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = self.class.default_path) ⇒ Configuration

Returns a new instance of Configuration.



5
6
7
8
# File 'lib/tddium_status/configuration.rb', line 5

def initialize(path = self.class.default_path)
  @path = path
  @lock = Mutex.new
end

Class Method Details

.default_pathObject



39
40
41
# File 'lib/tddium_status/configuration.rb', line 39

def self.default_path
  File.join(Dir.home, '.tddium_status.yml')
end

Instance Method Details

#feedsObject



10
11
12
13
14
# File 'lib/tddium_status/configuration.rb', line 10

def feeds
  @feeds ||= transaction do |data|
    data[:feeds] ||= []
  end
end

#feeds=(feeds) ⇒ Object



16
17
18
19
20
# File 'lib/tddium_status/configuration.rb', line 16

def feeds=(feeds)
  transaction do |data|
    data[:feeds] = feeds || []
  end
end

#save_feed(feed) ⇒ Object



22
23
24
25
26
# File 'lib/tddium_status/configuration.rb', line 22

def save_feed(feed)
  feeds = self.feeds
  feeds << feed unless feeds.include?(feed)
  self.feeds = feeds
end

#transaction(&block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/tddium_status/configuration.rb', line 28

def transaction(&block)
  @lock.synchronize do
    data = YAML.load(File.read(@path)) rescue {}
    result = block.call(data)
    File.open(@path, "w") do |f|
      f.write(YAML.dump(data))
    end
    result
  end
end