couch 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/couch.gemspec +13 -3
- data/lib/couch/actions/base.rb +1 -1
- data/lib/couch/actions/pull.rb +2 -2
- data/lib/couch/actions/push.rb +2 -2
- data/lib/couch/generators.rb +3 -2
- data/lib/couch/generators/application/application_generator.rb +1 -10
- data/lib/couch/generators/application/templates/{_id → _id.js} +0 -0
- data/lib/couch/generators/base.rb +9 -2
- data/lib/couch/generators/named_base.rb +23 -0
- data/lib/couch/generators/scaffold/USAGE +10 -0
- data/lib/couch/generators/scaffold/scaffold_generator.rb +21 -0
- data/lib/couch/generators/validation/USAGE +9 -0
- data/lib/couch/generators/validation/validation_generator.rb +29 -0
- data/lib/couch/generators/view/USAGE +8 -0
- data/lib/couch/generators/view/templates/map.js +5 -0
- data/lib/couch/generators/view/view_generator.rb +11 -0
- data/lib/couch/mapper.rb +9 -8
- data/lib/couch/version.rb +1 -1
- metadata +28 -6
- data/lib/couch/core_ext/string/inflections.rb +0 -50
data/Rakefile
CHANGED
@@ -16,6 +16,7 @@ begin
|
|
16
16
|
gem.add_dependency "thor", ">= 0.13.4"
|
17
17
|
gem.add_dependency "rest-client", ">= 1.4.1"
|
18
18
|
gem.add_dependency "json_pure", ">= 1.2.2"
|
19
|
+
gem.add_dependency "activesupport", ">= 3.0.0.beta"
|
19
20
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
20
21
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
21
22
|
end
|
data/couch.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{couch}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
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"]
|
@@ -34,18 +34,25 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/couch/commands/generate.rb",
|
35
35
|
"lib/couch/commands/pull.rb",
|
36
36
|
"lib/couch/commands/push.rb",
|
37
|
-
"lib/couch/core_ext/string/inflections.rb",
|
38
37
|
"lib/couch/generators.rb",
|
39
38
|
"lib/couch/generators/application/USAGE",
|
40
39
|
"lib/couch/generators/application/application_generator.rb",
|
41
40
|
"lib/couch/generators/application/templates/README",
|
42
41
|
"lib/couch/generators/application/templates/_attachments/index.html",
|
43
42
|
"lib/couch/generators/application/templates/_attachments/stylesheets/application.css",
|
44
|
-
"lib/couch/generators/application/templates/_id",
|
43
|
+
"lib/couch/generators/application/templates/_id.js",
|
45
44
|
"lib/couch/generators/application/templates/couchrc",
|
46
45
|
"lib/couch/generators/application/templates/gitignore",
|
47
46
|
"lib/couch/generators/application/templates/validate_doc_update.js",
|
48
47
|
"lib/couch/generators/base.rb",
|
48
|
+
"lib/couch/generators/named_base.rb",
|
49
|
+
"lib/couch/generators/scaffold/USAGE",
|
50
|
+
"lib/couch/generators/scaffold/scaffold_generator.rb",
|
51
|
+
"lib/couch/generators/validation/USAGE",
|
52
|
+
"lib/couch/generators/validation/validation_generator.rb",
|
53
|
+
"lib/couch/generators/view/USAGE",
|
54
|
+
"lib/couch/generators/view/templates/map.js",
|
55
|
+
"lib/couch/generators/view/view_generator.rb",
|
49
56
|
"lib/couch/mapper.rb",
|
50
57
|
"lib/couch/version.rb",
|
51
58
|
"spec/couch_spec.rb",
|
@@ -71,17 +78,20 @@ Gem::Specification.new do |s|
|
|
71
78
|
s.add_runtime_dependency(%q<thor>, [">= 0.13.4"])
|
72
79
|
s.add_runtime_dependency(%q<rest-client>, [">= 1.4.1"])
|
73
80
|
s.add_runtime_dependency(%q<json_pure>, [">= 1.2.2"])
|
81
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta"])
|
74
82
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
75
83
|
else
|
76
84
|
s.add_dependency(%q<thor>, [">= 0.13.4"])
|
77
85
|
s.add_dependency(%q<rest-client>, [">= 1.4.1"])
|
78
86
|
s.add_dependency(%q<json_pure>, [">= 1.2.2"])
|
87
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
|
79
88
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
80
89
|
end
|
81
90
|
else
|
82
91
|
s.add_dependency(%q<thor>, [">= 0.13.4"])
|
83
92
|
s.add_dependency(%q<rest-client>, [">= 1.4.1"])
|
84
93
|
s.add_dependency(%q<json_pure>, [">= 1.2.2"])
|
94
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
|
85
95
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
86
96
|
end
|
87
97
|
end
|
data/lib/couch/actions/base.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'couch'
|
2
2
|
require 'couch/mapper'
|
3
|
-
require 'couch/core_ext/string/inflections'
|
4
3
|
|
5
4
|
require 'rubygems'
|
6
5
|
require "rest_client"
|
7
6
|
require 'json'
|
8
7
|
require 'thor/group'
|
8
|
+
require 'active_support/core_ext/string/inflections'
|
9
9
|
|
10
10
|
module Couch
|
11
11
|
module Actions
|
data/lib/couch/actions/pull.rb
CHANGED
@@ -5,7 +5,7 @@ module Couch
|
|
5
5
|
class Pull < Base
|
6
6
|
add_runtime_options!
|
7
7
|
|
8
|
-
def
|
8
|
+
def pull
|
9
9
|
id = mapper.doc["_id"]
|
10
10
|
url = url_for(id)
|
11
11
|
|
@@ -28,7 +28,7 @@ module Couch
|
|
28
28
|
next if key == "_attachments"
|
29
29
|
filename = File.join(dirname, key)
|
30
30
|
if value.is_a?(String)
|
31
|
-
create_file filename, value
|
31
|
+
create_file "#{filename}.js", "#{value}\n"
|
32
32
|
else
|
33
33
|
Dir.mkdir(filename) unless File.directory?(filename)
|
34
34
|
map_doc value, File.join(dirname, key)
|
data/lib/couch/actions/push.rb
CHANGED
@@ -20,8 +20,8 @@ module Couch
|
|
20
20
|
|
21
21
|
if response["ok"]
|
22
22
|
rev = response["rev"]
|
23
|
-
File.open File.join(destination_root, "_rev"), "w" do |file|
|
24
|
-
file << rev
|
23
|
+
File.open File.join(destination_root, "_rev.js"), "w" do |file|
|
24
|
+
file << "#{rev}\n"
|
25
25
|
end
|
26
26
|
|
27
27
|
say "Pushed %s" % rev
|
data/lib/couch/generators.rb
CHANGED
@@ -18,10 +18,11 @@ module Couch
|
|
18
18
|
def self.help(command = 'generate')
|
19
19
|
path = File.expand_path("../generators/*/*_generator.rb", __FILE__)
|
20
20
|
generators = Dir.glob(path)
|
21
|
+
generators.sort!
|
21
22
|
generators.map! { |f| File.basename(f) }
|
22
23
|
generators.map! { |n| n.sub!(/_generator\.rb$/, '') }
|
23
|
-
|
24
|
-
generators.map! { |g| "%s # %s" % [g.ljust(
|
24
|
+
longest_name_size = generators.map { |g| g.size }.sort.last
|
25
|
+
generators.map! { |g| "%s # %s" % [g.ljust(longest_name_size), lookup(g).info] }
|
25
26
|
|
26
27
|
puts "Usage: couch #{command} GENERATOR [args] [options]"
|
27
28
|
puts
|
@@ -2,10 +2,6 @@ module Couch::Generators
|
|
2
2
|
class ApplicationGenerator < Base
|
3
3
|
argument :app_path, :type => :string
|
4
4
|
|
5
|
-
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
6
|
-
:desc => "Skip Git ignores and keeps"
|
7
|
-
|
8
|
-
|
9
5
|
def create_root
|
10
6
|
self.destination_root = File.expand_path(app_path, destination_root)
|
11
7
|
|
@@ -17,7 +13,7 @@ module Couch::Generators
|
|
17
13
|
template "couchrc", ".couchrc"
|
18
14
|
copy_file "README"
|
19
15
|
copy_file "gitignore", ".gitignore" unless options[:skip_git]
|
20
|
-
template "_id"
|
16
|
+
template "_id.js"
|
21
17
|
copy_file "validate_doc_update.js"
|
22
18
|
empty_directory_with_gitkeep "lists"
|
23
19
|
empty_directory_with_gitkeep "shows"
|
@@ -44,10 +40,5 @@ module Couch::Generators
|
|
44
40
|
def app_title
|
45
41
|
@app_title ||= app_name.humanize
|
46
42
|
end
|
47
|
-
|
48
|
-
def empty_directory_with_gitkeep(destination, config = {})
|
49
|
-
empty_directory(destination, config)
|
50
|
-
create_file("#{destination}/.gitkeep") unless options[:skip_git]
|
51
|
-
end
|
52
43
|
end
|
53
44
|
end
|
File without changes
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require 'couch/core_ext/string/inflections'
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
2
|
require 'thor/group'
|
3
|
+
require 'active_support/inflector'
|
5
4
|
|
6
5
|
module Couch
|
7
6
|
module Generators
|
@@ -13,6 +12,9 @@ module Couch
|
|
13
12
|
|
14
13
|
add_runtime_options!
|
15
14
|
|
15
|
+
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
16
|
+
:desc => "Skip Git ignores and keeps"
|
17
|
+
|
16
18
|
# Automatically sets the source root based on the class name.
|
17
19
|
#
|
18
20
|
def self.source_root
|
@@ -60,6 +62,11 @@ module Couch
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
65
|
+
|
66
|
+
def empty_directory_with_gitkeep(destination, config = {})
|
67
|
+
empty_directory(destination, config)
|
68
|
+
create_file("#{destination}/.gitkeep") unless options[:skip_git]
|
69
|
+
end
|
63
70
|
end
|
64
71
|
end
|
65
72
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'thor/group'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
module Couch
|
6
|
+
module Generators
|
7
|
+
class NamedBase < Base
|
8
|
+
argument :name, :type => :string
|
9
|
+
argument :attributes, :type => :array, :default => []
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
# force underscored and singularized model name
|
14
|
+
def model_name
|
15
|
+
@model_name ||= name.underscore.singularize
|
16
|
+
end
|
17
|
+
|
18
|
+
def pluralized_model_name
|
19
|
+
model_name.pluralize
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
The 'scaffold' generator creates a scaffold skelet
|
3
|
+
with a default show function, list function
|
4
|
+
of the name and attributes you specify
|
5
|
+
|
6
|
+
Example:
|
7
|
+
couch generate scaffold post title body
|
8
|
+
|
9
|
+
This generates a skeletal model post with a posts list view,
|
10
|
+
post show function and validation.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'couch/generators/named_base'
|
2
|
+
|
3
|
+
module Couch::Generators
|
4
|
+
class ScaffoldGenerator < NamedBase
|
5
|
+
def create_view_function
|
6
|
+
Couch::Generators.invoke "view", name, :behavior => behavior
|
7
|
+
end
|
8
|
+
|
9
|
+
def inject_validations
|
10
|
+
Couch::Generators.invoke "validation", [name] + attributes, :behavior => behavior
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_list_function
|
14
|
+
say "list function generation not implemented yet"
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_show_function
|
18
|
+
say "show function generation not implemented yet"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
The 'validation' generator creates a validation function
|
3
|
+
for the model name and attributes you specify
|
4
|
+
|
5
|
+
Example:
|
6
|
+
couch generate validation post title body
|
7
|
+
|
8
|
+
This generates a skeletal model validation for post
|
9
|
+
with validations of presence for title and body
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'couch/generators/named_base'
|
2
|
+
|
3
|
+
module Couch::Generators
|
4
|
+
class ValidationGenerator < NamedBase
|
5
|
+
def inject_validations
|
6
|
+
inject_into_file "validate_doc_update.js", model_validations, :after => "function (newDoc, oldDoc, userCtx) {\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def model_validations
|
12
|
+
str = <<-STR
|
13
|
+
if(newDoc.type == '#{model_name}') {
|
14
|
+
// validations for #{model_name}
|
15
|
+
STR
|
16
|
+
|
17
|
+
attributes.each do |attribute|
|
18
|
+
str << <<-STR
|
19
|
+
if (typeof(newDoc['#{attribute}']) === 'undefined') {
|
20
|
+
throw({ forbidden: '#{attribute} is required' });
|
21
|
+
}
|
22
|
+
STR
|
23
|
+
end
|
24
|
+
|
25
|
+
str << " }\n"
|
26
|
+
str
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/couch/mapper.rb
CHANGED
@@ -21,14 +21,15 @@ module Couch
|
|
21
21
|
Dir.entries(dirname).each do |file|
|
22
22
|
next if file =~ /^\./
|
23
23
|
filename = File.join(dirname, file)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
if file == "_attachments"
|
25
|
+
hash['_attachments'] = map_attachments(filename)
|
26
|
+
elsif File.directory?(filename)
|
27
|
+
hash[file] = map(filename)
|
28
|
+
elsif File.extname(filename) == '.js'
|
29
|
+
# only .js files are mapped
|
30
|
+
key = file.sub(/\.js$/, '')
|
31
|
+
hash[key] = File.read(filename).strip
|
32
|
+
end
|
32
33
|
end
|
33
34
|
hash
|
34
35
|
end
|
data/lib/couch/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Johannes J. Schmidt
|
@@ -60,9 +60,24 @@ dependencies:
|
|
60
60
|
type: :runtime
|
61
61
|
version_requirements: *id003
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: activesupport
|
64
64
|
prerelease: false
|
65
65
|
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 3
|
71
|
+
- 0
|
72
|
+
- 0
|
73
|
+
- beta
|
74
|
+
version: 3.0.0.beta
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rspec
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
66
81
|
requirements:
|
67
82
|
- - ">="
|
68
83
|
- !ruby/object:Gem::Version
|
@@ -72,7 +87,7 @@ dependencies:
|
|
72
87
|
- 9
|
73
88
|
version: 1.2.9
|
74
89
|
type: :development
|
75
|
-
version_requirements: *
|
90
|
+
version_requirements: *id005
|
76
91
|
description: With Couch you can easy build a standalone CouchDB application.
|
77
92
|
email: schmidt@netzmerk.com
|
78
93
|
executables:
|
@@ -98,18 +113,25 @@ files:
|
|
98
113
|
- lib/couch/commands/generate.rb
|
99
114
|
- lib/couch/commands/pull.rb
|
100
115
|
- lib/couch/commands/push.rb
|
101
|
-
- lib/couch/core_ext/string/inflections.rb
|
102
116
|
- lib/couch/generators.rb
|
103
117
|
- lib/couch/generators/application/USAGE
|
104
118
|
- lib/couch/generators/application/application_generator.rb
|
105
119
|
- lib/couch/generators/application/templates/README
|
106
120
|
- lib/couch/generators/application/templates/_attachments/index.html
|
107
121
|
- lib/couch/generators/application/templates/_attachments/stylesheets/application.css
|
108
|
-
- lib/couch/generators/application/templates/_id
|
122
|
+
- lib/couch/generators/application/templates/_id.js
|
109
123
|
- lib/couch/generators/application/templates/couchrc
|
110
124
|
- lib/couch/generators/application/templates/gitignore
|
111
125
|
- lib/couch/generators/application/templates/validate_doc_update.js
|
112
126
|
- lib/couch/generators/base.rb
|
127
|
+
- lib/couch/generators/named_base.rb
|
128
|
+
- lib/couch/generators/scaffold/USAGE
|
129
|
+
- lib/couch/generators/scaffold/scaffold_generator.rb
|
130
|
+
- lib/couch/generators/validation/USAGE
|
131
|
+
- lib/couch/generators/validation/validation_generator.rb
|
132
|
+
- lib/couch/generators/view/USAGE
|
133
|
+
- lib/couch/generators/view/templates/map.js
|
134
|
+
- lib/couch/generators/view/view_generator.rb
|
113
135
|
- lib/couch/mapper.rb
|
114
136
|
- lib/couch/version.rb
|
115
137
|
- spec/couch_spec.rb
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# String inflections define new methods on the String class to transform names for different purposes.
|
2
|
-
# For instance, you can figure out the name of a database from the name of a class.
|
3
|
-
#
|
4
|
-
# "ScaleScore".underscore # => "scale_score"
|
5
|
-
|
6
|
-
class String
|
7
|
-
# +camelize+ converts strings to UpperCamelCase.
|
8
|
-
#
|
9
|
-
# +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
|
10
|
-
#
|
11
|
-
# Examples:
|
12
|
-
# "scale_score".camelize # => "ScaleScore"
|
13
|
-
# "scale_score/errors".camelize # => "ScaleScore::Errors"
|
14
|
-
def camelize
|
15
|
-
self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
16
|
-
end
|
17
|
-
|
18
|
-
# Makes an underscored, lowercase form from the expression in the string.
|
19
|
-
#
|
20
|
-
# +underscore+ will also change '::' to '/' to convert namespaces to paths.
|
21
|
-
#
|
22
|
-
# "ScaleScore".underscore # => "scale_score"
|
23
|
-
# "Couch::Generators".underscore # => couch/generators
|
24
|
-
def underscore
|
25
|
-
self.gsub(/::/, '/').
|
26
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
27
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
28
|
-
tr("-", "_").
|
29
|
-
downcase
|
30
|
-
end
|
31
|
-
|
32
|
-
# Capitalizes the first word and turns underscores into spaces.
|
33
|
-
# This is meant for creating pretty output.
|
34
|
-
#
|
35
|
-
# Examples:
|
36
|
-
# "employee_salary" # => "Employee salary"
|
37
|
-
def humanize
|
38
|
-
self.gsub(/_/, " ").capitalize
|
39
|
-
end
|
40
|
-
|
41
|
-
# Create a class name
|
42
|
-
# Note that this returns a string and not a Class. (To convert to an actual class
|
43
|
-
# follow +classify+ with +constantize+.)
|
44
|
-
#
|
45
|
-
# Examples:
|
46
|
-
# "post".classify # => "Post"
|
47
|
-
def classify
|
48
|
-
self.camelize
|
49
|
-
end
|
50
|
-
end
|