rammer 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MODULE_FILES +9 -3
- data/bin/rammer +39 -2
- data/bin/viber +6 -2
- data/lib/modules/scaffold/base_apis.rb +62 -0
- data/lib/modules/scaffold/migration.rb +39 -0
- data/lib/modules/scaffold/model.rb +89 -0
- data/lib/rammer.rb +1 -0
- data/lib/rammer/module_generator.rb +36 -39
- data/lib/rammer/rammer_generator.rb +30 -32
- data/lib/rammer/reserved_words.rb +70 -0
- data/lib/rammer/scaffold_generator.rb +227 -0
- data/lib/rammer/version.rb +1 -1
- data/test/{test_rammer_root_structure.rb → hierarchy/test_rammer_root_structure.rb} +5 -4
- data/test/scaffold/test_scaffold_generator.rb +59 -0
- data/test/{test_viber_module_plugin.rb → viber/test_viber_module_plugin.rb} +1 -2
- data/test/{test_viber_module_unplug.rb → viber/test_viber_module_unplug.rb} +2 -2
- metadata +16 -14
data/MODULE_FILES
CHANGED
@@ -2,6 +2,8 @@ lib/rammer.rb
|
|
2
2
|
lib/rammer/version.rb
|
3
3
|
lib/rammer/rammer_generator.rb
|
4
4
|
lib/rammer/module_generator.rb
|
5
|
+
lib/rammer/scaffold_generator.rb
|
6
|
+
lib/rammer/reserved_words.rb
|
5
7
|
lib/modules/migrations/01_create_users.rb
|
6
8
|
lib/modules/migrations/02_create_sessions.rb
|
7
9
|
lib/modules/migrations/03_create_owners.rb
|
@@ -23,10 +25,14 @@ lib/modules/common/server.rb
|
|
23
25
|
lib/modules/models/session.rb
|
24
26
|
lib/modules/common/tree.rb
|
25
27
|
lib/modules/models/user.rb
|
28
|
+
lib/modules/scaffold/model.rb
|
29
|
+
lib/modules/scaffold/migration.rb
|
30
|
+
lib/modules/scaffold/base_apis.rb
|
26
31
|
test/helper.rb
|
27
|
-
test/test_rammer_root_structure.rb
|
28
|
-
test/
|
29
|
-
test/
|
32
|
+
test/hierarchy/test_rammer_root_structure.rb
|
33
|
+
test/scaffold/test_scaffold_generator.rb
|
34
|
+
test/viber/test_viber_module_plugin.rb
|
35
|
+
test/viber/test_viber_module_unplug.rb
|
30
36
|
Gemfile
|
31
37
|
LICENSE.txt
|
32
38
|
README.md
|
data/bin/rammer
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rammer'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
#Returns usage message
|
5
|
+
def options_message
|
6
|
+
STDOUT.puts <<-EOF
|
7
|
+
Please provide command options
|
8
|
+
|
9
|
+
Usage:
|
10
|
+
rammer generate/g scaffold [scaffold_name] [field_name:type]
|
11
|
+
EOF
|
12
|
+
end
|
13
|
+
|
14
|
+
#Validates the command line arguments for invoking generators.
|
15
|
+
def validate_options
|
16
|
+
scaffold_generator = true
|
17
|
+
case ARGV[1]
|
18
|
+
when 'scaffold'
|
19
|
+
unless ARGV[2].nil?
|
20
|
+
argv = ARGV.drop(3)
|
21
|
+
target_dir = Dir.pwd.split('/',Dir.pwd.count('/')+1).last
|
22
|
+
options = { :project_name => target_dir, :scaffold_name => ARGV[2], :arguments => argv}
|
23
|
+
scaffold_generator = Rammer::ScaffoldGenerator.new(options)
|
24
|
+
scaffold_generator.run
|
25
|
+
else
|
26
|
+
options_message
|
27
|
+
end
|
28
|
+
else
|
29
|
+
options_message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#Execution initiates here.
|
34
|
+
case ARGV[0]
|
35
|
+
when 'g', 'generate'
|
36
|
+
validate_options
|
37
|
+
when nil
|
38
|
+
$stdout.puts "\e[1;31mError:\e[0m Please specify an application name."
|
39
|
+
else
|
40
|
+
generator = Rammer::RammerGenerator.new(*ARGV)
|
41
|
+
generator.run
|
42
|
+
end
|
data/bin/viber
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rammer'
|
3
3
|
|
4
|
+
#Validates command line arguments.
|
4
5
|
def parse_options
|
5
6
|
case ARGV[1]
|
6
7
|
when "-p", "-plugin"
|
@@ -12,12 +13,13 @@ def parse_options
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
#Returns usage message
|
15
17
|
def options_message
|
16
18
|
STDOUT.puts <<-EOF
|
17
19
|
Please include module name
|
18
20
|
|
19
21
|
Usage:
|
20
|
-
viber module #{ARGV[1]}
|
22
|
+
viber module #{ARGV[1]} [options]
|
21
23
|
|
22
24
|
options:
|
23
25
|
authentication
|
@@ -26,6 +28,7 @@ Usage:
|
|
26
28
|
EOF
|
27
29
|
end
|
28
30
|
|
31
|
+
#Builds parameters and invokes the generator.
|
29
32
|
def execute(module_name,action)
|
30
33
|
target_dir = Dir.pwd.split('/',Dir.pwd.count('/')+1).last
|
31
34
|
name = target_dir.split('_').map(&:capitalize)*''
|
@@ -43,6 +46,7 @@ def execute(module_name,action)
|
|
43
46
|
module_generator.run
|
44
47
|
end
|
45
48
|
|
49
|
+
#Execution initiates here.
|
46
50
|
case ARGV[0]
|
47
51
|
when "module"
|
48
52
|
if parse_options
|
@@ -62,7 +66,7 @@ when "module"
|
|
62
66
|
Please provide command options
|
63
67
|
|
64
68
|
Usage:
|
65
|
-
viber module
|
69
|
+
viber module [options]
|
66
70
|
|
67
71
|
options:
|
68
72
|
-p,-plugin :Plugs in rammer specified modules.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
=begin
|
2
|
+
**************************************************************************
|
3
|
+
* The MIT License (MIT)
|
4
|
+
|
5
|
+
* Copyright (c) 2013-2014 QBurst Technologies Inc.
|
6
|
+
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
|
25
|
+
**************************************************************************
|
26
|
+
=end
|
27
|
+
|
28
|
+
module AppName
|
29
|
+
module ScaffoldName
|
30
|
+
class BaseApis < Grape::API
|
31
|
+
format :json
|
32
|
+
|
33
|
+
=begin
|
34
|
+
Handles read functionality
|
35
|
+
=end
|
36
|
+
get '/model' do
|
37
|
+
Model.read
|
38
|
+
end
|
39
|
+
|
40
|
+
=begin
|
41
|
+
Handles new record creation
|
42
|
+
=end
|
43
|
+
post '/model' do
|
44
|
+
Model.create(params)
|
45
|
+
end
|
46
|
+
|
47
|
+
=begin
|
48
|
+
Handles a record updation with respect to record id passed
|
49
|
+
=end
|
50
|
+
post '/model/:id' do
|
51
|
+
Model.edit(params)
|
52
|
+
end
|
53
|
+
|
54
|
+
=begin
|
55
|
+
Handles a record deletion with respect to record id passed
|
56
|
+
=end
|
57
|
+
delete '/model/:id' do
|
58
|
+
Model.destroy(params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
=begin
|
2
|
+
**************************************************************************
|
3
|
+
* The MIT License (MIT)
|
4
|
+
|
5
|
+
* Copyright (c) 2013-2014 QBurst Technologies Inc.
|
6
|
+
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
|
25
|
+
**************************************************************************
|
26
|
+
=end
|
27
|
+
|
28
|
+
class CreateMigration < ActiveRecord::Migration
|
29
|
+
def self.up
|
30
|
+
create_table :migration do |t|
|
31
|
+
|
32
|
+
t.timestamps
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.down
|
37
|
+
drop_table :migration
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
=begin
|
2
|
+
**************************************************************************
|
3
|
+
* The MIT License (MIT)
|
4
|
+
|
5
|
+
* Copyright (c) 2013-2014 QBurst Technologies Inc.
|
6
|
+
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
|
25
|
+
**************************************************************************
|
26
|
+
=end
|
27
|
+
|
28
|
+
class Model < ActiveRecord::Base
|
29
|
+
|
30
|
+
#Reads all the records
|
31
|
+
def self.read
|
32
|
+
@model = Model.all
|
33
|
+
return @model
|
34
|
+
end
|
35
|
+
|
36
|
+
#Creates new record
|
37
|
+
def self.create(params)
|
38
|
+
param = Model.build_param(params,1)
|
39
|
+
@model = Model.new(param)
|
40
|
+
response = @model.save ? @model.success_response("Added") : @model.error_response
|
41
|
+
return response
|
42
|
+
end
|
43
|
+
|
44
|
+
#Updates a record
|
45
|
+
def self.edit(params)
|
46
|
+
Model.set_model(params)
|
47
|
+
param = Model.build_param(params,2)
|
48
|
+
response = @model.update_attributes(param) ? @model.success_response("Edited") : @model.error_response
|
49
|
+
return response
|
50
|
+
end
|
51
|
+
|
52
|
+
#Deletes a record
|
53
|
+
def self.destroy(params)
|
54
|
+
Model.set_model(params)
|
55
|
+
@model.destroy
|
56
|
+
return @model.success_response("Deleted")
|
57
|
+
end
|
58
|
+
|
59
|
+
# Use callbacks to share common setup or constraints between actions.
|
60
|
+
def self.set_model(params)
|
61
|
+
@model = Model.find(params[:id])
|
62
|
+
end
|
63
|
+
|
64
|
+
#Builds parameter hash to handle the web request parameters.
|
65
|
+
def self.build_param(params,index)
|
66
|
+
param = params.to_a.reverse.drop(index)
|
67
|
+
hash_value = Hash.new
|
68
|
+
param.each do |value|
|
69
|
+
hash_value["#{value.first}"] = value.last
|
70
|
+
end
|
71
|
+
return hash_value
|
72
|
+
end
|
73
|
+
|
74
|
+
#Success response hash
|
75
|
+
def success_response(message)
|
76
|
+
success_message = {
|
77
|
+
"message" => "#{message} successfully.",
|
78
|
+
"details" => self
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
#Error response hash
|
83
|
+
def error_response
|
84
|
+
error_message = {
|
85
|
+
"error" => "Error",
|
86
|
+
"message" => self.errors
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
data/lib/rammer.rb
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
|
28
28
|
require "rammer/version"
|
29
29
|
require 'fileutils'
|
30
|
+
require_relative 'reserved_words'
|
30
31
|
|
31
32
|
$gem_file_name = "rammer-"+Rammer::VERSION
|
32
33
|
|
@@ -37,10 +38,6 @@ and the runs bundle install.
|
|
37
38
|
=end
|
38
39
|
class ModuleGenerator
|
39
40
|
attr_accessor :target_dir, :project_name, :module_class, :module_name, :gem_path, :action
|
40
|
-
AUTH_MIGRATE = ['01_create_users.rb','02_create_sessions.rb']
|
41
|
-
OAUTH_MIGRATE = ['03_create_owners.rb', '04_create_oauth2_authorizations.rb', '05_create_oauth2_clients.rb']
|
42
|
-
AUTH_MODELS = ['user.rb', 'session.rb', 'oauth2_authorization.rb']
|
43
|
-
OAUTH_MODELS = ['oauth2_client.rb', 'owner.rb']
|
44
41
|
|
45
42
|
=begin
|
46
43
|
Initiliazes the following attributes :
|
@@ -48,27 +45,27 @@ Initiliazes the following attributes :
|
|
48
45
|
module_name (rammer module name), action (viber action to plugin or unplug) and gem_path (path at which the gem is installed)
|
49
46
|
=end
|
50
47
|
def initialize(options)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
@project_name = options[:project_name]
|
49
|
+
@module_class = options[:module_class]
|
50
|
+
@module_name = options[:module_name]
|
51
|
+
@action = options[:action]
|
52
|
+
@target_dir = Dir.pwd
|
56
53
|
path = `gem which rammer`
|
57
|
-
|
54
|
+
@gem_path = path.split($gem_file_name,2).first + "/" + $gem_file_name
|
58
55
|
end
|
59
56
|
|
60
57
|
=begin
|
61
58
|
Creates the required files and configuration setup while module plugin or unplug.
|
62
59
|
=end
|
63
60
|
def run
|
64
|
-
case action
|
61
|
+
case @action
|
65
62
|
when "-p","-plugin"
|
66
63
|
flag = require_module_to_base
|
67
64
|
mount_module unless flag
|
68
65
|
copy_module
|
69
66
|
create_migrations_and_models
|
70
67
|
add_gems
|
71
|
-
oauth_message if module_name == "oauth" && !flag
|
68
|
+
oauth_message if @module_name == "oauth" && !flag
|
72
69
|
when "-u","-unplug"
|
73
70
|
unmount_module
|
74
71
|
end
|
@@ -78,39 +75,39 @@ Creates the required files and configuration setup while module plugin or unplug
|
|
78
75
|
Mounts the module onto the application.
|
79
76
|
=end
|
80
77
|
def mount_module
|
81
|
-
file = File.open("#{target_dir}/app/apis/#{project_name}/base.rb", "r+")
|
78
|
+
file = File.open("#{@target_dir}/app/apis/#{@project_name}/base.rb", "r+")
|
82
79
|
file.each do |line|
|
83
80
|
while line == "\tclass Base < Grape::API\n" do
|
84
81
|
pos = file.pos
|
85
82
|
rest = file.read
|
86
83
|
file.seek pos
|
87
84
|
file.write("\t\tmount ")
|
88
|
-
file.puts(module_class)
|
85
|
+
file.puts(@module_class)
|
89
86
|
file.write(rest)
|
90
87
|
break
|
91
88
|
end
|
92
89
|
end
|
93
|
-
$stdout.puts "\e[1;35m\tmounted\e[0m\t#{module_class}"
|
90
|
+
$stdout.puts "\e[1;35m\tmounted\e[0m\t#{@module_class}"
|
94
91
|
end
|
95
92
|
|
96
93
|
=begin
|
97
94
|
Checks whether the module is already mounted and if not then configures for mounting.
|
98
95
|
=end
|
99
96
|
def require_module_to_base
|
100
|
-
file = File.open("#{target_dir}/app/apis/#{project_name}/base.rb", "r+")
|
97
|
+
file = File.open("#{@target_dir}/app/apis/#{@project_name}/base.rb", "r+")
|
101
98
|
file.each do |line|
|
102
|
-
while line == "require_relative './modules/#{module_name}_apis'\n" do
|
99
|
+
while line == "require_relative './modules/#{@module_name}_apis'\n" do
|
103
100
|
$stdout.puts "\e[33mModule already mounted.\e[0m"
|
104
101
|
return true
|
105
102
|
end
|
106
103
|
end
|
107
104
|
|
108
|
-
File.open("#{target_dir}/app/apis/#{project_name}/base.rb", "r+") do |f|
|
105
|
+
File.open("#{@target_dir}/app/apis/#{@project_name}/base.rb", "r+") do |f|
|
109
106
|
pos = f.pos
|
110
107
|
rest = f.read
|
111
108
|
f.seek pos
|
112
109
|
f.write("require_relative './modules/")
|
113
|
-
f.write(module_name)
|
110
|
+
f.write(@module_name)
|
114
111
|
f.write("_apis'\n")
|
115
112
|
f.write(rest)
|
116
113
|
end
|
@@ -121,29 +118,29 @@ Checks whether the module is already mounted and if not then configures for moun
|
|
121
118
|
Function to copy the module of interest to project location.
|
122
119
|
=end
|
123
120
|
def copy_module
|
124
|
-
src = "#{gem_path}/lib/modules/#{module_name}/#{module_name}_apis.rb"
|
125
|
-
dest = "#{target_dir}/app/apis/#{project_name}/modules"
|
126
|
-
presence = File.exists?("#{dest}/#{module_name}_apis.rb")? true : false
|
121
|
+
src = "#{@gem_path}/lib/modules/#{@module_name}/#{@module_name}_apis.rb"
|
122
|
+
dest = "#{@target_dir}/app/apis/#{@project_name}/modules"
|
123
|
+
presence = File.exists?("#{dest}/#{@module_name}_apis.rb")? true : false
|
127
124
|
FileUtils.mkdir dest unless File.exists?(dest)
|
128
125
|
FileUtils.cp(src,dest) unless presence
|
129
126
|
configure_module_files
|
130
|
-
$stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{project_name}/modules/#{module_name}_apis.rb" unless presence
|
127
|
+
$stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{@project_name}/modules/#{@module_name}_apis.rb" unless presence
|
131
128
|
end
|
132
129
|
|
133
130
|
=begin
|
134
131
|
Function to create the necessary migrations and models.
|
135
132
|
=end
|
136
133
|
def create_migrations_and_models
|
137
|
-
src = "#{gem_path}/lib/modules/migrations"
|
138
|
-
dest = "#{target_dir}/db/migrate"
|
134
|
+
src = "#{@gem_path}/lib/modules/migrations"
|
135
|
+
dest = "#{@target_dir}/db/migrate"
|
139
136
|
copy_files(src,dest,AUTH_MIGRATE)
|
140
|
-
if module_name == "oauth"
|
137
|
+
if @module_name == "oauth"
|
141
138
|
copy_files(src,dest,OAUTH_MIGRATE)
|
142
139
|
end
|
143
|
-
src_path = "#{gem_path}/lib/modules/models"
|
144
|
-
dest_path = "#{target_dir}/app/models"
|
140
|
+
src_path = "#{@gem_path}/lib/modules/models"
|
141
|
+
dest_path = "#{@target_dir}/app/models"
|
145
142
|
copy_files(src_path,dest_path,AUTH_MODELS)
|
146
|
-
if module_name == "oauth"
|
143
|
+
if @module_name == "oauth"
|
147
144
|
copy_files(src_path,dest_path,OAUTH_MODELS)
|
148
145
|
end
|
149
146
|
end
|
@@ -166,8 +163,8 @@ Function to copy the module files to project location.
|
|
166
163
|
Function to configure the module files.
|
167
164
|
=end
|
168
165
|
def configure_module_files
|
169
|
-
source = "#{target_dir}/app/apis/#{project_name}/modules/#{module_name}_apis.rb"
|
170
|
-
application_module = project_name.split('_').map(&:capitalize)*''
|
166
|
+
source = "#{@target_dir}/app/apis/#{@project_name}/modules/#{@module_name}_apis.rb"
|
167
|
+
application_module = @project_name.split('_').map(&:capitalize)*''
|
171
168
|
file = File.read(source)
|
172
169
|
replace = file.gsub(/module Rammer/, "module #{application_module}")
|
173
170
|
File.open(source, "w"){|f|
|
@@ -179,13 +176,13 @@ Function to configure the module files.
|
|
179
176
|
Function to add the module dependency gems to project Gemfile.
|
180
177
|
=end
|
181
178
|
def add_gems
|
182
|
-
file = File.open("#{target_dir}/Gemfile", "r+")
|
179
|
+
file = File.open("#{@target_dir}/Gemfile", "r+")
|
183
180
|
file.each do |line|
|
184
181
|
while line == "gem 'oauth2'\n" do
|
185
182
|
return
|
186
183
|
end
|
187
184
|
end
|
188
|
-
File.open("#{target_dir}/Gemfile", "a+") do |f|
|
185
|
+
File.open("#{@target_dir}/Gemfile", "a+") do |f|
|
189
186
|
f.write("gem 'multi_json'\ngem 'oauth2'\ngem 'songkick-oauth2-provider'\ngem 'ruby_regex'\ngem 'oauth'\n")
|
190
187
|
end
|
191
188
|
$stdout.puts "\e[1;35m \tGemfile\e[0m\tgem 'multi_json'\n\t\tgem 'oauth2'
|
@@ -198,15 +195,15 @@ Function to add the module dependency gems to project Gemfile.
|
|
198
195
|
Unmounts the modules by removing the respective module files.
|
199
196
|
=end
|
200
197
|
def unmount_module
|
201
|
-
path = "#{target_dir}/app/apis/#{project_name}"
|
198
|
+
path = "#{@target_dir}/app/apis/#{@project_name}"
|
202
199
|
temp_file = "#{path}/tmp.rb"
|
203
200
|
source = "#{path}/base.rb"
|
204
|
-
delete_file = "#{path}/modules/#{module_name}_apis.rb"
|
201
|
+
delete_file = "#{path}/modules/#{@module_name}_apis.rb"
|
205
202
|
|
206
203
|
File.open(temp_file, "w") do |out_file|
|
207
204
|
File.foreach(source) do |line|
|
208
|
-
unless line == "require_relative './modules/#{module_name}_apis'\n"
|
209
|
-
out_file.puts line unless line == "\t\tmount #{module_class}\n"
|
205
|
+
unless line == "require_relative './modules/#{@module_name}_apis'\n"
|
206
|
+
out_file.puts line unless line == "\t\tmount #{@module_class}\n"
|
210
207
|
end
|
211
208
|
end
|
212
209
|
FileUtils.mv(temp_file, source)
|
@@ -214,8 +211,8 @@ Unmounts the modules by removing the respective module files.
|
|
214
211
|
|
215
212
|
if File.exists?(delete_file)
|
216
213
|
FileUtils.rm(delete_file)
|
217
|
-
$stdout.puts "\e[1;35m\tunmounted\e[0m\t#{module_class}"
|
218
|
-
$stdout.puts "\e[1;31m\tdelete\e[0m\t\tapp/apis/#{project_name}/modules/#{module_name}_apis.rb"
|
214
|
+
$stdout.puts "\e[1;35m\tunmounted\e[0m\t#{@module_class}"
|
215
|
+
$stdout.puts "\e[1;31m\tdelete\e[0m\t\tapp/apis/#{@project_name}/modules/#{@module_name}_apis.rb"
|
219
216
|
else
|
220
217
|
$stdout.puts "\e[33mModule already unmounted.\e[0m"
|
221
218
|
end
|
@@ -27,6 +27,7 @@
|
|
27
27
|
|
28
28
|
require "rammer/version"
|
29
29
|
require 'fileutils'
|
30
|
+
require_relative 'reserved_words'
|
30
31
|
|
31
32
|
$gem_file_name = "rammer-"+Rammer::VERSION
|
32
33
|
|
@@ -36,10 +37,7 @@ module Rammer
|
|
36
37
|
Generator class for creating application basic folder structure
|
37
38
|
=end
|
38
39
|
class RammerGenerator
|
39
|
-
attr_accessor :project_name, :target_dir, :module_name, :gem_path, :valid_name
|
40
|
-
BASE_DIR = ['app', 'app/apis', 'config', 'db', 'db/migrate', 'app/models']
|
41
|
-
COMMON_RAMMER_FILES = ['Gemfile','Gemfile.lock','Procfile','Rakefile','server.rb', 'tree.rb']
|
42
|
-
RESERVED_WORDS = ['rammer', 'viber', 'test', 'lib', 'template', 'authorization', 'authentication', 'app', 'apis', 'models', 'migrate', 'oauth', 'oauth2']
|
40
|
+
attr_accessor :project_name, :target_dir, :module_name, :gem_path, :valid_name
|
43
41
|
|
44
42
|
=begin
|
45
43
|
Initiliazes the following attributes :
|
@@ -47,38 +45,38 @@ Initiliazes the following attributes :
|
|
47
45
|
and gem_path (path at which the gem is installed)
|
48
46
|
=end
|
49
47
|
def initialize(dir_name)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
$stdout.puts "\e[1;31mError:\e[0m Invalid application name #{project_name}. Please give a name which does not match one of the reserved rammer words."
|
57
|
-
self.valid_name = false
|
48
|
+
@project_name = dir_name
|
49
|
+
@valid_name = true
|
50
|
+
|
51
|
+
if RESERVED_WORDS.include? @project_name
|
52
|
+
$stdout.puts "\e[1;31mError:\e[0m Invalid application name #{@project_name}. Please give a name which does not match one of the reserved rammer words."
|
53
|
+
@valid_name = false
|
58
54
|
end
|
59
55
|
|
60
|
-
|
56
|
+
@target_dir = Dir.pwd + "/" + @project_name
|
61
57
|
path = `gem which rammer`
|
62
|
-
|
58
|
+
@gem_path = path.split($gem_file_name,2).first + $gem_file_name
|
63
59
|
end
|
64
60
|
|
65
61
|
=begin
|
66
62
|
Creates a basic folder structure with required files and configuration setup.
|
67
63
|
=end
|
68
64
|
def run
|
69
|
-
unless
|
70
|
-
$stdout.puts "Creating goliath application under the directory #{project_name}"
|
71
|
-
FileUtils.mkdir project_name
|
65
|
+
unless !@valid_name || File.exists?(@project_name) || File.directory?(@project_name)
|
66
|
+
$stdout.puts "Creating goliath application under the directory #{@project_name}"
|
67
|
+
FileUtils.mkdir @project_name
|
72
68
|
|
73
69
|
create_base_dirs
|
74
70
|
copy_files_to_target
|
75
71
|
setup_api_module
|
76
72
|
copy_files_to_dir 'application.rb','config'
|
77
73
|
copy_files_to_dir 'database.yml','config'
|
78
|
-
$stdout.puts "\e[
|
74
|
+
$stdout.puts "\e[1;32m \trun\e[0m\tbundle install"
|
75
|
+
Dir.chdir("#{@project_name}")
|
76
|
+
system("bundle install")
|
79
77
|
else
|
80
|
-
unless
|
81
|
-
$stdout.puts "\e[1;31mError:\e[0m The directory #{project_name} already exists, aborting. Maybe move it out of the way before continuing."
|
78
|
+
unless !@valid_name
|
79
|
+
$stdout.puts "\e[1;31mError:\e[0m The directory #{@project_name} already exists, aborting. Maybe move it out of the way before continuing."
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
@@ -90,18 +88,18 @@ Creates the application base directories.
|
|
90
88
|
=end
|
91
89
|
def create_base_dirs
|
92
90
|
BASE_DIR.each do |dir|
|
93
|
-
FileUtils.mkdir "#{project_name}/#{dir}"
|
91
|
+
FileUtils.mkdir "#{@project_name}/#{dir}"
|
94
92
|
$stdout.puts "\e[1;32m \tcreate\e[0m\t#{dir}"
|
95
93
|
end
|
96
|
-
FileUtils.mkdir "#{project_name}/app/apis/#{project_name}"
|
97
|
-
$stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{project_name}"
|
94
|
+
FileUtils.mkdir "#{@project_name}/app/apis/#{@project_name}"
|
95
|
+
$stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{@project_name}"
|
98
96
|
end
|
99
97
|
|
100
98
|
=begin
|
101
99
|
Function to setup the API modules.
|
102
100
|
=end
|
103
101
|
def setup_api_module
|
104
|
-
|
102
|
+
@module_name = @project_name.split('_').map(&:capitalize).join('')
|
105
103
|
create_api_module
|
106
104
|
config_server
|
107
105
|
end
|
@@ -110,26 +108,26 @@ Function to setup the API modules.
|
|
110
108
|
Function to create the API modules.
|
111
109
|
=end
|
112
110
|
def create_api_module
|
113
|
-
File.open("#{project_name}/app/apis/#{project_name}/base.rb", "w") do |f|
|
111
|
+
File.open("#{@project_name}/app/apis/#{@project_name}/base.rb", "w") do |f|
|
114
112
|
f.write('module ')
|
115
|
-
f.puts(module_name)
|
113
|
+
f.puts(@module_name)
|
116
114
|
f.write("\tclass Base < Grape::API\n\tend\nend")
|
117
115
|
end
|
118
|
-
$stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{project_name}/base.rb"
|
116
|
+
$stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{@project_name}/base.rb"
|
119
117
|
end
|
120
118
|
|
121
119
|
=begin
|
122
120
|
Function to configure the Goliath server.
|
123
121
|
=end
|
124
122
|
def config_server
|
125
|
-
file = File.open("#{project_name}/server.rb", "r+")
|
123
|
+
file = File.open("#{@project_name}/server.rb", "r+")
|
126
124
|
file.each do |line|
|
127
125
|
while line == " def response(env)\n" do
|
128
126
|
pos = file.pos
|
129
127
|
rest = file.read
|
130
128
|
file.seek pos
|
131
129
|
file.write("\t::")
|
132
|
-
file.write(module_name)
|
130
|
+
file.write(@module_name)
|
133
131
|
file.write("::Base.call(env)\n")
|
134
132
|
file.write(rest)
|
135
133
|
$stdout.puts "\e[1;35m \tconfig\e[0m\tserver.rb"
|
@@ -143,8 +141,8 @@ Function to copy the template files project location.
|
|
143
141
|
=end
|
144
142
|
def copy_files_to_target
|
145
143
|
COMMON_RAMMER_FILES.each do |file|
|
146
|
-
source = File.join("#{gem_path}/lib/modules/common/",file)
|
147
|
-
FileUtils.cp(source,"#{project_name}")
|
144
|
+
source = File.join("#{@gem_path}/lib/modules/common/",file)
|
145
|
+
FileUtils.cp(source,"#{@project_name}")
|
148
146
|
$stdout.puts "\e[1;32m \tcreate\e[0m\t#{file}"
|
149
147
|
end
|
150
148
|
end
|
@@ -153,7 +151,7 @@ Function to copy the template files project location.
|
|
153
151
|
Creates api modules, required files and configures the server with respect to new application.
|
154
152
|
=end
|
155
153
|
def copy_files_to_dir(file,destination)
|
156
|
-
FileUtils.cp("#{gem_path}/lib/modules/common/#{file}","#{project_name}/#{destination}")
|
154
|
+
FileUtils.cp("#{@gem_path}/lib/modules/common/#{file}","#{@project_name}/#{destination}")
|
157
155
|
$stdout.puts "\e[1;32m \tcreate\e[0m\t#{destination}/#{file}"
|
158
156
|
end
|
159
157
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
=begin
|
2
|
+
**************************************************************************
|
3
|
+
* The MIT License (MIT)
|
4
|
+
|
5
|
+
* Copyright (c) 2013-2014 QBurst Technologies Inc.
|
6
|
+
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
|
25
|
+
**************************************************************************
|
26
|
+
=end
|
27
|
+
|
28
|
+
RESERVED_WORDS = [ 'rammer',
|
29
|
+
'viber',
|
30
|
+
'test',
|
31
|
+
'lib',
|
32
|
+
'template',
|
33
|
+
'authorization',
|
34
|
+
'authentication',
|
35
|
+
'app',
|
36
|
+
'apis',
|
37
|
+
'models',
|
38
|
+
'migrate',
|
39
|
+
'oauth',
|
40
|
+
'oauth2',
|
41
|
+
'scaffold'
|
42
|
+
]
|
43
|
+
AUTH_MIGRATE = [ '01_create_users.rb',
|
44
|
+
'02_create_sessions.rb'
|
45
|
+
]
|
46
|
+
OAUTH_MIGRATE = [ '03_create_owners.rb',
|
47
|
+
'04_create_oauth2_authorizations.rb',
|
48
|
+
'05_create_oauth2_clients.rb'
|
49
|
+
]
|
50
|
+
AUTH_MODELS = [ 'user.rb',
|
51
|
+
'session.rb',
|
52
|
+
'oauth2_authorization.rb'
|
53
|
+
]
|
54
|
+
OAUTH_MODELS = [ 'oauth2_client.rb',
|
55
|
+
'owner.rb'
|
56
|
+
]
|
57
|
+
BASE_DIR = [ 'app',
|
58
|
+
'app/apis',
|
59
|
+
'config',
|
60
|
+
'db',
|
61
|
+
'db/migrate',
|
62
|
+
'app/models'
|
63
|
+
]
|
64
|
+
COMMON_RAMMER_FILES = [ 'Gemfile',
|
65
|
+
'Gemfile.lock',
|
66
|
+
'Procfile',
|
67
|
+
'Rakefile',
|
68
|
+
'server.rb',
|
69
|
+
'tree.rb'
|
70
|
+
]
|
@@ -0,0 +1,227 @@
|
|
1
|
+
=begin
|
2
|
+
**************************************************************************
|
3
|
+
* The MIT License (MIT)
|
4
|
+
|
5
|
+
* Copyright (c) 2013-2014 QBurst Technologies Inc.
|
6
|
+
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
|
25
|
+
**************************************************************************
|
26
|
+
=end
|
27
|
+
|
28
|
+
require "rammer/version"
|
29
|
+
require 'fileutils'
|
30
|
+
require_relative 'reserved_words'
|
31
|
+
|
32
|
+
$gem_file_name = "rammer-"+Rammer::VERSION
|
33
|
+
|
34
|
+
module Rammer
|
35
|
+
|
36
|
+
=begin
|
37
|
+
Generator class for scaffolding
|
38
|
+
=end
|
39
|
+
class ScaffoldGenerator
|
40
|
+
attr_accessor :scaffold_name, :project_name, :gem_path, :model_class, :attributes, :data_types,
|
41
|
+
:arguments, :project_class, :valid
|
42
|
+
|
43
|
+
=begin
|
44
|
+
Initiliazes the basic attributes required for scaffolding.
|
45
|
+
=end
|
46
|
+
def initialize(options)
|
47
|
+
@scaffold_name = to_underscore(options[:scaffold_name])
|
48
|
+
@model_class = @scaffold_name.split('_').map(&:capitalize).join('')
|
49
|
+
@project_name = options[:project_name]
|
50
|
+
@project_class = @project_name.split('_').map(&:capitalize).join('')
|
51
|
+
@arguments = options[:arguments]
|
52
|
+
@attributes, @data_types = [],[]
|
53
|
+
path = `gem which rammer`
|
54
|
+
@gem_path = path.split($gem_file_name,2).first + $gem_file_name
|
55
|
+
@valid = false
|
56
|
+
end
|
57
|
+
|
58
|
+
=begin
|
59
|
+
Initiates scaffolding functionality by creating model, migration and api files.
|
60
|
+
=end
|
61
|
+
def run
|
62
|
+
create_model_file
|
63
|
+
create_migration if @valid==true
|
64
|
+
enable_apis if @valid==true
|
65
|
+
end
|
66
|
+
|
67
|
+
=begin
|
68
|
+
Generates the model file with CRED functionality.
|
69
|
+
=end
|
70
|
+
def create_model_file
|
71
|
+
dir = "/app/models/#{@scaffold_name}.rb"
|
72
|
+
unless File.exists?(File.join(Dir.pwd,dir))
|
73
|
+
File.join(Dir.pwd,dir)
|
74
|
+
source = "#{@gem_path}/lib/modules/scaffold/model.rb"
|
75
|
+
FileUtils.cp(source,File.join(Dir.pwd,dir))
|
76
|
+
config_model
|
77
|
+
@valid = true
|
78
|
+
$stdout.puts "\e[1;32m \tcreate\e[0m\t#{dir}"
|
79
|
+
else
|
80
|
+
$stdout.puts "\e[1;31mError:\e[0m Model named #{@scaffold_name} already exists, aborting."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
=begin
|
85
|
+
Configures the model file in accordance to user input.
|
86
|
+
=end
|
87
|
+
def config_model
|
88
|
+
source = "#{Dir.pwd}/app/models/#{@scaffold_name}.rb"
|
89
|
+
modify_content(source, 'Model', "#{model_class}")
|
90
|
+
modify_content(source, '@model', "@#{@scaffold_name}")
|
91
|
+
end
|
92
|
+
|
93
|
+
=begin
|
94
|
+
Generates migration files for the scaffold.
|
95
|
+
=end
|
96
|
+
def create_migration
|
97
|
+
migration_version = Time.now.to_i
|
98
|
+
dir = "/db/migrate/#{migration_version}_create_#{@scaffold_name}s.rb"
|
99
|
+
unless File.exists?(File.join(Dir.pwd,dir))
|
100
|
+
source = "#{@gem_path}/lib/modules/scaffold/migration.rb"
|
101
|
+
FileUtils.cp(source,File.join(Dir.pwd,dir))
|
102
|
+
config_migration(migration_version)
|
103
|
+
$stdout.puts "\e[1;32m \tcreate\e[0m\t#{dir}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
=begin
|
108
|
+
Configures the migration file with the required user input.
|
109
|
+
=end
|
110
|
+
def config_migration(migration_version)
|
111
|
+
source = "#{Dir.pwd}/db/migrate/#{migration_version}_create_#{@scaffold_name}s.rb"
|
112
|
+
modify_content(source, 'CreateMigration', "Create#{@model_class}s")
|
113
|
+
modify_content(source, 'migration', "#{@scaffold_name}s")
|
114
|
+
|
115
|
+
@arguments.each do |value|
|
116
|
+
@attributes << value.split(':').first
|
117
|
+
@data_types << value.split(':').last
|
118
|
+
end
|
119
|
+
|
120
|
+
attribute_data_types = @data_types.reverse
|
121
|
+
@attributes.reverse.each_with_index do |value,index|
|
122
|
+
add_attributes(source, value, attribute_data_types[index])
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
=begin
|
127
|
+
Edits the migration file with the user specified model attributes.
|
128
|
+
=end
|
129
|
+
def add_attributes(source,attribute,data_type)
|
130
|
+
file = File.open(source, "r+")
|
131
|
+
file.each do |line|
|
132
|
+
while line == " create_table :#{@scaffold_name}s do |t|\n" do
|
133
|
+
pos = file.pos
|
134
|
+
rest = file.read
|
135
|
+
file.seek pos
|
136
|
+
file.write(" t.#{data_type} :#{attribute}\n")
|
137
|
+
file.write(rest)
|
138
|
+
break
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
=begin
|
144
|
+
Generates the api file with CRED functionality apis enabled.
|
145
|
+
=end
|
146
|
+
def enable_apis
|
147
|
+
dir = "/app/apis/#{@project_name}/#{@scaffold_name}s/base_apis.rb"
|
148
|
+
base_dir = "#{Dir.pwd}/app/apis/#{@project_name}/#{@scaffold_name}s"
|
149
|
+
unless File.exists?(File.join(Dir.pwd,dir))
|
150
|
+
FileUtils.mkdir base_dir unless File.exists?(base_dir)
|
151
|
+
source = "#{@gem_path}/lib/modules/scaffold/base_apis.rb"
|
152
|
+
FileUtils.cp(source,File.join(Dir.pwd,dir))
|
153
|
+
config_apis
|
154
|
+
$stdout.puts "\e[1;32m \tcreate\e[0m\t#{dir}"
|
155
|
+
mount_apis
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
=begin
|
160
|
+
Configures the api file with respect to the user input.
|
161
|
+
=end
|
162
|
+
def config_apis
|
163
|
+
source = "#{Dir.pwd}/app/apis/#{@project_name}/#{@scaffold_name}s/base_apis.rb"
|
164
|
+
content = ['AppName','ScaffoldName', 'Model', 'model']
|
165
|
+
replacement = ["#{@project_class}", "#{model_class}s", "#{model_class}", "#{@scaffold_name}"]
|
166
|
+
for i in 0..3 do
|
167
|
+
modify_content(source, content[i], replacement[i])
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
=begin
|
172
|
+
Mounts the scaffold apis onto the application.
|
173
|
+
=end
|
174
|
+
def mount_apis
|
175
|
+
require_apis_to_base
|
176
|
+
mount_class = "::#{@project_class}::#{@model_class}s::BaseApis"
|
177
|
+
file = File.open("#{Dir.pwd}/app/apis/#{@project_name}/base.rb", "r+")
|
178
|
+
file.each do |line|
|
179
|
+
while line == "\tclass Base < Grape::API\n" do
|
180
|
+
pos = file.pos
|
181
|
+
rest = file.read
|
182
|
+
file.seek pos
|
183
|
+
file.write("\t\tmount ")
|
184
|
+
file.puts(mount_class)
|
185
|
+
file.write(rest)
|
186
|
+
break
|
187
|
+
end
|
188
|
+
end
|
189
|
+
$stdout.puts "\e[1;35m\tmounted\e[0m\t#{mount_class}"
|
190
|
+
end
|
191
|
+
|
192
|
+
=begin
|
193
|
+
Configures for mounting the scaffold apis.
|
194
|
+
=end
|
195
|
+
def require_apis_to_base
|
196
|
+
File.open("#{Dir.pwd}/app/apis/#{@project_name}/base.rb", "r+") do |f|
|
197
|
+
pos = f.pos
|
198
|
+
rest = f.read
|
199
|
+
f.seek pos
|
200
|
+
f.write("require_relative '#{@scaffold_name}s/base_apis'\n")
|
201
|
+
f.write(rest)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
=begin
|
208
|
+
Converts the string into snake case format.
|
209
|
+
=end
|
210
|
+
def to_underscore(value)
|
211
|
+
underscore_value = value.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
212
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
|
213
|
+
return underscore_value
|
214
|
+
end
|
215
|
+
|
216
|
+
=begin
|
217
|
+
Modifies the content(specified) of a file(specified) with another value(specified).
|
218
|
+
=end
|
219
|
+
def modify_content(source, content, replace_value)
|
220
|
+
file = File.read(source)
|
221
|
+
replace = file.gsub(/#{content}/, replace_value)
|
222
|
+
File.open(source, "w"){|f|
|
223
|
+
f.puts replace
|
224
|
+
}
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
data/lib/rammer/version.rb
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
**************************************************************************
|
26
26
|
=end
|
27
27
|
|
28
|
-
require_relative '
|
28
|
+
require_relative '../helper'
|
29
29
|
|
30
30
|
$test_file = "dummy"
|
31
31
|
$test_file_root = "#{Dir.pwd}/test"
|
@@ -39,8 +39,7 @@ class TestRammerRootStructure < Test::Unit::TestCase
|
|
39
39
|
def test_generator_directory_name
|
40
40
|
Dir.chdir("#{$test_file_root}")
|
41
41
|
dir_path = Dir.pwd
|
42
|
-
|
43
|
-
generator.run
|
42
|
+
$stdout.puts `rammer `
|
44
43
|
assert_equal(false, File.directory?("#{dir_path}/ "))
|
45
44
|
end
|
46
45
|
|
@@ -62,13 +61,15 @@ class TestRammerRootStructure < Test::Unit::TestCase
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def test_generator_root_directory_exisiting
|
64
|
+
Dir.chdir("#{$test_file_root}")
|
65
65
|
dir_path = Dir.pwd
|
66
66
|
generator = Rammer::RammerGenerator.new("#{$test_file}")
|
67
67
|
generator.run
|
68
68
|
assert_equal(true, File.directory?("#{dir_path}/#{$test_file}"))
|
69
69
|
end
|
70
70
|
|
71
|
-
def test_generator_root_folder_structure
|
71
|
+
def test_generator_root_folder_structure
|
72
|
+
Dir.chdir("#{$test_file_root}")
|
72
73
|
dir_path = Dir.pwd
|
73
74
|
DIR.each do |dir|
|
74
75
|
assert_equal(true, File.directory?("#{dir_path}/#{$test_file}/#{dir}"))
|
@@ -0,0 +1,59 @@
|
|
1
|
+
=begin
|
2
|
+
**************************************************************************
|
3
|
+
* The MIT License (MIT)
|
4
|
+
|
5
|
+
* Copyright (c) 2013-2014 QBurst Technologies Inc.
|
6
|
+
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
|
25
|
+
**************************************************************************
|
26
|
+
=end
|
27
|
+
|
28
|
+
require_relative '../helper'
|
29
|
+
|
30
|
+
$test_file = "dummy"
|
31
|
+
$test_file_root = "#{Dir.pwd}/test"
|
32
|
+
$scaffold_name = "test"
|
33
|
+
|
34
|
+
SCAFFOLD_FILES = ["app/models/#{$scaffold_name}.rb","app/apis/#{$test_file}/#{$scaffold_name}s/base_apis.rb"]
|
35
|
+
|
36
|
+
class TestScaffoldGenerator < Test::Unit::TestCase
|
37
|
+
def test_generator_scaffold_folder
|
38
|
+
Dir.chdir("#{$test_file_root}/#{$test_file}")
|
39
|
+
options = { :project_name => $test_file, :scaffold_name => $scaffold_name, :arguments => ['name:string']}
|
40
|
+
scaffold_generator = Rammer::ScaffoldGenerator.new(options)
|
41
|
+
scaffold_generator.run
|
42
|
+
dir_path = Dir.pwd
|
43
|
+
SCAFFOLD_FILES.each do |file|
|
44
|
+
assert_equal(true, File.file?("#{dir_path}/#{file}"))
|
45
|
+
end
|
46
|
+
Dir.entries('db/migrate/.').each do |file|
|
47
|
+
assert true if file.include?('create_#{scaffold_name}s')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_generator_scaffold_folder_duplicate
|
52
|
+
Dir.chdir("#{$test_file_root}/#{$test_file}")
|
53
|
+
options = { :project_name => $test_file, :scaffold_name => $scaffold_name, :arguments => ['name:string']}
|
54
|
+
scaffold_generator = Rammer::ScaffoldGenerator.new(options)
|
55
|
+
scaffold_generator.run
|
56
|
+
expected_valid_attr = false
|
57
|
+
assert_equal(expected_valid_attr, scaffold_generator.valid)
|
58
|
+
end
|
59
|
+
end
|
@@ -25,7 +25,7 @@
|
|
25
25
|
**************************************************************************
|
26
26
|
=end
|
27
27
|
|
28
|
-
require_relative '
|
28
|
+
require_relative '../helper'
|
29
29
|
|
30
30
|
$test_file = "dummy"
|
31
31
|
$test_file_root = "#{Dir.pwd}/test"
|
@@ -42,7 +42,6 @@ class TestViberModulePlugin < Test::Unit::TestCase
|
|
42
42
|
MODULE_CLASS = $test_file.split('_').map(&:capitalize)*''
|
43
43
|
|
44
44
|
def test_generator_root_module_mount_authenticate
|
45
|
-
Dir.chdir("#{Dir.pwd}/#{$test_file}")
|
46
45
|
dir_path = Dir.pwd
|
47
46
|
module_class = "::#{MODULE_CLASS}::AuthenticationApis"
|
48
47
|
options = { :project_name => "#{$test_file}", :module_class => module_class,
|
@@ -25,12 +25,12 @@
|
|
25
25
|
**************************************************************************
|
26
26
|
=end
|
27
27
|
|
28
|
-
require_relative '
|
28
|
+
require_relative '../helper'
|
29
29
|
|
30
30
|
$test_file = "dummy"
|
31
31
|
$test_file_root = "#{Dir.pwd}/test"
|
32
32
|
|
33
|
-
class
|
33
|
+
class TestViberModuleUnplug < Test::Unit::TestCase
|
34
34
|
|
35
35
|
AUTHENTICATE_MODULE_FILES = ["app/apis/#{$test_file}/modules/authentication_apis.rb"]
|
36
36
|
AUTHORIZE_MODULE_FILES = ["app/apis/#{$test_file}/modules/authorization_apis.rb"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rammer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- lib/rammer/version.rb
|
98
98
|
- lib/rammer/rammer_generator.rb
|
99
99
|
- lib/rammer/module_generator.rb
|
100
|
+
- lib/rammer/scaffold_generator.rb
|
101
|
+
- lib/rammer/reserved_words.rb
|
100
102
|
- lib/modules/migrations/01_create_users.rb
|
101
103
|
- lib/modules/migrations/02_create_sessions.rb
|
102
104
|
- lib/modules/migrations/03_create_owners.rb
|
@@ -118,10 +120,14 @@ files:
|
|
118
120
|
- lib/modules/models/session.rb
|
119
121
|
- lib/modules/common/tree.rb
|
120
122
|
- lib/modules/models/user.rb
|
123
|
+
- lib/modules/scaffold/model.rb
|
124
|
+
- lib/modules/scaffold/migration.rb
|
125
|
+
- lib/modules/scaffold/base_apis.rb
|
121
126
|
- test/helper.rb
|
122
|
-
- test/test_rammer_root_structure.rb
|
123
|
-
- test/
|
124
|
-
- test/
|
127
|
+
- test/hierarchy/test_rammer_root_structure.rb
|
128
|
+
- test/scaffold/test_scaffold_generator.rb
|
129
|
+
- test/viber/test_viber_module_plugin.rb
|
130
|
+
- test/viber/test_viber_module_unplug.rb
|
125
131
|
- bin/rammer
|
126
132
|
- bin/viber
|
127
133
|
homepage: http://github.com/qburstruby/rammer
|
@@ -137,18 +143,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
143
|
- - ! '>='
|
138
144
|
- !ruby/object:Gem::Version
|
139
145
|
version: '0'
|
140
|
-
segments:
|
141
|
-
- 0
|
142
|
-
hash: 2624680165410903349
|
143
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
147
|
none: false
|
145
148
|
requirements:
|
146
149
|
- - ! '>='
|
147
150
|
- !ruby/object:Gem::Version
|
148
151
|
version: '0'
|
149
|
-
segments:
|
150
|
-
- 0
|
151
|
-
hash: 2624680165410903349
|
152
152
|
requirements: []
|
153
153
|
rubyforge_project:
|
154
154
|
rubygems_version: 1.8.25
|
@@ -158,6 +158,8 @@ summary: Rammer is a framework dedicated to build high performance Async API ser
|
|
158
158
|
on top of non-blocking (asynchronous) Ruby web server called Goliath.
|
159
159
|
test_files:
|
160
160
|
- test/helper.rb
|
161
|
-
- test/test_rammer_root_structure.rb
|
162
|
-
- test/
|
163
|
-
- test/
|
161
|
+
- test/hierarchy/test_rammer_root_structure.rb
|
162
|
+
- test/scaffold/test_scaffold_generator.rb
|
163
|
+
- test/viber/test_viber_module_plugin.rb
|
164
|
+
- test/viber/test_viber_module_unplug.rb
|
165
|
+
has_rdoc:
|