soup 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ spec = Gem::Specification.new do |s|
21
21
 
22
22
  # Change these as appropriate
23
23
  s.name = "soup"
24
- s.version = "1.0.1"
24
+ s.version = "1.0.2"
25
25
  s.summary = "A super-simple data store"
26
26
  s.author = "James Adam"
27
27
  s.email = "james@lazyatom.com"
@@ -60,8 +60,8 @@ end
60
60
 
61
61
  task :package => :gemspec
62
62
 
63
- desc 'Release the gem to gemcutter and tag the repo'
64
- task :release => [:gemspec, :package] do
63
+ desc 'Tag the repository in git with gem version number'
64
+ task :tag => [:gemspec, :package] do
65
65
  if `git diff --cached`.empty?
66
66
  if `git tag`.split("\n").include?("v#{spec.version}")
67
67
  raise "Version #{spec.version} has already been released"
@@ -69,12 +69,18 @@ task :release => [:gemspec, :package] do
69
69
  `git add #{File.expand_path("../#{spec.name}.gemspec", __FILE__)}`
70
70
  `git commit -m "Released version #{spec.version}"`
71
71
  `git tag v#{spec.version}`
72
- `gem push pkg/#{spec.name}-#{spec.version}.gem`
72
+ `git push --tags`
73
+ `git push`
73
74
  else
74
75
  raise "Unstaged changes still waiting to be committed"
75
76
  end
76
77
  end
77
78
 
79
+ desc 'Release the gem to gemcutter and tag the repo'
80
+ task :release => [:tag] do
81
+ `gem push pkg/#{spec.name}-#{spec.version}.gem`
82
+ end
83
+
78
84
  # Generate documentation
79
85
  Rake::RDocTask.new do |rd|
80
86
  rd.main = "README"
@@ -21,10 +21,11 @@ class Soup
21
21
  default_attributes = {:name => name, :updated_at => file.mtime, :created_at => file.mtime}
22
22
  if attribute_start = data.index("\n:")
23
23
  content = data[0, attribute_start].strip
24
- attributes = default_attributes.merge(YAML.load(data[attribute_start, data.length]).merge(:content => content))
24
+ attributes = default_attributes.merge(YAML.load(data[attribute_start, data.length]))
25
25
  else
26
- attributes = default_attributes.merge(:content => data)
26
+ attributes = default_attributes
27
27
  end
28
+ attributes.update(:content => content) if content && content.length > 0
28
29
  Snip.new(attributes, self)
29
30
  else
30
31
  nil
@@ -21,10 +21,11 @@ class Soup
21
21
  file = File.read(path)
22
22
  if attribute_start = file.index(ATTRIBUTE_TOKEN)
23
23
  content = file.slice(0...attribute_start)
24
- attributes = {:name => name}.merge(YAML.load(file.slice(attribute_start..-1)).merge(:content => content))
24
+ attributes = {:name => name}.merge(YAML.load(file.slice(attribute_start..-1)))
25
25
  else
26
26
  attributes = {:content => file, :name => name}
27
27
  end
28
+ attributes.update(:content => content) if content && content.length > 0
28
29
  Snip.new(attributes, self)
29
30
  else
30
31
  nil
@@ -1,6 +1,6 @@
1
1
  # Based on Builder's BlankSlate object
2
2
  class Soup
3
3
  class EmptyClass
4
- instance_methods.each { |m| undef_method(m) unless m =~ /^(__|object_id|instance_eval|respond_to\?)/ }
4
+ instance_methods.each { |m| undef_method(m) unless m =~ /^(is_a\?|__|object_id|instance_eval|respond_to\?)/ }
5
5
  end
6
6
  end
@@ -19,8 +19,15 @@ class Soup
19
19
  self
20
20
  end
21
21
 
22
+ def ==(other)
23
+ other.is_a?(Snip) && matching_attributes(other)
24
+ end
25
+
22
26
  def inspect
