nephos-server 0.4.0 → 0.4.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 +4 -4
- data/bin/nephos-generator +39 -14
- data/version +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e144905879152af79fc251c1b0b2d3a178dfa066
|
4
|
+
data.tar.gz: d31444aa6d75c9dec7fe795bef0204067e257d86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a38d64cd6e7258a5dd2a136bf1024e5521cca2a68ab12c0450737c415fca756f26adf8f2cd905465f4544c5adbb7a3a46cb395e0b1dc70061636c345fb101b
|
7
|
+
data.tar.gz: 1b061583e821e28d60521770a119b0a0e8cbb4a42fa304fd3d11f362a530b5ecd413db9ad0ae5f1d1d6c16758bbc60379e82c1239c33a4ef321c64696e91266b
|
data/bin/nephos-generator
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'colorize'
|
3
4
|
require 'optparse'
|
4
5
|
require 'nephos-server/bin-helpers'
|
5
6
|
|
@@ -15,8 +16,25 @@ ROUTE_RB = <<EOF
|
|
15
16
|
#get url: "/rm", controller: "MainController", method: "rm_url"
|
16
17
|
EOF
|
17
18
|
|
19
|
+
def raise_invalid_appli
|
20
|
+
if not Nephos::Bin.is_a_valid_application? and not $debug
|
21
|
+
raise "You are not in a valid application directory"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def route_exists? line
|
26
|
+
File.read("routes.rb").split("\n").include? line
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_route! line
|
30
|
+
File.open("routes.rb", "a") do |f|
|
31
|
+
f.puts line
|
32
|
+
end
|
33
|
+
puts("Route created: ".green + line)
|
34
|
+
end
|
35
|
+
|
18
36
|
def generate_route(verb, url, dest_c, dest_m=nil)
|
19
|
-
|
37
|
+
raise_invalid_appli
|
20
38
|
raise InvalidVerb, "\"#{verb}\" doesn't match with /\w+/" if not verb.to_s.match(/^\w+$/)
|
21
39
|
raise InvalidUrl if not url.match(/^\/?(:?\w+)(\/:?\w+)*\/?$/)
|
22
40
|
raise "Option dest_m is not avaiable for now" if not dest_m.nil?
|
@@ -24,13 +42,15 @@ def generate_route(verb, url, dest_c, dest_m=nil)
|
|
24
42
|
controller = dest_c.split("#")[0]
|
25
43
|
method = dest_c.split("#")[1]
|
26
44
|
line = "add_route \"#{verb}\", url: \"#{url}\", controller: \"#{controller}\", method: \"#{method}\""
|
27
|
-
|
28
|
-
|
45
|
+
if route_exists? line
|
46
|
+
puts("Route already exists: ".yellow + line)
|
47
|
+
else
|
48
|
+
write_route!(line)
|
29
49
|
end
|
30
50
|
end
|
31
51
|
|
32
52
|
def generate_controller(name, file)
|
33
|
-
|
53
|
+
raise_invalid_appli
|
34
54
|
if File.exists? file
|
35
55
|
print "The file #{file} already exists. Are you sure to erase it ? (y/N)"
|
36
56
|
r = STDIN.gets.to_s.chomp
|
@@ -73,29 +93,34 @@ def initialize_application
|
|
73
93
|
end
|
74
94
|
|
75
95
|
begin
|
76
|
-
OptionParser.new do |opts|
|
96
|
+
opt = OptionParser.new do |opts|
|
77
97
|
opts.banner = "Usage: nephos-generator [controller name] [appli [name]]"
|
98
|
+
|
99
|
+
opts.on("--debug") do
|
100
|
+
$debug = true
|
101
|
+
end
|
102
|
+
|
78
103
|
end.parse!
|
79
104
|
|
80
|
-
case
|
105
|
+
case opt[0]
|
81
106
|
when "c", "controller"
|
82
|
-
if
|
83
|
-
generate_controller("#{
|
107
|
+
if opt[1].to_s.match(/[\w\-\.]+/)
|
108
|
+
generate_controller("#{opt[1].capitalize}Controller", "app/#{opt[1].downcase}.rb")
|
84
109
|
else
|
85
110
|
puts "error"
|
86
111
|
end
|
87
112
|
when "a", "appli", "application"
|
88
|
-
if not
|
89
|
-
create_application_dir(
|
90
|
-
puts "Application #{
|
91
|
-
move_to_application_dir(
|
113
|
+
if not opt[1].to_s.empty?
|
114
|
+
create_application_dir(opt[1])
|
115
|
+
puts "Application #{opt[1]} created"
|
116
|
+
move_to_application_dir(opt[1])
|
92
117
|
end
|
93
118
|
initialize_application
|
94
119
|
puts "Application initialized"
|
95
120
|
when "r", "route"
|
96
|
-
generate_route(*(
|
121
|
+
generate_route(*(opt[1..4]))
|
97
122
|
else
|
98
|
-
puts "\"#{
|
123
|
+
puts "\"#{opt[0]}\" not recognized has a command"
|
99
124
|
end
|
100
125
|
|
101
126
|
rescue => err
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|