soup 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ lib/active_record_tuple.rb
2
+ lib/data_mapper_tuple.rb
3
+ lib/sequel_tuple.rb
4
+ lib/snip.rb
5
+ lib/soup.rb
6
+ README
7
+ spec/snip_spec.rb
8
+ spec/soup_test.rb
9
+ spec/spec_runner.rb
10
+ Manifest
data/README CHANGED
@@ -1,5 +1,5 @@
1
- Soup is a bit of everything, summoned from nothing. Soup is like an imaginary friend - comforting,
2
- and will often talk to you, but when you look closely, they don't exist.
1
+ Soup is a bit of everything, summoned from nothing. Soup is like an imaginary friend - comforting,
2
+ and will often talk to you, but when you look closely, they don't exist.
3
3
 
4
4
  Terrifying. And so:
5
5
 
@@ -1,7 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'activerecord'
3
3
 
4
- class Tuple < ActiveRecord::Base
4
+ class ActiveRecordTuple < ActiveRecord::Base
5
+ set_table_name :tuples
6
+
5
7
  def self.prepare_database(config)
6
8
  ActiveRecord::Base.establish_connection(config)
7
9
  return if connection.tables.include?("tuples")
@@ -4,7 +4,7 @@ require 'data_mapper'
4
4
  # This tuple implementation is broken - there's a weird interaction
5
5
  # where values are not set within the web application.
6
6
  #
7
- class Tuple < DataMapper::Base
7
+ class DataMapperTuple < DataMapper::Base
8
8
 
9
9
  property :snip_id, :integer
10
10
 
@@ -3,7 +3,7 @@ require 'sequel'
3
3
 
4
4
  DB = Sequel.sqlite 'soup_development.db'
5
5
 
6
- class Tuple < Sequel::Model(:tuples)
6
+ class SequelTuple < Sequel::Model(:tuples)
7
7
  set_schema do
8
8
  primary_key :id
9
9
  integer :snip_id
@@ -20,7 +20,7 @@ class Snip < EmptyClass
20
20
  # Returns the snip with the given name (i.e. the snip with the tuple of "name" -> name)
21
21
  #
22
22
  def self.[](name)
23
- tuples = Tuple.all_for_snip_named(name)
23
+ tuples = Soup.tuple_class.all_for_snip_named(name)
24
24
  snip = Snip.new(:__id => tuples.first.snip_id)
25
25
  snip.replace_tuples(tuples)
26
26
  snip
@@ -36,7 +36,7 @@ class Snip < EmptyClass
36
36
  # should return all Snips who have a 'created_at' value greater than '2007-01-01'.
37
37
  #
38
38
  def self.with(name, tuple_value_conditions=nil)
39
- matching_tuples = Tuple.find_matching(name, tuple_value_conditions)
39
+ matching_tuples = Soup.tuple_class.find_matching(name, tuple_value_conditions)
40
40
  matching_tuples.map { |t| t.snip_id }.uniq.map { |snip_id| find(snip_id) }
41
41
  end
42
42
 
@@ -44,7 +44,7 @@ class Snip < EmptyClass
44
44
  # with the matching snip_id, gathered into a magical snip.)
45
45
  #
46
46
  def self.find(id)
47
- raise "not found" unless (tuples = Tuple.for_snip(id)).any?
47
+ raise "not found" unless (tuples = Soup.tuple_class.for_snip(id)).any?
48
48
  snip = Snip.new(:__id => id)
49
49
  snip.replace_tuples(tuples)
50
50
  snip
@@ -75,7 +75,7 @@ class Snip < EmptyClass
75
75
 
76
76
  def reload
77
77
  return self unless self.id
78
- replace_tuples(Tuple.for_snip(id))
78
+ replace_tuples(Soup.tuple_class.for_snip(id))
79
79
  self
80
80
  end
81
81
 
@@ -123,7 +123,7 @@ class Snip < EmptyClass
123
123
 
124
124
  def set_id_if_necessary
125
125
  if self.id.nil?
126
- set_id(Tuple.next_snip_id)
126
+ set_id(Soup.tuple_class.next_snip_id)
127
127
  @tuples.values.each { |tuple| tuple.snip_id = self.id }
128
128
  end
129
129
  end
@@ -142,7 +142,7 @@ class Snip < EmptyClass
142
142
  tuple.value = value
143
143
  else
144
144
  attributes = {:snip_id => self.id, :name => name.to_s, :value => value}
145
- tuple = @tuples[name.to_s] = Tuple.new(attributes)
145
+ tuple = @tuples[name.to_s] = Soup.tuple_class.new(attributes)
146
146
  end
147
147
  tuple.value
148
148
  end
@@ -1,7 +1,7 @@
1
1
  require 'snip'
2
2
 
3
3
  module Soup
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
 
