rid 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -5,8 +5,7 @@ In the spirit of Ruby on Rails Rid tends on programmers happiness.
5
5
  Rid eases the process of building standalone CouchDB applications
6
6
  with tools for deployment, codegenerators and a javascript library.
7
7
 
8
- This is the rid gem with the CouchDB model and command line
9
- infrastructure.
8
+ This is the meta rid gem which installs all base rid gems.
10
9
 
11
10
 
12
11
  == Copyright
data/Rakefile CHANGED
@@ -5,19 +5,19 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "rid"
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.}
8
+ gem.summary = %Q{Rest in development meta package.}
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 meta package.}
10
10
  gem.email = "schmidt@netzmerk.com"
11
11
  gem.homepage = "http://rid.github.com/rid"
12
12
  gem.authors = ["Johannes J. Schmidt"]
13
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"
14
+ gem.add_dependency "rid-core"
15
+ gem.add_dependency "rid-init"
16
+ gem.add_dependency "rid-dd"
17
+ gem.add_dependency "rid-fn"
18
+ gem.add_dependency "rid-push"
19
+ gem.add_dependency "rid-export"
19
20
 
20
- gem.add_development_dependency "rspec", ">= 1.2.9"
21
21
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
22
  end
23
23
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -5,15 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rid}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Johannes J. Schmidt"]
12
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.}
13
+ 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 meta package.}
15
14
  s.email = %q{schmidt@netzmerk.com}
16
- s.executables = ["rid"]
17
15
  s.extra_rdoc_files = [
18
16
  "LICENSE",
19
17
  "README"
@@ -24,66 +22,40 @@ Gem::Specification.new do |s|
24
22
  "README",
25
23
  "Rakefile",
26
24
  "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.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"
25
+ "rid.gemspec"
45
26
  ]
46
27
  s.homepage = %q{http://rid.github.com/rid}
47
28
  s.rdoc_options = ["--charset=UTF-8"]
48
29
  s.require_paths = ["lib"]
49
30
  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
- ]
31
+ s.summary = %q{Rest in development meta package.}
60
32
 
61
33
  if s.respond_to? :specification_version then
62
34
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
35
  s.specification_version = 3
64
36
 
65
37
  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"])
38
+ s.add_runtime_dependency(%q<rid-core>, [">= 0"])
39
+ s.add_runtime_dependency(%q<rid-init>, [">= 0"])
40
+ s.add_runtime_dependency(%q<rid-dd>, [">= 0"])
41
+ s.add_runtime_dependency(%q<rid-fn>, [">= 0"])
42
+ s.add_runtime_dependency(%q<rid-push>, [">= 0"])
43
+ s.add_runtime_dependency(%q<rid-export>, [">= 0"])
72
44
  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"])
45
+ s.add_dependency(%q<rid-core>, [">= 0"])
46
+ s.add_dependency(%q<rid-init>, [">= 0"])
47
+ s.add_dependency(%q<rid-dd>, [">= 0"])
48
+ s.add_dependency(%q<rid-fn>, [">= 0"])
49
+ s.add_dependency(%q<rid-push>, [">= 0"])
50
+ s.add_dependency(%q<rid-export>, [">= 0"])
79
51
  end
80
52
  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"])
53
+ s.add_dependency(%q<rid-core>, [">= 0"])
54
+ s.add_dependency(%q<rid-init>, [">= 0"])
55
+ s.add_dependency(%q<rid-dd>, [">= 0"])
56
+ s.add_dependency(%q<rid-fn>, [">= 0"])
57
+ s.add_dependency(%q<rid-push>, [">= 0"])
58
+ s.add_dependency(%q<rid-export>, [">= 0"])
87
59
  end
88
60
  end
89
61
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Johannes J. Schmidt
@@ -16,42 +16,38 @@ bindir: bin
16
16
  cert_chain: []
17
17
 
18
18
  date: 2010-08-21 00:00:00 +02:00
19
- default_executable: rid
19
+ default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: commander
22
+ name: rid-core
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 57
29
+ hash: 3
30
30
  segments:
