acts_as_lockable 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a17326305d42a095c6b0107527ff232957f4996
4
- data.tar.gz: 5f259a7639d89ad068b9e2894a8c921817a9783e
3
+ metadata.gz: 9d1f65e440c52da4d26577a216441a4dc9036aad
4
+ data.tar.gz: 80c8df26f287cc4e8a0360326083f3cc1759965f
5
5
  SHA512:
6
- metadata.gz: 440c3e9c205b3196545f76f085b2baa4e3d986e0fe358f662a9879ea7ff5070f13ff25f62a1f68d2f23df616f898d09b9a49d8daaa0e5c233a03d8fb50c4fa8b
7
- data.tar.gz: fe337f453ab40967b3306e52f16e723cc8ceb62452de396868327831c93931fc221e12cb69c944ae688f8b39a67d909e11a9b0c589a8886b455c2e907abe8a84
6
+ metadata.gz: ef5788b86d5cecd94764b2cc913dacea16065edc248dff876bac626c88bdfd1702dd735a1028b0ff64e588a167887d06a4c7e9816042d4e4f313f92b2fdca7fe
7
+ data.tar.gz: e894900d21564d686e9ce87e0800f74ffa7dcacf862a3b8f6a33595dbcf2cd9f7812f20ce73912c2ff343cc2a9e8042192fdd82a0e1dd94158cba7392e503abe
data/README.md CHANGED
@@ -18,27 +18,18 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install acts_as_lockable
20
20
 
21
- #### Run your migrations for the desired models
21
+ #### Database Migrations
22
22
 
23
23
  Run:
24
24
 
25
25
  ``` shell
26
- rails generate migration AddIsLockedToLockers is_locked:boolean
27
- ```
28
-
29
- and now you have a migration
30
-
31
- ``` ruby
32
- class AddIsLockedToLockers < ActiveRecord::Migration
33
- def change
34
- add_column :lockers, :is_locked, :boolean
35
- end
36
- end
26
+ rails generate acts_as_lockable:migration
27
+ rake db:migrate
37
28
  ```
38
29
 
39
30
  ## Usage
40
31
 
41
- #### In your model:
32
+ #### Lockable Models
42
33
 
43
34
  ``` ruby
44
35
  class Locker < ActiveRecord::Base
@@ -47,7 +38,15 @@ class Locker < ActiveRecord::Base
47
38
  # ...
48
39
  end
49
40
  ```
41
+ #### Example
42
+
43
+ ``` ruby
44
+ lovely_locker = Locker.create
45
+ lovely_locker.lock
46
+ lovely_locker.unlock
47
+ lovely_locker.is_locked?
50
48
 
49
+ ```
51
50
 
52
51
  ## Development
53
52
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsLockable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,31 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module ActsAsLockable
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ desc "Generates migration for lockable (locks table)"
8
+
9
+ def self.orm
10
+ Rails::Generators.options[:rails][:orm]
11
+ end
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
15
+ end
16
+
17
+ def self.orm_has_migration?
18
+ [:active_record].include? orm
19
+ end
20
+
21
+ def self.next_migration_number(path)
22
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ end
24
+
25
+ def create_migration_file
26
+ if self.class.orm_has_migration?
27
+ migration_template 'migration.rb', 'db/migrate/acts_as_lockable_migration.rb'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ class ActsAsLockableMigration < ActiveRecord::Migration
2
+ def change
3
+ create_table :locks do |t|
4
+ t.integer :locked_id
5
+ t.string :locked_type
6
+ end
7
+ add_index :locks, :locked_id
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_lockable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GIZIPP
@@ -102,6 +102,8 @@ files:
102
102
  - lib/acts_as_lockable/lock.rb
103
103
  - lib/acts_as_lockable/locker.rb
104
104
  - lib/acts_as_lockable/version.rb
105
+ - lib/generators/acts_as_lockable/migration/migration_generator.rb
106
+ - lib/generators/acts_as_lockable/migration/templates/active_record/migration.rb
105
107
  homepage: https://github.com/gizipp/acts_as_lockable
106
108
  licenses:
107
109
  - MIT