jfs-generators 0.1.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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jason Stahl.
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.md ADDED
@@ -0,0 +1,9 @@
1
+ generators
2
+ ==========
3
+
4
+ Description goes here.
5
+
6
+ Copyright
7
+ ---------
8
+
9
+ Copyright (c) 2009 Jason Stahl. See LICENSE for details.
data/lib/generators.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Generators
2
+ # empty
3
+ end
@@ -0,0 +1,57 @@
1
+ class JfsModelGenerator < Rails::Generator::Base
2
+
3
+ attr_accessor :name, :attributes
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ usage if @args.empty?
8
+
9
+ @name = @args.first
10
+ @attributes = []
11
+
12
+ @args[1..-1].each do |arg|
13
+ @attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
14
+ end
15
+ @attributes.uniq!
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ m.directory "app/models"
21
+ m.template "model.rb", "app/models/#{singular_name}.rb"
22
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
23
+ end
24
+ end
25
+
26
+ def singular_name
27
+ name.underscore.singularize
28
+ end
29
+
30
+ def plural_name
31
+ name.underscore.pluralize
32
+ end
33
+
34
+ def class_name
35
+ singular_name.camelize
36
+ end
37
+
38
+ def plural_class_name
39
+ plural_name.camelize
40
+ end
41
+
42
+ def gen_attr_accessor(attribute)
43
+ case attribute.type
44
+ when :belongs_to
45
+ "attr_accessor :#{attribute.name}_ids"
46
+ else
47
+ "attr_accessor :#{attribute.name}"
48
+ end
49
+ end
50
+
51
+ protected
52
+
53
+ def banner
54
+ "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
55
+ end
56
+
57
+ end
@@ -0,0 +1,14 @@
1
+ class Create<%= plural_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= plural_name %> do |t|
4
+ <%- attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :<%= plural_name %>
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ <%- attributes.each do |attribute| -%>
3
+ <%- if attribute.type.eql? :belongs_to -%>
4
+ belongs_to :<%= attribute.name %>
5
+ <%- end -%>
6
+ <%- end -%>
7
+ <%- attributes.each do |attribute| -%>
8
+ <%= gen_attr_accessor attribute %>
9
+ <%- end -%>
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class GeneratorsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'generators'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jfs-generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Stahl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: My collection of Ruby on Rails generators.
17
+ email: jason@jasonstahl.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.md
25
+ files:
26
+ - lib/generators.rb
27
+ - rails_generators/jfs_model/jfs_model_generator.rb
28
+ - rails_generators/jfs_model/templates/migration.rb
29
+ - rails_generators/jfs_model/templates/model.rb
30
+ - LICENSE
31
+ - README.md
32
+ has_rdoc: false
33
+ homepage: http://github.com/jfs/generators
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --charset=UTF-8
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.2.0
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: My collection of Ruby on Rails generators.
58
+ test_files:
59
+ - test/generators_test.rb
60
+ - test/test_helper.rb