23
- "<Snip name:#{self.name}>"
27
+ keys = @attributes.keys.dup
28
+ keys.delete(:name)
29
+ attrs = keys.inject([[:name, self.name]]) { |a, key| a + [[key, @attributes[key]]] }
30
+ "<Snip #{attrs.map { |(key,value)| "#{key}:#{value.inspect}"}.join(" ")}>"
24
31
  end
25
32
 
26
33
  def respond_to?(method)
@@ -35,5 +42,17 @@ class Soup
35
42
  @attributes[method]
36
43
  end
37
44
  end
45
+
46
+ private
47
+
48
+ def matching_attributes(other)
49
+ my_attributes = self.attributes.dup
50
+ their_attributes = other.attributes.dup
51
+ [:created_at, :updated_at].each do |attribute_to_ignore|
52
+ my_attributes.delete(attribute_to_ignore)
53
+ their_attributes.delete(attribute_to_ignore)
54
+ end
55
+ my_attributes == their_attributes
56
+ end
38
57
  end
39
58
  end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class SnipTest < Test::Unit::TestCase
4
+ context "A snip" do
5
+ setup do
6
+ @snip = Soup::Snip.new({:name => "james", :content => "is awesome"}, nil)
7
+ end
8
+
9
+ should "be equal to another snip with the same attributes" do
10
+ other_snip = Soup::Snip.new({:name => "james", :content => "is awesome"}, nil)
11
+ assert other_snip == @snip
12
+ end
13
+
14
+ should "not be equal to another snip with differing attributes" do
15
+ other_snip = Soup::Snip.new({:name => "james", :content => "is really awesome"}, nil)
16
+ assert other_snip != @snip
17
+ end
18
+
19
+ should "be comparable in arrays" do
20
+ other_snip = Soup::Snip.new({:name => "james", :content => "is awesome"}, nil)
21
+ assert [@snip] == [other_snip]
22
+ end
23
+
24
+ context "loaded from the soup" do
25
+ setup do
26
+ @base_path = File.join(File.dirname(__FILE__), *%w[.. tmp soup])
27
+ backend = Soup::Backends::FileBackend.new(@base_path)
28
+ @soup = Soup.new(backend)
29
+ end
30
+
31
+ teardown do
32
+ FileUtils.rm_rf(@base_path)
33
+ end
34
+
35
+ should "ignore empty content when comparing" do
36
+ @soup << {:name => 'test'}
37
+ assert_equal Soup::Snip.new({:name => 'test'}, nil), @soup['test']
38
+ end
39
+ end
40
+ end
41
+ end
@@ -17,12 +17,12 @@ class SoupTest < Test::Unit::TestCase
17
17
  teardown do
18
18
  FileUtils.rm_rf(base_path)
19
19
  end
20
- yield backend
20
+ yield
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
- each_backend do |backend|
25
+ each_backend do
26
26
  should "be able to store content" do
27
27
  @soup << {:name => 'test', :content => "I like stuff, and things"}
28
28
  assert_equal "I like stuff, and things", @soup['test'].content
@@ -48,7 +48,7 @@ class SoupTest < Test::Unit::TestCase
48
48
  end
49
49
 
50
50
  should "match using all parameters" do
51
- assert_equal @james, @soup[:powers => 'yes', :colour => 'red']
51
+ assert_equal [@murray], @soup[:powers => 'yes', :colour => 'red']
52
52
  end
53
53
 
54
54
  should "return an array if more than one snip matches" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soup
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Adam
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 +00:00
18
+ date: 2010-11-30 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,6 +46,7 @@ files:
46
46
  - README
47
47
  - test/file_backend_test.rb
48
48
  - test/multi_soup_backend_test.rb
49
+ - test/snip_test.rb
49
50
  - test/soup_test.rb
50
51
  - test/test_helper.rb
51
52
  - lib/soup/backends/base.rb