reactive-activerecord 0.2.0

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.
@@ -0,0 +1,19 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ <% unless attributes.empty? -%>
4
+ one:
5
+ <% for attribute in attributes -%>
6
+ <%= attribute.name %>: <%= attribute.default %>
7
+ <% end -%>
8
+
9
+ two:
10
+ <% for attribute in attributes -%>
11
+ <%= attribute.name %>: <%= attribute.default %>
12
+ <% end -%>
13
+ <% else -%>
14
+ # one:
15
+ # column: value
16
+ #
17
+ # two:
18
+ # column: value
19
+ <% end -%>
@@ -0,0 +1,16 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= plural_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ <% unless options[:skip_timestamps] %>
8
+ t.timestamps
9
+ <% end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= plural_name %>
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting.size %>/../test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ def test_truth
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ Description:
2
+ Generates an entire resource, from model and migration to controller and
3
+ views, along with a full test suite. The resource is ready to use as a
4
+ starting point for your CRUD resource-oriented application.
5
+ You still have to fill in the views.
6
+ The generated actions are:
7
+ index, show, new, create, edit, update, delete, destroy
8
+
9
+ Pass the name of the model, either CamelCased or under_scored, as the first
10
+ argument, and an optional list of attribute pairs that will be used for the
11
+ database migration.
12
+
13
+ Attribute pairs are column_name:sql_type arguments specifying the
14
+ model's attributes. Timestamps are added by default, so you don't have to
15
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
16
+
17
+ You don't have to think up every attribute up front, but it helps to
18
+ sketch out a few so you can start working with the resource immediately.
19
+
20
+ For example, `scaffold resource name:string description:text price:decimal`
21
+ gives you a model with those three attributes and a controller that handles
22
+ the create/show/update/destroy.
23
+
24
+ Examples:
25
+ `./script/generate resource product`
26
+ `./script/generate resource product name:string description:text price:decimal`
27
+ `./script/generate resource purchase order_id:integer amount:decimal`
@@ -0,0 +1,39 @@
1
+ class ResourceGenerator < Reactive::NamedBaseGenerator
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions(path, "#{plural_class_name}Controller")
6
+
7
+ # Controller, helper, views, and test directories.
8
+ m.directory(Reactive.relative_path_for(:controller, path))
9
+ m.directory(Reactive.relative_path_for(:helper, path))
10
+
11
+ m.template('controller.rb', Reactive.relative_path_for(:controller, path, "#{plural_name}_controller.rb"))
12
+ m.template('helper.rb', Reactive.relative_path_for(:helper, path, "#{plural_name}_helper.rb"))
13
+ # m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
14
+
15
+ m.dependency('model', [name] + @args, {:collision => :ask}.merge(@options))
16
+ m.dependency('view', [name] + @args, {:collision => :ask}.merge(@options)) unless options[:no_views]
17
+ end
18
+ end
19
+
20
+ protected
21
+ # Override with your own usage banner.
22
+ def banner
23
+ "Usage: #{$0} resource name [field:type, field:type]"
24
+ end
25
+
26
+ def add_options!(opt)
27
+ opt.separator ''
28
+ opt.separator 'Options:'
29
+ opt.on("--skip-timestamps",
30
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
31
+ opt.on("--skip-migration",
32
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
33
+ opt.on("--skip-fixture",
34
+ "Don't generate a fixture file for this model") { |v| options[:skip_fixture] = v}
35
+ opt.on("--no-views",
36
+ "Don't generate views for this resource") { |v| options[:no_views] = v}
37
+ end
38
+
39
+ end
@@ -0,0 +1,51 @@
1
+ class <%= plural_class_name %>Controller < ApplicationController
2
+
3
+ def index
4
+ @<%= plural_name %> = <%= class_name %>.find(:all)
5
+ end
6
+
7
+ def show
8
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
9
+ end
10
+
11
+ def new
12
+ @<%= singular_name %> = <%= class_name %>.new
13
+ end
14
+
15
+ def edit
16
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
17
+ end
18
+
19
+ def create
20
+ @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
21
+
22
+ if @<%= singular_name %>.save
23
+ flash[:notice] = '<%= singular_class_name %> was successfully created.'
24
+ else
25
+ count = @<%= singular_name %>.errors.count
26
+ flash[:notice] = count == 1 ? "There is one error, please correct it." : "There are #{count} errors, please correct them."
27
+ render :action => "new"
28
+ end
29
+ end
30
+
31
+ def update
32
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
33
+
34
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
35
+ flash[:notice] = '<%= singular_class_name %> was successfully updated.'
36
+ else
37
+ count = @<%= singular_name %>.errors.count
38
+ flash[:notice] = count == 1 ? "There is one error, please correct it." : "There are #{count} errors, please correct them."
39
+ render :action => "edit"
40
+ end
41
+ end
42
+
43
+ def delete
44
+ @<%= plural_name %> = [<%= class_name %>.find(params[:id])].flatten
45
+ end
46
+
47
+ def destroy
48
+ @<%= plural_name %> = [<%= class_name %>.find(params[:id])].flatten
49
+ @<%= plural_name %>.map(&:destroy)
50
+ end
51
+ end
@@ -0,0 +1,2 @@
1
+ module <%= plural_class_name %>Helper
2
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reactive-activerecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Pascal Hurni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-11 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: reactive-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ version:
35
+ description: Provides ActiveRecord for the ORM used by the reactive-mvc plugin.
36
+ email: phi@ruby-reactive.org
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - LICENSE
44
+ files:
45
+ - README
46
+ - LICENSE
47
+ - Manifest
48
+ - Rakefile
49
+ - lib/activerecord_meta_model.rb
50
+ - lib/reactive-activerecord.rb
51
+ - lib/tasks/databases.rake
52
+ - reactive_app_generators/activerecord/USAGE
53
+ - reactive_app_generators/activerecord/activerecord_generator.rb
54
+ - reactive_app_generators/activerecord/templates/frontbase.yml
55
+ - reactive_app_generators/activerecord/templates/ibm_db.yml
56
+ - reactive_app_generators/activerecord/templates/mysql.yml
57
+ - reactive_app_generators/activerecord/templates/oracle.yml
58
+ - reactive_app_generators/activerecord/templates/postgresql.yml
59
+ - reactive_app_generators/activerecord/templates/sqlite2.yml
60
+ - reactive_app_generators/activerecord/templates/sqlite3.yml
61
+ - reactive_generators/model/USAGE
62
+ - reactive_generators/model/model_generator.rb
63
+ - reactive_generators/model/templates/fixtures.yml
64
+ - reactive_generators/model/templates/migration.rb
65
+ - reactive_generators/model/templates/model.rb
66
+ - reactive_generators/model/templates/unit_test.rb
67
+ - reactive_generators/resource/USAGE
68
+ - reactive_generators/resource/resource_generator.rb
69
+ - reactive_generators/resource/templates/controller.rb
70
+ - reactive_generators/resource/templates/helper.rb
71
+ has_rdoc: true
72
+ homepage: http://www.ruby-reactive.org
73
+ post_install_message:
74
+ rdoc_options:
75
+ - -x
76
+ - Manifest
77
+ - -x
78
+ - Rakefile
79
+ - -x
80
+ - .*\.rake
81
+ - -m
82
+ - README
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements: []
98
+
99
+ rubyforge_project: reactive-activerecord
100
+ rubygems_version: 1.3.1
101
+ signing_key:
102
+ specification_version: 2
103
+ summary: Reactive plugin that provides ActiveRecord support for Models.
104
+ test_files: []
105
+