grape_bunch 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/active_record/grape_bunch_generator.rb +43 -0
- data/lib/generators/active_record/templates/migration.rb +15 -0
- data/lib/generators/active_record/templates/migration_existing.rb +17 -0
- data/lib/generators/grape_bunch/grape_bunch_generator.rb +24 -0
- data/lib/generators/grape_bunch/orm_helpers.rb +21 -0
- data/lib/grape_bunch/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4045a9c2ad1c96eda572a6c08a23984f7cb593f
|
4
|
+
data.tar.gz: 64be5181757d0c741804470dd5aaaa9da5d090d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54e22e5bb11aa45e2c6174f6787729df4c5baacbb267d0f320f8ff0fdde13287914eb2204a1b30eea1f4df1ed3f5f4b660f96ad1ca918d1bcf671c1cc7cbb1a2
|
7
|
+
data.tar.gz: 7460141525bdf485c81f0ba4fac9ec01b4b2a10cbb95691e385ff2c4a9400a3efb00ebcc27a93280770e4f3d5a7a12e4734e150b3433f7889aa0cfce5f06e7cb
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/grape_bunch/orm_helpers'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class GrapeBunchGenerator < ActiveRecord::Generators::Base
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
8
|
+
|
9
|
+
include GrapeBunch::Generators::OrmHelpers
|
10
|
+
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
def copy_grape_bunch_migration
|
14
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
15
|
+
migration_template "migration_existing.rb", "db/migrate/add_grape_bunch_to_#{table_name}.rb", migration_version: migration_version
|
16
|
+
else
|
17
|
+
migration_template "migration.rb", "db/migrate/grape_bunch_create_#{table_name}.rb", migration_version: migration_version
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_model
|
22
|
+
invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
|
23
|
+
end
|
24
|
+
|
25
|
+
def migration_data
|
26
|
+
<<RUBY
|
27
|
+
t.string :email, null: false, default: ""
|
28
|
+
RUBY
|
29
|
+
end
|
30
|
+
|
31
|
+
def rails5?
|
32
|
+
Rails.version.start_with? '5'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def migration_version
|
37
|
+
if rails5?
|
38
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class GrapeBunchCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
<%= migration_data -%>
|
5
|
+
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
t.timestamps null: false
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :<%= table_name %>, :email, unique: true
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddGrapeBunchTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def self.up
|
3
|
+
change_table :<%= table_name %> do |t|
|
4
|
+
<%= migration_data -%>
|
5
|
+
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :<%= table_name %>, :email, unique: true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
raise ActiveRecord::IrreversibleMigration
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module GrapeBunch
|
4
|
+
module Generators
|
5
|
+
class GrapeBunchGenerator < Rails::Generators::NamedBase
|
6
|
+
include Rails::Generators::ResourceHelpers
|
7
|
+
|
8
|
+
namespace "grape_bunch"
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
desc "Generates a model with the given NAME (if one does not exist) with grape_bunch " <<
|
12
|
+
"configuration plus a migration file and grape_bunch routes."
|
13
|
+
|
14
|
+
hook_for :orm
|
15
|
+
|
16
|
+
# def add_grape_bunch_routes
|
17
|
+
# grape_bunch_route = "grape_bunch_for :#{plural_name}"
|
18
|
+
# grape_bunch_route << %Q(, class_name: "#{class_name}") if class_name.include?("::")
|
19
|
+
# grape_bunch_route << %Q(, skip: :all) unless options.routes?
|
20
|
+
# route grape_bunch_route
|
21
|
+
# end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GrapeBunch
|
2
|
+
module Generators
|
3
|
+
module OrmHelpers
|
4
|
+
def model_exists?
|
5
|
+
File.exist?(File.join(destination_root, model_path))
|
6
|
+
end
|
7
|
+
|
8
|
+
def migration_exists?(table_name)
|
9
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_grape_bunch_to_#{table_name}.rb$/).first
|
10
|
+
end
|
11
|
+
|
12
|
+
def migration_path
|
13
|
+
@migration_path ||= File.join("db", "migrate")
|
14
|
+
end
|
15
|
+
|
16
|
+
def model_path
|
17
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/grape_bunch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_bunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mykyta Troianov
|
@@ -100,10 +100,15 @@ executables: []
|
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
+
- lib/generators/active_record/grape_bunch_generator.rb
|
104
|
+
- lib/generators/active_record/templates/migration.rb
|
105
|
+
- lib/generators/active_record/templates/migration_existing.rb
|
106
|
+
- lib/generators/grape_bunch/grape_bunch_generator.rb
|
103
107
|
- lib/generators/grape_bunch/install_generator.rb
|
108
|
+
- lib/generators/grape_bunch/orm_helpers.rb
|
104
109
|
- lib/grape_bunch.rb
|
105
110
|
- lib/grape_bunch/version.rb
|
106
|
-
homepage: https://
|
111
|
+
homepage: https://gitlab.com/NickTroy/grape_bunch.git
|
107
112
|
licenses:
|
108
113
|
- MIT
|
109
114
|
metadata: {}
|