6
6
  DEFAULT_CONFIG = {
7
7
  :adapter => 'sqlite3',
@@ -27,9 +27,20 @@ module Soup
27
27
  @tuple_implementation = "#{tuple_implementation}_tuple"
28
28
  end
29
29
 
30
+ def self.tuple_class
31
+ @tuple_class ||= case @tuple_implementation
32
+ when "active_record_tuple", nil
33
+ ActiveRecordTuple
34
+ when "data_mapper_tuple"
35
+ DataMapperTuple
36
+ when "sequel_tuple"
37
+ SequelTuple
38
+ end
39
+ end
40
+
30
41
  # Get the soup ready!
31
42
  def self.prepare
32
43
  require @tuple_implementation || DEFAULT_TUPLE_IMPLEMENTATION
33
- Tuple.prepare_database(DEFAULT_CONFIG.merge(@database_config || {}))
44
+ tuple_class.prepare_database(DEFAULT_CONFIG.merge(@database_config || {}))
34
45
  end
35
46
  end
@@ -0,0 +1,56 @@
1
+
2
+ # Gem::Specification for Soup-0.1.4
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{soup}
7
+ s.version = "0.1.4"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["James Adam"]
13
+ s.date = %q{2008-03-11}
14
+ s.description = %q{Soup is a bit of everything, summoned from nothing. Soup is like an imaginary friend - comforting,}
15
+ s.email = ["james@lazyatom.com"]
16
+ s.files = ["lib/active_record_tuple.rb", "lib/data_mapper_tuple.rb", "lib/sequel_tuple.rb", "lib/snip.rb", "lib/soup.rb", "README", "spec/snip_spec.rb", "spec/soup_test.rb", "spec/spec_runner.rb", "Manifest", "soup.gemspec"]
17
+ s.has_rdoc = true
18
+ s.homepage = %q{}
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{soup}
21
+ s.rubygems_version = %q{0.9.5}
22
+ s.summary = %q{Soup is a bit of everything, summoned from nothing. Soup is like an imaginary friend - comforting,}
23
+ end
24
+
25
+
26
+ # # Original Rakefile source (requires the Echoe gem):
27
+ #
28
+ # require 'rubygems'
29
+ # #require 'rake/gempackagetask'
30
+ #
31
+ # require 'lib/soup'
32
+ #
33
+ # begin
34
+ # require 'echoe'
35
+ #
36
+ # Echoe.new("soup", Soup::VERSION) do |soup|
37
+ # soup.author = ["James Adam"]
38
+ # soup.email = ["james@lazyatom.com"]
39
+ # soup.description = File.readlines("README").first
40
+ # end
41
+ #
42
+ # rescue LoadError
43
+ # puts "You need to install the echoe gem to perform meta operations on this gem"
44
+ # end
45
+ #
46
+ # desc "Open an irb session preloaded with this library"
47
+ # task :console do
48
+ # sh "irb -rubygems -r ./lib/soup.rb"
49
+ # end
50
+ #
51
+ # # We have to run our own spec runner, because Snip will try to undefine
52
+ # # rspec's should methods using the default one
53
+ # task(:test) do
54
+ # files = FileList['spec/**/*_spec.rb']
55
+ # system "ruby spec/spec_runner.rb #{files} --format specdoc"
56
+ # end
@@ -0,0 +1,46 @@
1
+ Soup.base = {:database => "soup_test.db"}
2
+ Soup.prepare
3
+
4
+ describe Snip, "when newly created" do
5
+ before(:each) { @snip = Snip.new }
6
+
7
+ it "should not have a name" do
8
+ @snip.name.should be_nil
9
+ end
10
+
11
+ it "should return nil for any attributes" do
12
+ @snip.other_attribute.should be_nil
13
+ end
14
+ end
15
+
16
+
17
+ describe Snip, "when setting attributes" do
18
+ before(:each) { @snip = Snip.new }
19
+
20
+ it "should allow setting attributes" do
21
+ @snip.something = "blah"
22
+ @snip.something.should == "blah"
23
+ end
24
+
25
+ it "should not respond to attributes that have not been set" do
26
+ @snip.should_not respond_to(:monkey)
27
+ end
28
+
29
+ it "should respond to attributes that have been set" do
30
+ @snip.monkey = true
31
+ @snip.should respond_to(:monkey)
32
+ end
33
+ end
34
+
35
+ describe Snip, "when saving" do
36
+ before(:each) { @snip = Snip.new }
37
+
38
+ it "should return all attributes when reloading" do
39
+ @snip.name = "something"
40
+ @snip.jazz = "smooth"
41
+ @snip.save
42
+
43
+ other_snip = Snip['something']
44
+ other_snip.jazz.should == "smooth"
45
+ end
46
+ end
Binary file
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # We need to do a bit of extra work here, because Snip will undefine a
4
+ # whole bunch of stuff that spec adds, like the Object#should method.
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+ require 'soup'
7
+
8
+ # This is basically the contents of rspec's own spec runner. It's just
9
+ # that we needed to require 'soup' before it.
10
+ require 'rubygems'
11
+ require 'spec'
12
+ exit ::Spec::Runner::CommandLine.run(rspec_options)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Adam
@@ -13,14 +13,15 @@ date: 2008-03-11 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description:
17
- email: james at lazyatom dot com
16
+ description: Soup is a bit of everything, summoned from nothing. Soup is like an imaginary friend - comforting,
17
+ email:
18
+ - james@lazyatom.com
18
19
  executables: []
19
20
 
20
21
  extensions: []
21
22
 
22
- extra_rdoc_files:
23
- - README
23
+ extra_rdoc_files: []
24
+
24
25
  files:
25
26
  - lib/active_record_tuple.rb
26
27
  - lib/data_mapper_tuple.rb
@@ -28,8 +29,13 @@ files:
28
29
  - lib/snip.rb
29
30
  - lib/soup.rb
30
31
  - README
32
+ - spec/snip_spec.rb
33
+ - spec/soup_test.rb
34
+ - spec/spec_runner.rb
35
+ - Manifest
36
+ - soup.gemspec
31
37
  has_rdoc: true
32
- homepage:
38
+ homepage: ""
33
39
  post_install_message:
34
40
  rdoc_options: []
35
41
 
@@ -49,10 +55,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
55
  version:
50
56
  requirements: []
51
57
 
52
- rubyforge_project:
58
+ rubyforge_project: soup
53
59
  rubygems_version: 0.9.5
54
60
  signing_key:
55
61
  specification_version: 2
56
- summary: A mess of data
62
+ summary: Soup is a bit of everything, summoned from nothing. Soup is like an imaginary friend - comforting,
57
63
  test_files: []
58
64