locker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -90,37 +90,13 @@ Otherwise you can just `gem install locker`.
90
90
 
91
91
  This gem includes generators for Rails 3.0+:
92
92
 
93
- ```bash
94
- script/rails generate locker [ModelName]
95
- ```
96
-
97
- The 'ModelName' defaults to 'Lock'. This will generate the Lock model and its migration.
93
+ `script/rails generate locker [ModelName]`
98
94
 
99
- I apologize if you're using Rails 2.3.x, I couldn't be arsed to figure out how to make generators for it and Rails 3.x+, so you'll need to create the migration and the model yourself:
95
+ In Rails 2.3.x+:
100
96
 
101
- ```ruby
102
- class CreateLocks < ActiveRecord::Migration
103
- def self.up
104
- create_table :locks do |t|
105
- t.string :locked_by
106
- t.string :key
107
- t.datetime :locked_at
108
- t.datetime :locked_until
109
- end
110
-
111
- add_index :locks, :key, :unique => true
112
- end
97
+ `script/generate locker [ModelName]`
113
98
 
114
- def self.down
115
- drop_table :locks
116
- end
117
- end
118
- ```
119
-
120
- ```ruby
121
- class Lock < ActiveRecord::Base
122
- end
123
- ```
99
+ The 'ModelName' defaults to 'Lock' if not specified. This will generate the Lock model and its migration.
124
100
 
125
101
  ## Advanced Usage
126
102
 
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Generate a 'Lock' model for use with the Locker gem.
3
+
4
+ Example:
5
+ script/generate locker [Lock]
6
+
7
+ 'Lock' is the model name to use for the model.
8
+
9
+ This will create:
10
+ db/migrations/123456_create_locks.rb
11
+ app/models/locks.rb
@@ -0,0 +1,28 @@
1
+ class LockerGenerator < Rails::Generator::Base
2
+ attr_reader :name
3
+
4
+ def initialize(runtime_args, runtime_options={})
5
+ super
6
+ @name = (runtime_args.first || "lock").underscore
7
+ end
8
+
9
+ def manifest
10
+ record do |m|
11
+ m.directory "app/models"
12
+ m.template "model.rb", "app/models/#{name}.rb"
13
+ m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
14
+ end
15
+ end
16
+
17
+ def plural_name
18
+ name.pluralize
19
+ end
20
+
21
+ def plural_class_name
22
+ plural_name.camelize
23
+ end
24
+
25
+ def class_name
26
+ name.camelize
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ class Create<%= plural_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= plural_name %> do |t|
4
+ t.string :locked_by
5
+ t.string :key
6
+ t.datetime :locked_at
7
+ t.datetime :locked_until
8
+ end
9
+
10
+ add_index :<%= plural_name %>, :key, :unique => true
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
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Explain the generator
2
+ Generate a 'Lock' model for use with the Locker gem.
3
3
 
4
4
  Example:
5
5
  rails generate locker [Lock]
@@ -1,3 +1,3 @@
1
1
  class Locker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nathan Sutton
@@ -93,6 +93,10 @@ files:
93
93
  - README.md
94
94
  - Rakefile
95
95
  - autotest/discover.rb
96
+ - generators/locker/USAGE
97
+ - generators/locker/locker_generator.rb
98
+ - generators/locker/templates/migration.rb
99
+ - generators/locker/templates/model.rb
96
100
  - lib/generators/locker/USAGE
97
101
  - lib/generators/locker/locker_generator.rb
98
102
  - lib/generators/locker/templates/migration.rb