RubyTapas #162 - #166
162 PStore
★
require "pstore"
store = PStore.new("todo.pstore")
lister = store.transaction do |s|
s.roots # => ["lister"]
s.root?("lister")
s.roots
end
read only for optimization
read_only = true
store.transaction(read_only) do |s|
read-only mode, read-write mode
PStore is not a universal persistence solution
163 YAML::Store
★★
pstore - Unfortunately, it's not so easy for us humans to interpret
require "yaml/store"
store = YAML::Store.new("todo.yaml")
YAML::Store has the exact same API as PStore
YAML::Store has turned out to be around an order of magnitude slower than PStore
use YAML::Store by preference
if you find it too slow for your needs, drop in PStore as an optimization
164 Mapper
★
ContentPostGateway class serves to hide the details of screen-scraping DPD
class EpisodeMapper
def each_episode
return to_enum(__callee__) unless block_given?
gw = DPD::ContentPostGateway.new
mapper = EpisodeMapper.new(gw)
mapper.each_episode.take(10)
165 Refactor Tapas::Queue
★
refactoring
We start by copying the #wait_for_condition method into a new class called SpaceAvailableCondition
We also give this class a constructor which saves references to the queue, a mutex lock, and a condition variable
class SpaceAvailableCondition < LogicalCondition
class ItemAvailableCondition < LogicalCondition
166 Not Implemented
★
def condition_holds?
raise NotImplementedError,
NotImplementedError inherits from ScriptError, which in turn inherits directly from Exception
Since it does not inherit from StandardError, ordinary rescue clauses will not capture a NotImplementedError. This is good