Class: FakeFlorence::FeatureCache

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_florence/feature_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FeatureCache

Returns a new instance of FeatureCache.



7
8
9
10
11
# File 'lib/fake_florence/feature_cache.rb', line 7

def initialize(path)
  @root = path.join('features')
  @root.mkpath
  @callbacks = []
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/fake_florence/feature_cache.rb', line 5

def root
  @root
end

Instance Method Details

#announce_all_nowObject



30
31
32
33
34
35
36
37
38
# File 'lib/fake_florence/feature_cache.rb', line 30

def announce_all_now
  names = []

  Announcers.load(Config.announce).each do |announcer|
    names.push(announcer.name) if announcer.announce(noop: features)
  end

  { features: features.size, announcers: names }
end

#feature(id) ⇒ Object



17
18
19
# File 'lib/fake_florence/feature_cache.rb', line 17

def feature(id)
  Feature.read(id, id_to_file(id))
end

#featuresObject



13
14
15
# File 'lib/fake_florence/feature_cache.rb', line 13

def features
  Dir.glob(@root.join('*.yaml')).map(&method(:file_to_feature))
end

#id_to_file(id) ⇒ Object



26
27
28
# File 'lib/fake_florence/feature_cache.rb', line 26

def id_to_file(id)
  @root.join("#{id}.yaml")
end

#register_listener(&block) ⇒ Object



21
22
23
24
# File 'lib/fake_florence/feature_cache.rb', line 21

def register_listener(&block)
  @callbacks.push(block)
  listen_for_changes unless @listener
end