fauxsql 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +44 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/fauxsql.gemspec +68 -0
- data/lib/fauxsql/attribute.rb +10 -0
- data/lib/fauxsql/attribute_list.rb +35 -0
- data/lib/fauxsql/attribute_map.rb +32 -0
- data/lib/fauxsql/dereferenced_attribute.rb +25 -0
- data/lib/fauxsql/dsl.rb +53 -0
- data/lib/fauxsql.rb +70 -0
- data/test/helper.rb +17 -0
- data/test/test_fauxsql.rb +127 -0
- metadata +127 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Collin Miller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= fauxsql
|
2
|
+
|
3
|
+
It's a little api for DataMapper records.
|
4
|
+
|
5
|
+
class FauxSqlObject
|
6
|
+
include DataMapper::Resource
|
7
|
+
include Fauxsql
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
end
|
11
|
+
|
12
|
+
Fauxsql adds its own property.
|
13
|
+
|
14
|
+
property :fauxsql_attributes, Object
|
15
|
+
|
16
|
+
To specify the specific fauxsql attributes use this api:
|
17
|
+
|
18
|
+
attribute :secret_power
|
19
|
+
|
20
|
+
If you want to have an attribute that is an Array or a Hash, use these:
|
21
|
+
|
22
|
+
list :awesome_things
|
23
|
+
map :dictionary
|
24
|
+
|
25
|
+
That's the basics. Under the hood most of the serializing/deserializing
|
26
|
+
is left up to DataMapper. However, Fauxsql steps in for special cases.
|
27
|
+
|
28
|
+
Right now the only special case is when you set a DataMapper record as an
|
29
|
+
attribute, member of a list, key in a map, or a value in a map. In this case
|
30
|
+
Fauxsql transparently wraps the record in a DereferencedAttribute class.
|
31
|
+
|
32
|
+
== Note on Patches/Pull Requests
|
33
|
+
|
34
|
+
* Fork the project.
|
35
|
+
* Make your feature addition or bug fix.
|
36
|
+
* Add tests for it. This is important so I don't break it in a
|
37
|
+
future version unintentionally.
|
38
|
+
* Commit, do not mess with rakefile, version, or history.
|
39
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
40
|
+
* Send me a pull request. Bonus points for topic branches.
|
41
|
+
|
42
|
+
== Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2010 Collin Miller. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "fauxsql"
|
8
|
+
gem.summary = %Q{This is summary}
|
9
|
+
gem.description = %Q{And description}
|
10
|
+
gem.email = "collintmiller@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/collin/fauxsql"
|
12
|
+
gem.authors = ["Collin Miller"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
gem.add_dependency "datamapper"
|
15
|
+
gem.add_dependency "do_sqlite3"
|
16
|
+
gem.add_dependency "activesupport", ">= 3.0.pre"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/test_*.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "fauxsql #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/fauxsql.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fauxsql}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Collin Miller"]
|
12
|
+
s.date = %q{2010-04-20}
|
13
|
+
s.description = %q{And description}
|
14
|
+
s.email = %q{collintmiller@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"fauxsql.gemspec",
|
27
|
+
"lib/fauxsql.rb",
|
28
|
+
"lib/fauxsql/attribute.rb",
|
29
|
+
"lib/fauxsql/attribute_list.rb",
|
30
|
+
"lib/fauxsql/attribute_map.rb",
|
31
|
+
"lib/fauxsql/dereferenced_attribute.rb",
|
32
|
+
"lib/fauxsql/dsl.rb",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/test_fauxsql.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/collin/fauxsql}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.6}
|
40
|
+
s.summary = %q{This is summary}
|
41
|
+
s.test_files = [
|
42
|
+
"test/helper.rb",
|
43
|
+
"test/test_fauxsql.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<datamapper>, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<do_sqlite3>, [">= 0"])
|
54
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.pre"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<datamapper>, [">= 0"])
|
58
|
+
s.add_dependency(%q<do_sqlite3>, [">= 0"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.pre"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
s.add_dependency(%q<datamapper>, [">= 0"])
|
64
|
+
s.add_dependency(%q<do_sqlite3>, [">= 0"])
|
65
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.pre"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Fauxsql
|
2
|
+
# Attribute is a mixin for AttributeList and AttributeMap classes.
|
3
|
+
# It should be mixed into classes that inherit standard Ruby data structures
|
4
|
+
module Attribute
|
5
|
+
def initialize(record, name)
|
6
|
+
super() # explicitly super without arguments to preserve base behavior
|
7
|
+
record.fauxsql_attributes[name] = self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fauxsql
|
2
|
+
# AttributeList is an Array that dereferences and resolves fauxsql attributes
|
3
|
+
# when setting/reading members in the Array
|
4
|
+
class AttributeList < Array
|
5
|
+
include Attribute
|
6
|
+
|
7
|
+
def <<(attribute)
|
8
|
+
super Fauxsql.dereference_fauxsql_attribute(attribute)
|
9
|
+
end
|
10
|
+
|
11
|
+
def [] index
|
12
|
+
Fauxsql.resolve_fauxsql_attribute super(index)
|
13
|
+
end
|
14
|
+
|
15
|
+
def first
|
16
|
+
self[0]
|
17
|
+
end
|
18
|
+
|
19
|
+
def last
|
20
|
+
self[length - 1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def equals list
|
24
|
+
map_resolved == list
|
25
|
+
end
|
26
|
+
|
27
|
+
def map_resolved
|
28
|
+
map = []
|
29
|
+
each_with_index do |item, index|
|
30
|
+
map[index] = self[index]
|
31
|
+
end
|
32
|
+
map
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fauxsql
|
2
|
+
# AttributeMap is an Hash that dereferences and resolves fauxsql attributes
|
3
|
+
# when setting/reading members in the Hash
|
4
|
+
class AttributeMap < Hash
|
5
|
+
include Attribute
|
6
|
+
|
7
|
+
# We dereference and resolve the key because in Ruby _any_ object
|
8
|
+
# can be a hash key. Even a DataMapper record.
|
9
|
+
def []= key, value
|
10
|
+
real_key = Fauxsql.dereference_fauxsql_attribute(key)
|
11
|
+
real_value = Fauxsql.dereference_fauxsql_attribute(value)
|
12
|
+
super real_key.hash, real_value
|
13
|
+
end
|
14
|
+
|
15
|
+
def [] key
|
16
|
+
real_key = Fauxsql.dereference_fauxsql_attribute(key)
|
17
|
+
Fauxsql.resolve_fauxsql_attribute super(real_key.hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
# VERY VERY SPECIFIC to the marshal dump format.
|
21
|
+
# Probably brittle.
|
22
|
+
def keys
|
23
|
+
super.map do |key|
|
24
|
+
if key.match(/^.+Fauxsql::DereferencedAttribute.+@klass.+@lookup_key.+$/)
|
25
|
+
Fauxsql::DereferencedAttribute.load(key)
|
26
|
+
else
|
27
|
+
key
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Fauxsql
|
2
|
+
# DereferencedAttribute stores objects that quack like DataMapper::Resource
|
3
|
+
# This is the object that Fauxsql stores in the database when a
|
4
|
+
# DataMapper::Resource object is given. This way only the class and the
|
5
|
+
# primary key are stored.
|
6
|
+
class DereferencedAttribute
|
7
|
+
def initialize(attribute)
|
8
|
+
@klass = attribute.class
|
9
|
+
@lookup_key = attribute.key
|
10
|
+
end
|
11
|
+
|
12
|
+
def resolve
|
13
|
+
@klass.get(*@lookup_key)
|
14
|
+
end
|
15
|
+
|
16
|
+
def dump
|
17
|
+
Marshal.dump(self)
|
18
|
+
end
|
19
|
+
alias hash dump
|
20
|
+
|
21
|
+
def self.load(dump)
|
22
|
+
Marshal.load(dump)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/fauxsql/dsl.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Fauxsql
|
2
|
+
module DSL
|
3
|
+
# DSL method to define a named Fauxsql attribute
|
4
|
+
#
|
5
|
+
# calling with 'power' is like writing:
|
6
|
+
# def power
|
7
|
+
# get_fauxsql_attribute(:power)
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def power=(value)
|
11
|
+
# set_fauxsql_attribute(:power, value)
|
12
|
+
# end
|
13
|
+
def attribute(attribute_name)
|
14
|
+
class_eval <<EORUBY
|
15
|
+
def #{attribute_name}
|
16
|
+
get_fauxsql_attribute(:#{attribute_name})
|
17
|
+
end
|
18
|
+
|
19
|
+
def #{attribute_name}=(value)
|
20
|
+
set_fauxsql_attribute(:#{attribute_name}, value)
|
21
|
+
end
|
22
|
+
EORUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
# DSL method to define a named Fauxsql list
|
26
|
+
#
|
27
|
+
# calling with 'squad_members' is like writing:
|
28
|
+
# def squad_members
|
29
|
+
# get_fauxsql_list(:squad_members)
|
30
|
+
# end
|
31
|
+
def list(attribute_name)
|
32
|
+
class_eval <<EORUBY
|
33
|
+
def #{attribute_name}
|
34
|
+
get_fauxsql_list(:#{attribute_name})
|
35
|
+
end
|
36
|
+
EORUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
# DSL method to define a named Fauxsql map
|
40
|
+
#
|
41
|
+
# calling with 'mitigates' is like writing:
|
42
|
+
# def mitigates
|
43
|
+
# get_fauxsql_map(:mitigates)
|
44
|
+
# end
|
45
|
+
def map(attribute_name)
|
46
|
+
class_eval <<EORUBY
|
47
|
+
def #{attribute_name}
|
48
|
+
get_fauxsql_map(:#{attribute_name})
|
49
|
+
end
|
50
|
+
EORUBY
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/fauxsql.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Libs
|
2
|
+
require 'active_support/concern'
|
3
|
+
require 'datamapper'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
# Internal Libs
|
7
|
+
root = Pathname.new(__FILE__).dirname.expand_path
|
8
|
+
require root+'fauxsql/dereferenced_attribute'
|
9
|
+
require root+'fauxsql/attribute'
|
10
|
+
require root+'fauxsql/attribute_list'
|
11
|
+
require root+'fauxsql/attribute_map'
|
12
|
+
require root+'fauxsql/dsl'
|
13
|
+
module Fauxsql
|
14
|
+
extend ActiveSupport::Concern
|
15
|
+
|
16
|
+
included do
|
17
|
+
property :fauxsql_attributes, Object, :default => {}
|
18
|
+
extend Fauxsql::DSL
|
19
|
+
end
|
20
|
+
|
21
|
+
# Getter method for attributes defined as:
|
22
|
+
# attribute :attribute_name
|
23
|
+
def get_fauxsql_attribute(attribute_name)
|
24
|
+
attribute = fauxsql_attributes[attribute_name]
|
25
|
+
Fauxsql.resolve_fauxsql_attribute(attribute)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Setter method for attributes defined as:
|
29
|
+
# attribute :attribute_name
|
30
|
+
def set_fauxsql_attribute(attribute_name, value)
|
31
|
+
attribute = Fauxsql.dereference_fauxsql_attribute(value)
|
32
|
+
fauxsql_attributes[attribute_name] = attribute
|
33
|
+
end
|
34
|
+
|
35
|
+
# Gets a reference to an AttributeList object. AttributeList quacks like
|
36
|
+
# a Ruby Array. Except it uses Fauxsql's dereference and resolve strategy to
|
37
|
+
# store members.
|
38
|
+
def get_fauxsql_list(list_name)
|
39
|
+
fauxsql_attributes[list_name] or AttributeList.new(self, list_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Gets a reference to an AttributeMap object. AttributeMap quacks like
|
43
|
+
# a Ruby Hash. Except it uses Fauxsql's dereference and resolve strategy to
|
44
|
+
# store keys and values.
|
45
|
+
def get_fauxsql_map(map_name)
|
46
|
+
fauxsql_attributes[map_name] or AttributeMap.new(self, map_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
# When setting values, all attributes pass through this method.
|
50
|
+
# This way we can control how certain classes are serialized by Fauxsql
|
51
|
+
# See #resolve_fauxsql_attribute to see how attributes are read.
|
52
|
+
def self.dereference_fauxsql_attribute(attribute)
|
53
|
+
if attribute.is_a?(DataMapper::Resource)
|
54
|
+
DereferencedAttribute.new(attribute)
|
55
|
+
else
|
56
|
+
attribute
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# When reading values, all attributes pass through this method.
|
61
|
+
# This way we can control how certain classes are deserialized by Fauxsql
|
62
|
+
# See #dereference_fauxsql_attribute to see how attributes are stored.
|
63
|
+
def self.resolve_fauxsql_attribute(attribute)
|
64
|
+
if attribute.is_a?(DereferencedAttribute)
|
65
|
+
attribute.resolve
|
66
|
+
else
|
67
|
+
attribute
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
require 'datamapper'
|
6
|
+
DataMapper.setup(:default, "sqlite3://:memory:")
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require 'fauxsql'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
def reload
|
14
|
+
@faux.save
|
15
|
+
@faux.reload
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class SimpleKey
|
4
|
+
include DataMapper::Resource
|
5
|
+
property :id, Serial
|
6
|
+
end
|
7
|
+
|
8
|
+
class ComplexKey
|
9
|
+
include DataMapper::Resource
|
10
|
+
property :string, String, :key => true
|
11
|
+
property :integer, Integer, :key => true
|
12
|
+
end
|
13
|
+
|
14
|
+
class FauxObject
|
15
|
+
include DataMapper::Resource
|
16
|
+
include Fauxsql
|
17
|
+
|
18
|
+
property :id, Serial
|
19
|
+
property :type, Discriminator
|
20
|
+
attribute :name
|
21
|
+
attribute :record
|
22
|
+
list :things
|
23
|
+
map :dictionary
|
24
|
+
end
|
25
|
+
|
26
|
+
class OtherFauxObject < FauxObject; end
|
27
|
+
|
28
|
+
class TestFauxsql < Test::Unit::TestCase
|
29
|
+
context "A FauxObject" do
|
30
|
+
setup do
|
31
|
+
DataMapper.auto_migrate!
|
32
|
+
@faux = FauxObject.new
|
33
|
+
end
|
34
|
+
|
35
|
+
should "have getters and setters for attributes" do
|
36
|
+
assert @faux.respond_to?(:name)
|
37
|
+
assert @faux.respond_to?(:name=)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "have getter for lists" do
|
41
|
+
assert @faux.respond_to?(:things)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "have getters and setters for maps" do
|
45
|
+
assert @faux.respond_to?(:dictionary)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "persist attributes" do
|
49
|
+
@faux.name = "MyName"
|
50
|
+
reload
|
51
|
+
assert_equal "MyName", @faux.name
|
52
|
+
end
|
53
|
+
|
54
|
+
should "persist lists" do
|
55
|
+
@faux.things << :hello
|
56
|
+
@faux.things << :goodbye
|
57
|
+
reload
|
58
|
+
assert_equal [:hello, :goodbye], @faux.things
|
59
|
+
end
|
60
|
+
|
61
|
+
should "persist maps" do
|
62
|
+
@faux.dictionary[:a] = 1
|
63
|
+
@faux.dictionary[:b] = 2
|
64
|
+
reload
|
65
|
+
assert_equal 1, @faux.dictionary[:a]
|
66
|
+
assert_equal 2, @faux.dictionary[:b]
|
67
|
+
end
|
68
|
+
|
69
|
+
should "dereference and resolve objects that include Fauxsql" do
|
70
|
+
has_fauxsql = OtherFauxObject.create
|
71
|
+
@faux.record = has_fauxsql
|
72
|
+
reload
|
73
|
+
assert_equal has_fauxsql, @faux.record
|
74
|
+
end
|
75
|
+
|
76
|
+
should "dereference and resolve dm objects with simple keys" do
|
77
|
+
simple_key = SimpleKey.create
|
78
|
+
@faux.record = simple_key
|
79
|
+
reload
|
80
|
+
assert @faux.fauxsql_attributes[:record].is_a?(Fauxsql::DereferencedAttribute)
|
81
|
+
assert_equal simple_key, @faux.record
|
82
|
+
end
|
83
|
+
|
84
|
+
should "deference and resolve dm objects with complex keys" do
|
85
|
+
complex_key = ComplexKey.create(:string => "string", :integer => 1)
|
86
|
+
@faux.record = complex_key
|
87
|
+
reload
|
88
|
+
assert @faux.fauxsql_attributes[:record].is_a?(Fauxsql::DereferencedAttribute)
|
89
|
+
assert_equal complex_key, @faux.record
|
90
|
+
end
|
91
|
+
|
92
|
+
should "derefencenc and resolve dm objects in lists" do
|
93
|
+
simple = SimpleKey.create
|
94
|
+
@faux.things << :hello
|
95
|
+
@faux.things << simple
|
96
|
+
@faux.things << :goodbye
|
97
|
+
reload
|
98
|
+
assert_equal [:hello, simple, :goodbye], @faux.things.map_resolved
|
99
|
+
end
|
100
|
+
|
101
|
+
should "derefencenc and resolve fauxsql objects in lists" do
|
102
|
+
has_fauxsql = OtherFauxObject.create
|
103
|
+
@faux.things << :hello
|
104
|
+
@faux.things << has_fauxsql
|
105
|
+
@faux.things << :goodbye
|
106
|
+
reload
|
107
|
+
assert_equal [:hello, has_fauxsql, :goodbye], @faux.things.map_resolved
|
108
|
+
end
|
109
|
+
|
110
|
+
should "derference and resolve dm objects with fauxsql in maps" do
|
111
|
+
has_fauxsql1 = OtherFauxObject.create
|
112
|
+
has_fauxsql2 = OtherFauxObject.create
|
113
|
+
@faux.dictionary[has_fauxsql1] = has_fauxsql2
|
114
|
+
reload
|
115
|
+
assert_equal has_fauxsql2, @faux.dictionary[has_fauxsql1]
|
116
|
+
end
|
117
|
+
|
118
|
+
should "derference and resolve dm objects in maps" do
|
119
|
+
simple1 = SimpleKey.create
|
120
|
+
simple2 = SimpleKey.create
|
121
|
+
@faux.dictionary[simple1] = simple2
|
122
|
+
assert_equal Fauxsql::DereferencedAttribute, @faux.dictionary.keys.first.class
|
123
|
+
reload
|
124
|
+
assert_equal simple2, @faux.dictionary[simple1]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fauxsql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Collin Miller
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-20 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: datamapper
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: do_sqlite3
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activesupport
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 3
|
65
|
+
- 0
|
66
|
+
- pre
|
67
|
+
version: 3.0.pre
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id004
|
70
|
+
description: And description
|
71
|
+
email: collintmiller@gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE
|
78
|
+
- README.rdoc
|
79
|
+
files:
|
80
|
+
- .document
|
81
|
+
- .gitignore
|
82
|
+
- LICENSE
|
83
|
+
- README.rdoc
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
86
|
+
- fauxsql.gemspec
|
87
|
+
- lib/fauxsql.rb
|
88
|
+
- lib/fauxsql/attribute.rb
|
89
|
+
- lib/fauxsql/attribute_list.rb
|
90
|
+
- lib/fauxsql/attribute_map.rb
|
91
|
+
- lib/fauxsql/dereferenced_attribute.rb
|
92
|
+
- lib/fauxsql/dsl.rb
|
93
|
+
- test/helper.rb
|
94
|
+
- test/test_fauxsql.rb
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://github.com/collin/fauxsql
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options:
|
101
|
+
- --charset=UTF-8
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.3.6
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: This is summary
|
125
|
+
test_files:
|
126
|
+
- test/helper.rb
|
127
|
+
- test/test_fauxsql.rb
|