rid-core 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README +14 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/rid +4 -0
- data/lib/rid/app.rb +49 -0
- data/lib/rid/attachments.rb +72 -0
- data/lib/rid/commands.rb +63 -0
- data/lib/rid/core_ext/hash.rb +57 -0
- data/lib/rid/database.rb +69 -0
- data/lib/rid/document.rb +99 -0
- data/lib/rid.rb +16 -0
- data/rid-core.gemspec +89 -0
- data/spec/mock_app/_database +1 -0
- data/spec/rid/app_spec.rb +59 -0
- data/spec/rid/attachments_spec.rb +38 -0
- data/spec/rid/commands_spec.rb +14 -0
- data/spec/rid/core_ext/hash_spec.rb +71 -0
- data/spec/rid/database_spec.rb +25 -0
- data/spec/rid/document_spec.rb +36 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +15 -0
- metadata +189 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Johannes J. Schmidt
|
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
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
= Rid
|
2
|
+
|
3
|
+
In the spirit of Ruby on Rails Rid tends on programmers happiness.
|
4
|
+
|
5
|
+
Rid eases the process of building standalone CouchDB applications
|
6
|
+
with tools for deployment, codegenerators and a javascript library.
|
7
|
+
|
8
|
+
This is the rid gem with the CouchDB model and command line
|
9
|
+
infrastructure.
|
10
|
+
|
11
|
+
|
12
|
+
== Copyright
|
13
|
+
|
14
|
+
Copyright (c) 2010 Johannes J. Schmidt. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rid-core"
|
8
|
+
gem.summary = %Q{Rest in development core.}
|
9
|
+
gem.description = %Q{Rid is a toolkit to relax in web development. Based on CouchDB you get a distributed, high scaling web application infrastructure with Rid. This is the Rid core.}
|
10
|
+
gem.email = "schmidt@netzmerk.com"
|
11
|
+
gem.homepage = "http://rid.github.com/rid"
|
12
|
+
gem.authors = ["Johannes J. Schmidt"]
|
13
|
+
|
14
|
+
gem.add_dependency "commander", ">= 4.0.3"
|
15
|
+
gem.add_dependency "filander", ">= 0.6.0"
|
16
|
+
gem.add_dependency "rest-client", ">= 1.5.0"
|
17
|
+
gem.add_dependency "json_pure", ">= 1.4.2"
|
18
|
+
gem.add_dependency "activesupport"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
21
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'spec/rake/spectask'
|
29
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
35
|
+
spec.libs << 'lib' << 'spec'
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :spec => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "rid-core #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.3
|
data/bin/rid
ADDED
data/lib/rid/app.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Rid
|
2
|
+
# Holds Application config
|
3
|
+
#
|
4
|
+
class App
|
5
|
+
attr_reader :db_url, :db
|
6
|
+
attr_accessor :root
|
7
|
+
|
8
|
+
# Initialize app with an options object,
|
9
|
+
# which behaves like an open struct.
|
10
|
+
#
|
11
|
+
# Options are:
|
12
|
+
# root: specify app root directory
|
13
|
+
# database: set database name
|
14
|
+
#
|
15
|
+
def initialize(options = OpenStruct.new)
|
16
|
+
@root = options.root
|
17
|
+
@root ||= Dir.pwd
|
18
|
+
@root = Pathname.new(@root)
|
19
|
+
|
20
|
+
@db_url = options.database
|
21
|
+
@db_url ||= read_db_url
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns an instance of Rid::Database,
|
25
|
+
# configured with db_name.
|
26
|
+
#
|
27
|
+
def db
|
28
|
+
return unless @db_url
|
29
|
+
@db ||= Rid::Database.new(@db_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
# List application documents.
|
33
|
+
# Each entry is a filename.
|
34
|
+
#
|
35
|
+
def documents
|
36
|
+
@documents ||= Dir[root.join("*")].
|
37
|
+
select { |f| File.directory? f }.
|
38
|
+
map { |f| Rid::Document.new :path => f }
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def read_db_url
|
44
|
+
filename = root.join('_database')
|
45
|
+
File.read(filename).strip
|
46
|
+
rescue Errno::ENOENT
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rid
|
2
|
+
module Attachments
|
3
|
+
# Mime type mapping from extensions
|
4
|
+
MIME_TYPE_MAPPING = {
|
5
|
+
".htm" => "text/html",
|
6
|
+
".html" => "text/html",
|
7
|
+
".js" => "text/javascript",
|
8
|
+
".css" => "text/css",
|
9
|
+
".manifest" => "text/cache-manifest",
|
10
|
+
".png" => "image/png",
|
11
|
+
".gif" => "image/gif",
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
# encode attachments and add meta data
|
16
|
+
#
|
17
|
+
def map_attachments!
|
18
|
+
return if attachments.empty?
|
19
|
+
|
20
|
+
doc = {}
|
21
|
+
attachments.flatten.each do |key, value|
|
22
|
+
doc[key] = {
|
23
|
+
"data" => encode_attachment(value),
|
24
|
+
"content_type" => mime_type_for(key)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
self.attachments = doc
|
29
|
+
end
|
30
|
+
|
31
|
+
# decode attachments and flatten meta data hash
|
32
|
+
#
|
33
|
+
def reduce_attachments!
|
34
|
+
return if attachments.empty?
|
35
|
+
|
36
|
+
doc = {}
|
37
|
+
attachments.each do |key, value|
|
38
|
+
data = value["data"]
|
39
|
+
next unless data
|
40
|
+
doc[key] = decode_attachment(data)
|
41
|
+
end
|
42
|
+
|
43
|
+
self.attachments = doc
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# accessor for attachments hash
|
49
|
+
#
|
50
|
+
def attachments
|
51
|
+
@hash["_attachments"] || {}
|
52
|
+
end
|
53
|
+
|
54
|
+
def attachments=(value)
|
55
|
+
@hash["_attachments"] = value
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def decode_attachment(data)
|
60
|
+
data.unpack("m").first
|
61
|
+
end
|
62
|
+
|
63
|
+
def encode_attachment(data)
|
64
|
+
[data].pack("m").gsub(/\s+/,'')
|
65
|
+
end
|
66
|
+
|
67
|
+
def mime_type_for(filename)
|
68
|
+
ext = File.extname(filename)
|
69
|
+
MIME_TYPE_MAPPING[ext] || 'text/plain'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/rid/commands.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Rid
|
2
|
+
# Rid Commands module defines the available Rid commands.
|
3
|
+
# A Rid command is a commander command.
|
4
|
+
# See http://github.com/visionmedia/commander for more information.
|
5
|
+
#
|
6
|
+
module Commands
|
7
|
+
# Returns the version specified in VERSION file at project root.
|
8
|
+
#
|
9
|
+
def self.version
|
10
|
+
versionfile = File.expand_path('../../../VERSION', __FILE__)
|
11
|
+
File.read(versionfile) if File.file?(versionfile)
|
12
|
+
end
|
13
|
+
|
14
|
+
program :name, 'Rid: Rest in development.'
|
15
|
+
program :version, version
|
16
|
+
program :description, <<-STR
|
17
|
+
Rid is a toolkit to relax in web development.
|
18
|
+
|
19
|
+
Based on CouchDB you get a distributed,
|
20
|
+
high scaling web application infrastructure with Rid.
|
21
|
+
|
22
|
+
Rid commands are distributed as RubyGems. Explore more Rid commands via
|
23
|
+
'gem list --remote rid-'
|
24
|
+
|
25
|
+
Type 'rid help command'
|
26
|
+
to get information about each command.
|
27
|
+
STR
|
28
|
+
|
29
|
+
program :help, 'Author', 'Johannes Jörg Schmidt, TF <schmidt@netzmerk.com>'
|
30
|
+
|
31
|
+
global_option '-q', '--quiet', 'Supress status output'
|
32
|
+
|
33
|
+
global_option '-b BEHAVIOR', '--behavior BEHAVIOR', String, 'Can be skip, pretend and force'
|
34
|
+
|
35
|
+
default_command :help
|
36
|
+
|
37
|
+
# List all installed rid gems, which starts with rid-.
|
38
|
+
#
|
39
|
+
def self.gems
|
40
|
+
Gem.path.
|
41
|
+
map { |p| Dir[File.join(p, 'gems/rid-*')] }.
|
42
|
+
flatten.
|
43
|
+
map { |g| File.basename(g).sub /-(\d+\.)*(\d+)$/, '' }.
|
44
|
+
uniq.
|
45
|
+
sort
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# require rid gem and do not care if that fails.
|
51
|
+
#
|
52
|
+
def self.require_rid_gem(gem)
|
53
|
+
begin
|
54
|
+
require gem
|
55
|
+
rescue LoadError
|
56
|
+
return
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# actually load all rid gems
|
61
|
+
gems.each { |g| require_rid_gem(g) }
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Hash
|
2
|
+
DEFAULT_SEPERATOR = '/' unless defined? DEFAULT_SEPERATOR
|
3
|
+
|
4
|
+
def flatten(seperator = DEFAULT_SEPERATOR, prefix = nil)
|
5
|
+
new_hash = {}
|
6
|
+
|
7
|
+
each do |key, value|
|
8
|
+
new_key = [prefix, key].compact.join(seperator)
|
9
|
+
if value.is_a?(self.class)
|
10
|
+
new_hash.update value.flatten(seperator, new_key)
|
11
|
+
else
|
12
|
+
new_hash.update new_key => value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
new_hash
|
17
|
+
end
|
18
|
+
|
19
|
+
def flatten!(*args)
|
20
|
+
replace flatten(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def at(path, seperator = DEFAULT_SEPERATOR)
|
24
|
+
current = self
|
25
|
+
|
26
|
+
parts = path.split(DEFAULT_SEPERATOR)
|
27
|
+
key = parts.pop
|
28
|
+
|
29
|
+
return unless key
|
30
|
+
|
31
|
+
parts.each do |part|
|
32
|
+
current = current[part]
|
33
|
+
|
34
|
+
return unless current.is_a?(self.class)
|
35
|
+
end
|
36
|
+
|
37
|
+
current[key]
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_at(path, value, seperator = DEFAULT_SEPERATOR)
|
41
|
+
current = self
|
42
|
+
|
43
|
+
parts = path.split(DEFAULT_SEPERATOR)
|
44
|
+
key = parts.pop
|
45
|
+
|
46
|
+
return self unless key
|
47
|
+
|
48
|
+
parts.each do |part|
|
49
|
+
current[part] ||= {}
|
50
|
+
current = current[part]
|
51
|
+
|
52
|
+
raise 'updating value at %s failed!' % inspect unless current.is_a?(self.class)
|
53
|
+
end
|
54
|
+
|
55
|
+
current[key] = value
|
56
|
+
end
|
57
|
+
end
|
data/lib/rid/database.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Rid
|
2
|
+
class Database
|
3
|
+
attr_accessor :name
|
4
|
+
|
5
|
+
# Initialize new Database object by url.
|
6
|
+
#
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
|
11
|
+
# Get document.
|
12
|
+
#
|
13
|
+
def get(doc, options = {})
|
14
|
+
response = RestClient.get(url(doc, options)) rescue nil
|
15
|
+
Rid::Document.new(:json => response.body) if response
|
16
|
+
end
|
17
|
+
|
18
|
+
# Save document.
|
19
|
+
# Creates it, until exists.
|
20
|
+
#
|
21
|
+
def save(doc)
|
22
|
+
# create database unless exists
|
23
|
+
# TODO: make this lazy
|
24
|
+
begin
|
25
|
+
RestClient.put @name, nil
|
26
|
+
rescue RestClient::PreconditionFailed
|
27
|
+
# database already exists
|
28
|
+
end
|
29
|
+
# push document
|
30
|
+
response = RestClient.put(url(doc), doc.to_json)
|
31
|
+
json = JSON.parse(response.body)
|
32
|
+
if json && json["ok"] && json["rev"]
|
33
|
+
doc.rev = json["rev"]
|
34
|
+
end
|
35
|
+
# return response
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
# Base URL for design document
|
40
|
+
#
|
41
|
+
def base_url(doc)
|
42
|
+
File.join(@name, doc.id)
|
43
|
+
end
|
44
|
+
|
45
|
+
# URL for accessing document
|
46
|
+
#
|
47
|
+
# Takes an optional options hash
|
48
|
+
# which gets converted to url encoded options
|
49
|
+
# and appended to the documents base url
|
50
|
+
#
|
51
|
+
def url(doc, options = {})
|
52
|
+
base_url(doc) + build_options_string(options)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# construct url options string
|
58
|
+
# values are url encoded
|
59
|
+
#
|
60
|
+
def build_options_string(options)
|
61
|
+
return '' if options.empty?
|
62
|
+
options_array = []
|
63
|
+
options.each do |key, value|
|
64
|
+
options_array << URI.escape([key, value].join('='))
|
65
|
+
end
|
66
|
+
'?' + options_array.join("&")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/rid/document.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Rid
|
4
|
+
class Document
|
5
|
+
include Attachments
|
6
|
+
|
7
|
+
attr_accessor :hash, :path
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
path = options[:path]
|
11
|
+
path = Pathname.new(path) unless path.nil? || path.is_a?(Pathname)
|
12
|
+
@path = path
|
13
|
+
# build hash from options hash
|
14
|
+
@hash = options[:hash]
|
15
|
+
# build hash from json option
|
16
|
+
self.json = options[:json] if !@hash && options[:json]
|
17
|
+
@hash ||= {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
@hash == other.hash
|
22
|
+
end
|
23
|
+
|
24
|
+
# Read document from a filesystem.
|
25
|
+
#
|
26
|
+
# Takes a filename,
|
27
|
+
# many filenames,
|
28
|
+
# or an array of filenames
|
29
|
+
# and assign the return value of a yielded block to the hash.
|
30
|
+
#
|
31
|
+
# Nested hashes
|
32
|
+
# like { "hash" => { "key" => "value" } }
|
33
|
+
# can be constructed if the filename contains a slash (/),
|
34
|
+
# eg "hash/key".
|
35
|
+
#
|
36
|
+
def read!(&block)
|
37
|
+
raise 'No path given!' unless @path
|
38
|
+
|
39
|
+
Dir[@path.join '**/*'].
|
40
|
+
map! { |file| Pathname.new file }.
|
41
|
+
delete_if { |f| !f.file? }.
|
42
|
+
flatten.
|
43
|
+
uniq.
|
44
|
+
each do |filename|
|
45
|
+
key = filename.relative_path_from(@path).to_s
|
46
|
+
# strip js extname from javascript files
|
47
|
+
key.sub!(/\.js$/, '') unless key =~ /^_attachments/
|
48
|
+
key.sub!(/\.erb$/, '')
|
49
|
+
|
50
|
+
value = block_given? ? block.call(filename) : read_file(filename)
|
51
|
+
# strip value if its a one-liner
|
52
|
+
value.strip! if value.count("\n") == 1
|
53
|
+
@hash.update_at key, value
|
54
|
+
end
|
55
|
+
|
56
|
+
map_attachments!
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Returns a JSON string representation of the documents hash
|
61
|
+
#
|
62
|
+
def to_json
|
63
|
+
@hash.to_json
|
64
|
+
end
|
65
|
+
|
66
|
+
# Build the documents hash from a JSON string
|
67
|
+
#
|
68
|
+
def json=(json)
|
69
|
+
@hash = JSON.parse(json)
|
70
|
+
end
|
71
|
+
|
72
|
+
def id
|
73
|
+
@id ||= @hash['_id']
|
74
|
+
@id ||= @path && File.read(@path.join('_id')).strip rescue nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def rev
|
78
|
+
@rev ||= @hash['_rev']
|
79
|
+
@rev ||= @path && File.read(@path.join('_rev')).strip rescue nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def rev=(value)
|
83
|
+
@rev = @hash['_rev'] = value
|
84
|
+
if @path
|
85
|
+
File.open(@path.join('_rev'), "w") { |file| file << value }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def read_file(filename)
|
92
|
+
if File.extname(filename) == '.erb'
|
93
|
+
ERB.new(File.read(filename)).result(binding)
|
94
|
+
else
|
95
|
+
File.read(filename)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/rid.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'commander/import'
|
6
|
+
require 'filander'
|
7
|
+
require 'active_support/inflector'
|
8
|
+
require 'json'
|
9
|
+
require 'rest_client'
|
10
|
+
|
11
|
+
require 'rid/core_ext/hash'
|
12
|
+
require 'rid/attachments'
|
13
|
+
require 'rid/database'
|
14
|
+
require 'rid/document'
|
15
|
+
require 'rid/app'
|
16
|
+
require 'rid/commands'
|
data/rid-core.gemspec
ADDED
@@ -0,0 +1,89 @@
|
|
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{rid-core}
|
8
|
+
s.version = "1.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Johannes J. Schmidt"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
|
+
s.default_executable = %q{rid}
|
14
|
+
s.description = %q{Rid is a toolkit to relax in web development. Based on CouchDB you get a distributed, high scaling web application infrastructure with Rid. This is the Rid core.}
|
15
|
+
s.email = %q{schmidt@netzmerk.com}
|
16
|
+
s.executables = ["rid"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"bin/rid",
|
28
|
+
"lib/rid.rb",
|
29
|
+
"lib/rid/app.rb",
|
30
|
+
"lib/rid/attachments.rb",
|
31
|
+
"lib/rid/commands.rb",
|
32
|
+
"lib/rid/core_ext/hash.rb",
|
33
|
+
"lib/rid/database.rb",
|
34
|
+
"lib/rid/document.rb",
|
35
|
+
"rid-core.gemspec",
|
36
|
+
"spec/mock_app/_database",
|
37
|
+
"spec/rid/app_spec.rb",
|
38
|
+
"spec/rid/attachments_spec.rb",
|
39
|
+
"spec/rid/commands_spec.rb",
|
40
|
+
"spec/rid/core_ext/hash_spec.rb",
|
41
|
+
"spec/rid/database_spec.rb",
|
42
|
+
"spec/rid/document_spec.rb",
|
43
|
+
"spec/spec.opts",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://rid.github.com/rid}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.7}
|
50
|
+
s.summary = %q{Rest in development core.}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/spec_helper.rb",
|
53
|
+
"spec/rid/core_ext/hash_spec.rb",
|
54
|
+
"spec/rid/database_spec.rb",
|
55
|
+
"spec/rid/commands_spec.rb",
|
56
|
+
"spec/rid/app_spec.rb",
|
57
|
+
"spec/rid/attachments_spec.rb",
|
58
|
+
"spec/rid/document_spec.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<commander>, [">= 4.0.3"])
|
67
|
+
s.add_runtime_dependency(%q<filander>, [">= 0.6.0"])
|
68
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.5.0"])
|
69
|
+
s.add_runtime_dependency(%q<json_pure>, [">= 1.4.2"])
|
70
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<commander>, [">= 4.0.3"])
|
74
|
+
s.add_dependency(%q<filander>, [">= 0.6.0"])
|
75
|
+
s.add_dependency(%q<rest-client>, [">= 1.5.0"])
|
76
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.2"])
|
77
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
s.add_dependency(%q<commander>, [">= 4.0.3"])
|
82
|
+
s.add_dependency(%q<filander>, [">= 0.6.0"])
|
83
|
+
s.add_dependency(%q<rest-client>, [">= 1.5.0"])
|
84
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.2"])
|
85
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
86
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
mydb
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'rid/app'
|
3
|
+
|
4
|
+
describe "App" do
|
5
|
+
describe "initialization" do
|
6
|
+
it "should set root as pathname" do
|
7
|
+
app = Rid::App.new
|
8
|
+
app.root.should be_a(Pathname)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should set root from options" do
|
12
|
+
app = Rid::App.new(OpenStruct.new(:root => "myroot"))
|
13
|
+
app.root.should == Pathname.new("myroot")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should default root to pwd" do
|
17
|
+
app = Rid::App.new
|
18
|
+
app.root.should == Pathname.new(Dir.pwd)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set database url from options" do
|
22
|
+
app = Rid::App.new(OpenStruct.new(:database => "mydb"))
|
23
|
+
app.db_url.should == "mydb"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should default database url to contents of _database file at root" do
|
27
|
+
app = Rid::App.new(OpenStruct.new(:root => mock_app_root))
|
28
|
+
app.db_url.should == "mydb"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "db" do
|
33
|
+
before do
|
34
|
+
@app = Rid::App.new(OpenStruct.new(:database => "mydb"))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return an instance od Rid::Database" do
|
38
|
+
@app.db.should be_a(Rid::Database)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return a database set to db_name" do
|
42
|
+
@app.db.name.should == 'mydb'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "documents" do
|
47
|
+
before do
|
48
|
+
@app = Rid::App.new(OpenStruct.new(:root => mock_app_root))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be an array" do
|
52
|
+
@app.documents.should be_a(Array)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return Document instances" do
|
56
|
+
@app.documents.all? { |d| d.should be_a(Rid::Document) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'rid/document'
|
3
|
+
|
4
|
+
describe "Attachments" do
|
5
|
+
before do
|
6
|
+
@doc = Rid::Document.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "map" do
|
10
|
+
describe "_attachments encoding and content_type" do
|
11
|
+
it "should proper encode and add plain text content type" do
|
12
|
+
@doc.hash = { "_attachments" => { "key" => "value" } }
|
13
|
+
@doc.map_attachments!
|
14
|
+
@doc.hash.should == { "_attachments" => { "key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should proper encode and add html content type" do
|
18
|
+
@doc.hash = { "_attachments" => { "key.html" => "value" } }
|
19
|
+
@doc.map_attachments!
|
20
|
+
@doc.hash.should == { "_attachments" => { "key.html" => { "data" => "dmFsdWU=", "content_type" => "text/html" } } }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should proper map nested attachments" do
|
24
|
+
@doc.hash = { "_attachments" => { "hash" => { "key" => "value" } } }
|
25
|
+
@doc.map_attachments!
|
26
|
+
@doc.hash.should == { "_attachments" => { "hash/key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "reduce" do
|
32
|
+
it "should decode _attachments data" do
|
33
|
+
@doc.hash = { "_attachments" => { "key" => { "data" => "dmFsdWU=" } } }
|
34
|
+
@doc.reduce_attachments!
|
35
|
+
@doc.hash.should == { "_attachments" => { "key" => "value" } }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'rid/commands'
|
3
|
+
|
4
|
+
describe "Commands" do
|
5
|
+
describe "gems" do
|
6
|
+
it "should be an array" do
|
7
|
+
Rid::Commands.gems.should be_a(Array)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not include rid gem" do
|
11
|
+
Rid::Commands.gems.should_not include("rid")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
require 'rid/core_ext/hash'
|
3
|
+
|
4
|
+
describe "Hash" do
|
5
|
+
describe "flatten" do
|
6
|
+
it "should untouch flat hash" do
|
7
|
+
hash = { "a" => 1, "b" => 2 }
|
8
|
+
hash.flatten.should == hash
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should flaten simple nested hash" do
|
12
|
+
hash = { "a" => { "b" => 1 } }
|
13
|
+
hash.flatten.should == { "a/b" => 1 }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should flaten deep nested hash" do
|
17
|
+
hash = { "a" => { "b" => { "c" => 1 } } }
|
18
|
+
hash.flatten.should == { "a/b/c" => 1 }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "flatten!" do
|
23
|
+
it "should change receiver" do
|
24
|
+
hash = { "a" => { "b" => 1 } }
|
25
|
+
hash.flatten!
|
26
|
+
hash.should == { "a/b" => 1 }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "at" do
|
31
|
+
it "should retrieve value at top level" do
|
32
|
+
hash = { "a" => 1 }
|
33
|
+
hash.at("a").should == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should retrieve value at nested level" do
|
37
|
+
hash = { "a" => { "b" => 1 } }
|
38
|
+
hash.at("a/b").should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should retrieve value at deep nested level" do
|
42
|
+
hash = { "a" => { "b" => { "c" => 1 } } }
|
43
|
+
hash.at("a/b/c").should == 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return nil if not present" do
|
47
|
+
hash = { "a" => { "c" => { "c" => 1 } } }
|
48
|
+
hash.at("a/b/c").should == nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "update_at" do
|
53
|
+
it "should insert value at top level" do
|
54
|
+
hash = { }
|
55
|
+
hash.update_at "a", 1
|
56
|
+
hash.should == { "a" => 1 }
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should insert value at nested level" do
|
60
|
+
hash = { }
|
61
|
+
hash.update_at "a/b", 1
|
62
|
+
hash.should == { "a" => { "b" => 1 } }
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should insert value at deep nested level" do
|
66
|
+
hash = { }
|
67
|
+
hash.update_at "a/b/c", 1
|
68
|
+
hash.should == { "a" => { "b" => { "c" => 1 } } }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'rid/database'
|
3
|
+
|
4
|
+
describe "Database" do
|
5
|
+
before do
|
6
|
+
@name = "http://127.0.0.1:5984/rid-tests"
|
7
|
+
@db = Rid::Database.new(@name)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
RestClient.delete(@name) rescue nil
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "initialization" do
|
15
|
+
it "should initialize database by name" do
|
16
|
+
@db.name.should == @name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "get" do
|
21
|
+
it "should return nil if document was not found" do
|
22
|
+
@db.get(Rid::Document.new).should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'rid/document'
|
3
|
+
|
4
|
+
describe "Document" do
|
5
|
+
before do
|
6
|
+
@doc = Rid::Document.new
|
7
|
+
@hash = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "read!" do
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "to_json" do
|
14
|
+
it "should convert key-value pair" do
|
15
|
+
@doc.hash = { "key" => "value" }
|
16
|
+
@doc.to_json.should == '{"key":"value"}'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should convert nested hash" do
|
20
|
+
@doc.hash = { "hash" => { "key" => "value" } }
|
21
|
+
@doc.to_json.should == '{"hash":{"key":"value"}}'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "json=" do
|
26
|
+
it "should read key-value pair" do
|
27
|
+
@doc.json = '{"key":"value"}'
|
28
|
+
@doc.hash.should == { "key" => "value" }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should read nested hash" do
|
32
|
+
@doc.json = '{"hash":{"key":"value"}}'
|
33
|
+
@doc.hash.should == { "hash" => { "key" => "value" } }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rid'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
# returns the dirname of the mock app
|
12
|
+
#
|
13
|
+
def mock_app_root
|
14
|
+
File.expand_path('../mock_app', __FILE__)
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rid-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Johannes J. Schmidt
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-21 00:00:00 +02:00
|
19
|
+
default_executable: rid
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: commander
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 57
|
30
|
+
segments:
|
31
|
+
- 4
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 4.0.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: filander
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 6
|
49
|
+
- 0
|
50
|
+
version: 0.6.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rest-client
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 5
|
65
|
+
- 0
|
66
|
+
version: 1.5.0
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json_pure
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 4
|
81
|
+
- 2
|
82
|
+
version: 1.4.2
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: activesupport
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
type: :runtime
|
98
|
+
version_requirements: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rspec
|
101
|
+
prerelease: false
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 13
|
108
|
+
segments:
|
109
|
+
- 1
|
110
|
+
- 2
|
111
|
+
- 9
|
112
|
+
version: 1.2.9
|
113
|
+
type: :development
|
114
|
+
version_requirements: *id006
|
115
|
+
description: Rid is a toolkit to relax in web development. Based on CouchDB you get a distributed, high scaling web application infrastructure with Rid. This is the Rid core.
|
116
|
+
email: schmidt@netzmerk.com
|
117
|
+
executables:
|
118
|
+
- rid
|
119
|
+
extensions: []
|
120
|
+
|
121
|
+
extra_rdoc_files:
|
122
|
+
- LICENSE
|
123
|
+
- README
|
124
|
+
files:
|
125
|
+
- .gitignore
|
126
|
+
- LICENSE
|
127
|
+
- README
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- bin/rid
|
131
|
+
- lib/rid.rb
|
132
|
+
- lib/rid/app.rb
|
133
|
+
- lib/rid/attachments.rb
|
134
|
+
- lib/rid/commands.rb
|
135
|
+
- lib/rid/core_ext/hash.rb
|
136
|
+
- lib/rid/database.rb
|
137
|
+
- lib/rid/document.rb
|
138
|
+
- rid-core.gemspec
|
139
|
+
- spec/mock_app/_database
|
140
|
+
- spec/rid/app_spec.rb
|
141
|
+
- spec/rid/attachments_spec.rb
|
142
|
+
- spec/rid/commands_spec.rb
|
143
|
+
- spec/rid/core_ext/hash_spec.rb
|
144
|
+
- spec/rid/database_spec.rb
|
145
|
+
- spec/rid/document_spec.rb
|
146
|
+
- spec/spec.opts
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
has_rdoc: true
|
149
|
+
homepage: http://rid.github.com/rid
|
150
|
+
licenses: []
|
151
|
+
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options:
|
154
|
+
- --charset=UTF-8
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: "0"
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
175
|
+
requirements: []
|
176
|
+
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 1.3.7
|
179
|
+
signing_key:
|
180
|
+
specification_version: 3
|
181
|
+
summary: Rest in development core.
|
182
|
+
test_files:
|
183
|
+
- spec/spec_helper.rb
|
184
|
+
- spec/rid/core_ext/hash_spec.rb
|
185
|
+
- spec/rid/database_spec.rb
|
186
|
+
- spec/rid/commands_spec.rb
|
187
|
+
- spec/rid/app_spec.rb
|
188
|
+
- spec/rid/attachments_spec.rb
|
189
|
+
- spec/rid/document_spec.rb
|