acts_in_relation 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98631806c248ec6a232438391598ca3c3b6d1429
4
- data.tar.gz: 15a8894cde8f8da9d753d647be4220c4c373d0f6
3
+ metadata.gz: 4fe38daa27d165526d7e9e12500dc6c912a09ecd
4
+ data.tar.gz: 962ba4832d57d659960ca05cb80035f293c0262e
5
5
  SHA512:
6
- metadata.gz: cab9fb68c574f05868c3abc17c5cd26638ab901041f6008cc8996e231398bc8087d3002201ead3e2f9ba60cbfd98e9d87e4ab6b965ec040c523233f97f8cf297
7
- data.tar.gz: 2b754e9fb4eacba5be95acbdb2dc7eff4adf15220ab32afd96bd87008b90ba4110356b404db0564727cc30d5c5611d359ea722bd992bd2991dff94b76c0f9ce3
6
+ metadata.gz: 24b69788f633b82dfd277d4ffe6eee078e2edc42018f6f40698328a2a38d5627c19b429485cfd64d026e10de670787a49263dfd23dc6f80b40ffb6c63bdeec0c
7
+ data.tar.gz: 26a752c79a045ba6595c36d6387134df630e89dab1a66f24e0ab9b331118b2a6e19cb1be7071e877c5d1ac2d1df256b5918305e2bda50725ddffb8faf4e2c4f0
data/.gitignore CHANGED
@@ -1,9 +1,6 @@
1
1
  .bundle/
2
- log/*.log
3
2
  pkg/
4
- spec/dummy/db/*.sqlite3
5
- spec/dummy/db/*.sqlite3-journal
6
- spec/dummy/log/*.log
3
+ spec/dummy/db
4
+ spec/dummy/log
7
5
  spec/dummy/tmp/
8
- spec/dummy/.sass-cache
9
6
  Gemfile.lock
data/README.md CHANGED
@@ -142,6 +142,20 @@ acts_in_relation has three roles: source, target and action.
142
142
  | target | The model that receives the action. | User | Post |
143
143
  | action | The action performs between two models. | Follow | Like |
144
144
 
145
+ ## Generate migration
146
+
147
+ You can generate migration by generator:
148
+
149
+ ```
150
+ $ rails generate acts_in_relation:action [action] --source=[source] --target=[target]
151
+ ```
152
+
153
+ For example:
154
+
155
+ ```
156
+ $ rails generate acts_in_relation:action like --source=user --target=post
157
+ ```
158
+
145
159
  ## Contributing
146
160
 
147
161
  1. Fork it ( https://github.com/kami30k/acts_in_relation/fork )
@@ -1,3 +1,3 @@
1
1
  module ActsInRelation
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActsInRelation
4
+ module Generators
5
+ class ActionGenerator < ActiveRecord::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ argument :name, required: true, banner: '[action] --source=[source] --target=[target]'
9
+
10
+ class_option :source, required: true, aliases: '-s'
11
+ class_option :target, required: true, aliases: '-t'
12
+
13
+ def copy_migration
14
+ if migration_exists?
15
+ migration_template 'add.rb.erb', "db/migrate/add_columns_to_#{table_name}.rb"
16
+ else
17
+ migration_template 'create.rb.erb', "db/migrate/create_#{table_name}.rb"
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def migration_exists?
24
+ Dir.glob("#{migration_path}/[0-9]*_*.rb").grep(/\d+_create_#{table_name}.rb$/).present?
25
+ end
26
+
27
+ def migration_path
28
+ Rails.root.join('db/migrate')
29
+ end
30
+
31
+ def table_name
32
+ name.downcase.pluralize
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ class AddColumnsTo<%= table_name.capitalize %> < ActiveRecord::Migration
2
+ def change
3
+ add_column :<%= table_name %>, :<%= options[:source] %>_id, :integer
4
+ add_column :<%= table_name %>, :target_<%= options[:target] %>_id, :integer
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class Create<%= table_name.capitalize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ t.integer :<%= options[:source] %>_id
5
+ t.integer :target_<%= options[:target] %>_id
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ $:.unshift File.expand_path('../../../lib', __FILE__)
2
+
1
3
  require 'action_controller/railtie'
2
4
  require 'active_record'
3
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_in_relation
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
  - kami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-11 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -102,6 +102,9 @@ files:
102
102
  - lib/acts_in_relation/roles/target.rb
103
103
  - lib/acts_in_relation/supports/verb.rb
104
104
  - lib/acts_in_relation/version.rb
105
+ - lib/generators/acts_in_relation/action_generator.rb
106
+ - lib/generators/acts_in_relation/templates/add.rb.erb
107
+ - lib/generators/acts_in_relation/templates/create.rb.erb
105
108
  - spec/dummy/application.rb
106
109
  - spec/dummy/bin/rails
107
110
  - spec/dummy/config.ru
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
131
  version: '0'
129
132
  requirements: []
130
133
  rubyforge_project:
131
- rubygems_version: 2.4.6
134
+ rubygems_version: 2.4.5
132
135
  signing_key:
133
136
  specification_version: 4
134
137
  summary: Add relational feature to Rails (e.g. follow, block and like).