31
- - 4
32
31
  - 0
33
- - 3
34
- version: 4.0.3
32
+ version: "0"
35
33
  type: :runtime
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
38
- name: filander
36
+ name: rid-init
39
37
  prerelease: false
40
38
  requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 7
43
+ hash: 3
46
44
  segments:
47
45
  - 0
48
- - 6
49
- - 0
50
- version: 0.6.0
46
+ version: "0"
51
47
  type: :runtime
52
48
  version_requirements: *id002
53
49
  - !ruby/object:Gem::Dependency
54
- name: rest-client
50
+ name: rid-dd
55
51
  prerelease: false
56
52
  requirement: &id003 !ruby/object:Gem::Requirement
57
53
  none: false
@@ -60,14 +56,12 @@ dependencies:
60
56
  - !ruby/object:Gem::Version
61
57
  hash: 3
62
58
  segments:
63
- - 1
64
- - 5
65
59
  - 0
66
- version: 1.5.0
60
+ version: "0"
67
61
  type: :runtime
68
62
  version_requirements: *id003
69
63
  - !ruby/object:Gem::Dependency
70
- name: json_pure
64
+ name: rid-fn
71
65
  prerelease: false
72
66
  requirement: &id004 !ruby/object:Gem::Requirement
73
67
  none: false
@@ -76,14 +70,12 @@ dependencies:
76
70
  - !ruby/object:Gem::Version
77
71
  hash: 3
78
72
  segments:
79
- - 1
80
- - 4
81
- - 2
82
- version: 1.4.2
73
+ - 0
74
+ version: "0"
83
75
  type: :runtime
84
76
  version_requirements: *id004
85
77
  - !ruby/object:Gem::Dependency
86
- name: activesupport
78
+ name: rid-push
87
79
  prerelease: false
88
80
  requirement: &id005 !ruby/object:Gem::Requirement
89
81
  none: false
@@ -97,25 +89,23 @@ dependencies:
97
89
  type: :runtime
98
90
  version_requirements: *id005
99
91
  - !ruby/object:Gem::Dependency
100
- name: rspec
92
+ name: rid-export
101
93
  prerelease: false
102
94
  requirement: &id006 !ruby/object:Gem::Requirement
103
95
  none: false
104
96
  requirements:
105
97
  - - ">="
106
98
  - !ruby/object:Gem::Version
107
- hash: 13
99
+ hash: 3
108
100
  segments:
109
- - 1
110
- - 2
111
- - 9
112
- version: 1.2.9
113
- type: :development
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
114
104
  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.
105
+ 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 meta package.
116
106
  email: schmidt@netzmerk.com
117
- executables:
118
- - rid
107
+ executables: []
108
+
119
109
  extensions: []
120
110
 
121
111
  extra_rdoc_files:
@@ -127,24 +117,7 @@ files:
127
117
  - README
128
118
  - Rakefile
129
119
  - 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
120
  - rid.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
121
  has_rdoc: true
149
122
  homepage: http://rid.github.com/rid
150
123
  licenses: []
@@ -178,12 +151,6 @@ rubyforge_project:
178
151
  rubygems_version: 1.3.7
179
152
  signing_key:
180
153
  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
154
+ summary: Rest in development meta package.
155
+ test_files: []
156
+
data/bin/rid DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.join(File.dirname(__FILE__), '../lib/rid')
4
- include Rid::Commands
data/lib/rid.rb DELETED
@@ -1,16 +0,0 @@
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'
@@ -1,49 +0,0 @@
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
@@ -1,72 +0,0 @@
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
@@ -1,63 +0,0 @@
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
@@ -1,57 +0,0 @@
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
@@ -1,69 +0,0 @@
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
@@ -1,99 +0,0 @@
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
@@ -1 +0,0 @@
1
- mydb
@@ -1,59 +0,0 @@
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
@@ -1,38 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,71 +0,0 @@
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
@@ -1,25 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1 +0,0 @@
1
- --color
@@ -1,15 +0,0 @@
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