couchrest_model_thought 1.0.0.beta8 → 1.0.0.beta9
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/Gemfile +2 -2
- data/lib/couchrest/model/version.rb +1 -1
- data/lib/generators/couchrest/couch_rest_generator.rb +69 -0
- data/lib/generators/couchrest/install_generator.rb +24 -0
- data/lib/generators/couchrest/templates/README +6 -0
- data/lib/generators/couchrest/templates/couch_config.rb +8 -0
- data/lib/generators/couchrest/templates/model.erb +9 -0
- metadata +8 -3
data/Gemfile
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Couchrest
|
2
|
+
module Generators
|
3
|
+
class CouchrestGenerator < Rails::Generators::NamedBase
|
4
|
+
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
|
7
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
8
|
+
|
9
|
+
check_class_collision
|
10
|
+
|
11
|
+
class_option :timestamps, :type => :boolean
|
12
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
13
|
+
|
14
|
+
def create_model_file
|
15
|
+
template 'model.erb', File.join('app/models', class_path, "#{file_name}.rb")
|
16
|
+
end
|
17
|
+
|
18
|
+
hook_for :test_framework
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class ActiveModel < Rails::Generators::ActiveModel
|
23
|
+
def self.all(klass)
|
24
|
+
"#{klass}.all"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find(klass, params=nil)
|
28
|
+
"#{klass}.get(#{params})"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.build(klass, params=nil)
|
32
|
+
if params
|
33
|
+
"#{klass}.new(#{params})"
|
34
|
+
else
|
35
|
+
"#{klass}.new"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def save
|
40
|
+
"#{name}.save"
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_attributes(params=nil)
|
44
|
+
"#{name}.update(#{params})"
|
45
|
+
end
|
46
|
+
|
47
|
+
def errors
|
48
|
+
"#{name}.errors"
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy
|
52
|
+
"#{name}.destroy"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module Rails
|
60
|
+
module Generators
|
61
|
+
class GeneratedAttribute #:nodoc:
|
62
|
+
def declaration
|
63
|
+
declaration = @name
|
64
|
+
declaration << ", :cast_as => '#{@type}'" unless !self.default.to_s.empty?
|
65
|
+
declaration
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Couchrest
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
desc "Creates a CouchRest initializer for your application."
|
6
|
+
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
template "couch_config.rb", "config/initializers/couch_config.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_readme
|
14
|
+
readme "README"
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def readme(path)
|
20
|
+
say File.read(File.expand_path(path, self.class.source_root))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class <%= class_name %> < <%= options[:parent] != nil ? options[:parent].classify : 'CouchRest::Model::Base' %>
|
2
|
+
use_database '<%= class_name..underscore %>'
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
property :<%= attribute.declaration %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
timestamps!
|
8
|
+
|
9
|
+
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 1
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.0.
|
9
|
+
- beta9
|
10
|
+
version: 1.0.0.beta9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J. Chris Anderson
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2010-07-
|
22
|
+
date: 2010-07-30 00:00:00 +03:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -141,6 +141,11 @@ files:
|
|
141
141
|
- lib/couchrest/model/class_proxy.rb
|
142
142
|
- lib/couchrest/model/associations.rb
|
143
143
|
- lib/couchrest/model.rb
|
144
|
+
- lib/generators/couchrest/install_generator.rb
|
145
|
+
- lib/generators/couchrest/couch_rest_generator.rb
|
146
|
+
- lib/generators/couchrest/templates/model.erb
|
147
|
+
- lib/generators/couchrest/templates/README
|
148
|
+
- lib/generators/couchrest/templates/couch_config.rb
|
144
149
|
- spec/spec.opts
|
145
150
|
- spec/couchrest/view_spec.rb
|
146
151
|
- spec/couchrest/persistence_spec.rb
|