Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix yaml adapter on a touched yaml file #14

Closed
wants to merge 7 commits into from

3 participants

@duritong

YAML.load_file returns false on an empty file. So we initialize
the loaded yaml with an empty hash, as on a non existing file.

This is mainly a problem if you are setting up your cache to have correct file permissions etc. and hence touch it before using it for the first time.

duritong and others added some commits
@duritong duritong Fix using yaml adapter with an empty file
YAML.load_file returns `false` on an empty file. So we initialize
the loaded yaml with an empty hash, as on a non existing file.
ab14254
@duritong duritong fix default nil value
fetch will try to execute `default` if the default is nil, but this
should be `value`. Also we need to address that nil is not false.
6ab39f0
@duritong duritong release my very own version 8e74134
@duritong duritong Merge branch 'fix_default' 38125d0
@duritong duritong also increase the version in the Rakefile 73042a1
@icy icy fix monelta.gemspec 01b2cbd
@duritong duritong Merge pull request #1 from icyfork/master
Fix file list in .gemspec
9c29390
@minad
Collaborator

The yaml adapter uses the YAML::Store now

@minad minad closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 1, 2011
  1. @duritong

    Fix using yaml adapter with an empty file

    duritong authored
    YAML.load_file returns `false` on an empty file. So we initialize
    the loaded yaml with an empty hash, as on a non existing file.
Commits on Sep 4, 2011
  1. @duritong

    fix default nil value

    duritong authored
    fetch will try to execute `default` if the default is nil, but this
    should be `value`. Also we need to address that nil is not false.
Commits on Jan 5, 2012
  1. @duritong

    release my very own version

    duritong authored
  2. @duritong

    Merge branch 'fix_default'

    duritong authored
Commits on Jan 17, 2012
  1. @duritong
Commits on May 4, 2012
  1. @icy

    fix monelta.gemspec

    icy authored
Commits on May 10, 2012
  1. @duritong

    Merge pull request #1 from icyfork/master

    duritong authored
    Fix file list in .gemspec
This page is out of date. Refresh to see the latest.
View
4 Rakefile
@@ -5,7 +5,7 @@ require 'spec/rake/spectask'
require 'date'
GEM = "moneta"
-GEM_VERSION = "0.5.0"
+GEM_VERSION = "0.6.1"
AUTHOR = "Yehuda Katz"
EMAIL = "wycats@gmail.com"
HOMEPAGE = "http://www.yehudakatz.com"
@@ -57,4 +57,4 @@ Spec::Rake::SpecTask.new('spec') do |t|
FileList['spec/**/*_spec.rb']
end
end
-end
+end
View
2  lib/moneta.rb
@@ -4,7 +4,7 @@ module Moneta
module Defaults
def fetch(key, value = nil, *)
self[key] || begin
- value ||= block_given? ? yield(key) : default
+ value = block_given? ? yield(key) : value
self[key] || value
end
end
View
2  lib/moneta/adapters/yaml.rb
@@ -42,7 +42,7 @@ def clear(*)
private
def yaml
- ::YAML.load_file(@file)
+ ::YAML.load_file(@file) || {}
end
def save(hash = {})
View
4 moneta.gemspec
@@ -4,7 +4,7 @@
Gem::Specification.new do |s|
s.name = %q{moneta}
- s.version = "0.6.0"
+ s.version = "0.6.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Yehuda Katz"]
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.description = %q{A unified interface to key/value stores}
s.email = %q{wycats@gmail.com}
s.extra_rdoc_files = ["README", "LICENSE", "TODO"]
- s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/moneta", "lib/moneta/datamapper.rb", "lib/moneta/file.rb", "lib/moneta/memcache.rb", "lib/moneta/memory.rb", "lib/moneta/xattr.rb", "lib/moneta.rb"]
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
s.has_rdoc = true
s.homepage = %q{http://www.yehudakatz.com}
s.require_paths = ["lib"]
View
13 spec/moneta_yaml_spec.rb
@@ -2,9 +2,9 @@
begin
require "moneta/adapters/yaml"
+ path = File.expand_path("../yaml_cache", __FILE__)
describe "Moneta::Adapters::YAML" do
- path = File.expand_path("../yaml_cache", __FILE__)
before(:each) do
@cache = Moneta::Builder.new do
@@ -21,5 +21,16 @@
it_should_behave_like "a read/write Moneta cache"
end
end
+
+ describe "Moneta::Adapters::YAML with an existing empty file" do
+ it "should initialize with an empty hash" do
+ require 'fileutils'
+ FileUtils.touch(path)
+ @cache = Moneta::Builder.new do
+ run Moneta::Adapters::YAML, :path => path
+ end
+ lambda { @cache['some_key'] }.should_not raise_error
+ end
+ end
rescue SystemExit
end
View
3  spec/shared.rb
@@ -58,6 +58,9 @@
@cache.key?(key2).should_not be_true
end
+ it "fetches a #{type} key with a default value of nil, if the key is not available" do
+ @cache.fetch(key).should be_nil
+ end
it "fetches a #{type} key with a default value with fetch, if the key is not available" do
@cache.fetch(key, "value").should == "value"
end
Something went wrong with that request. Please try again.