nephos-server 0.4.1 → 0.4.2
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 +113 -79
- data/bin/nephos-server +1 -0
- data/bin/nephos-status +16 -2
- data/lib/nephos-server.rb +5 -0
- data/nephos-server.gemspec +1 -0
- data/test/generator.rb +47 -0
- data/version +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fdc970288b999aeab76422947f72cfbfcba0710
|
4
|
+
data.tar.gz: 38042ea637910e98ca204e6119d457b51417c3a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e95c52c9519e04511f62db2d89197923ebf5bc485bad8997c0facf3142cf423953b010e997345df57ff1db1ff03e73f275fc747ef36a2fd1e2057b4ba48dc858
|
7
|
+
data.tar.gz: a8e1e84c5d8f58b0598b5987759ea1e545258977f96a0745f81fdbf1394f23055daa2485cf29501cd7c41ead58f2e19cf62ad0b8fb9df491121984013361ee1c
|
data/bin/nephos-generator
CHANGED
@@ -22,107 +22,141 @@ def raise_invalid_appli
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
25
|
+
module Nephos
|
26
|
+
module Generator
|
27
|
+
|
28
|
+
module Route
|
29
|
+
def self.exists? line
|
30
|
+
File.read("routes.rb").split("\n").include? line
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.write! line
|
34
|
+
File.open("routes.rb", "a") do |f|
|
35
|
+
f.puts line
|
36
|
+
end
|
37
|
+
puts("Route created: ".green + line)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.generate!(verb, url, dest_c, dest_m=nil)
|
41
|
+
raise_invalid_appli
|
42
|
+
raise InvalidVerb, "\"#{verb}\" doesn't match with /\w+/" if not verb.to_s.match(/^\w+$/)
|
43
|
+
raise InvalidUrl if not url.match(/^\/?(:?\w+)(\/:?\w+)*\/?$/)
|
44
|
+
raise "Option dest_c must match with \"controller#method\"" if not dest_c.match(/^\w+\#\w+$/) and dest_m.nil?
|
45
|
+
raise "Option dest_c must match with \"controllerName\"" if not dest_m.nil? and not dest_c.match(/^\w+$/)
|
46
|
+
raise "Option dest_m must match with \"methodName\"" if not dest_m.nil? and not dest_c.match(/^\w+$/)
|
47
|
+
controller, method = dest_c, dest_m
|
48
|
+
if dest_m.nil?
|
49
|
+
controller = dest_c.split("#")[0]
|
50
|
+
method = dest_c.split("#")[1]
|
51
|
+
end
|
52
|
+
line = "add_route \"#{verb}\", url: \"#{url}\", controller: \"#{controller}\", method: \"#{method}\""
|
53
|
+
if exists? line
|
54
|
+
if $remove
|
55
|
+
routes = File.read("routes.rb").split("\n")
|
56
|
+
puts "Route deleted: ".green + routes.delete(line).to_s
|
57
|
+
File.write("routes.rb", routes.join("\n") + "\n")
|
58
|
+
else
|
59
|
+
puts("Route already exists: ".yellow + line)
|
60
|
+
end
|
61
|
+
else
|
62
|
+
if $remove
|
63
|
+
puts("Route doesn't exists: ".yellow + line)
|
64
|
+
else
|
65
|
+
write!(line)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
51
70
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
71
|
+
module Controller
|
72
|
+
def self.generate!(name, file)
|
73
|
+
raise_invalid_appli
|
74
|
+
if File.exists? file
|
75
|
+
print "The file #{file} already exists. Are you sure to erase it ? (y/N)"
|
76
|
+
r = STDIN.gets.to_s.chomp
|
77
|
+
raise "File #{file} already exists" unless r.match(/y(es)?/)
|
78
|
+
end
|
79
|
+
f = File.open(file, 'w')
|
80
|
+
f << <<EOF
|
61
81
|
class #{name} < Nephos::Controller
|
62
82
|
def root
|
63
83
|
return {plain: "index"}
|
64
84
|
end
|
65
85
|
end
|
66
86
|
EOF
|
67
|
-
|
68
|
-
end
|
87
|
+
puts "Controller \"#{name}\" created at location \"#{file}\""
|
88
|
+
end
|
89
|
+
end
|
69
90
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
91
|
+
module Application
|
92
|
+
def self.create_application_dir dir
|
93
|
+
raise "Directory #{dir} already exists" if Dir.exists? dir
|
94
|
+
Dir.mkdir dir
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.move_to_application_dir dir
|
98
|
+
Dir.chdir dir
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.initialize!
|
102
|
+
raise "Not an empty dir" unless Dir[File.expand_path "*"].empty?
|
103
|
+
File.write "routes.rb", ROUTE_RB
|
104
|
+
File.write "Gemfile", GEMFILE
|
105
|
+
Dir.mkdir "app"
|
106
|
+
begin
|
107
|
+
`git init .`
|
108
|
+
puts "Git repository initialized"
|
109
|
+
rescue Errno::ENOENT => err
|
110
|
+
puts "Warning: git repository not initialized"
|
111
|
+
rescue => err
|
112
|
+
puts "Error: #{err.message}"
|
113
|
+
end
|
114
|
+
exec("bundle install")
|
115
|
+
end
|
116
|
+
end
|
74
117
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
118
|
+
def self.main opt
|
119
|
+
case opt[0]
|
120
|
+
when "c", "controller"
|
121
|
+
if opt[1].to_s.match(/[\w\-\.]+/)
|
122
|
+
Controller.generate!("#{opt[1].capitalize}Controller", "app/#{opt[1].downcase}.rb")
|
123
|
+
else
|
124
|
+
puts "error"
|
125
|
+
end
|
126
|
+
when "a", "appli", "application"
|
127
|
+
if not opt[1].to_s.empty?
|
128
|
+
Application.create_application_dir(opt[1])
|
129
|
+
puts "Application #{opt[1]} created"
|
130
|
+
Application.move_to_application_dir(opt[1])
|
131
|
+
end
|
132
|
+
Application.initialize!
|
133
|
+
puts "Application initialized"
|
134
|
+
when "r", "route"
|
135
|
+
Route.generate!(*(opt[1..4]))
|
136
|
+
else
|
137
|
+
puts "\"#{opt[0]}\" not recognized has a command"
|
138
|
+
end
|
139
|
+
end
|
78
140
|
|
79
|
-
def initialize_application
|
80
|
-
raise "Not an empty dir" unless Dir[File.expand_path "*"].empty?
|
81
|
-
File.write "routes.rb", ROUTE_RB
|
82
|
-
File.write "Gemfile", GEMFILE
|
83
|
-
Dir.mkdir "app"
|
84
|
-
begin
|
85
|
-
`git init .`
|
86
|
-
puts "Git repository initialized"
|
87
|
-
rescue Errno::ENOENT => err
|
88
|
-
puts "Warning: git repository not initialized"
|
89
|
-
rescue => err
|
90
|
-
puts "Error: #{err.message}"
|
91
141
|
end
|
92
|
-
exec("bundle install")
|
93
142
|
end
|
94
143
|
|
95
144
|
begin
|
96
145
|
opt = OptionParser.new do |opts|
|
97
146
|
opts.banner = "Usage: nephos-generator [controller name] [appli [name]]"
|
98
147
|
|
148
|
+
opts.on("--rm") do
|
149
|
+
$remove = true
|
150
|
+
end
|
151
|
+
|
99
152
|
opts.on("--debug") do
|
100
153
|
$debug = true
|
101
154
|
end
|
102
|
-
|
103
155
|
end.parse!
|
104
156
|
|
105
|
-
|
106
|
-
when "c", "controller"
|
107
|
-
if opt[1].to_s.match(/[\w\-\.]+/)
|
108
|
-
generate_controller("#{opt[1].capitalize}Controller", "app/#{opt[1].downcase}.rb")
|
109
|
-
else
|
110
|
-
puts "error"
|
111
|
-
end
|
112
|
-
when "a", "appli", "application"
|
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])
|
117
|
-
end
|
118
|
-
initialize_application
|
119
|
-
puts "Application initialized"
|
120
|
-
when "r", "route"
|
121
|
-
generate_route(*(opt[1..4]))
|
122
|
-
else
|
123
|
-
puts "\"#{opt[0]}\" not recognized has a command"
|
124
|
-
end
|
157
|
+
Nephos::Generator.main(opt)
|
125
158
|
|
126
159
|
rescue => err
|
127
|
-
puts "Error: #{err.message}"
|
160
|
+
puts "Error:".red + " #{err.message}"
|
161
|
+
puts err.backtrace
|
128
162
|
end
|
data/bin/nephos-server
CHANGED
data/bin/nephos-status
CHANGED
@@ -3,11 +3,20 @@
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'nephos-server/bin-helpers'
|
5
5
|
|
6
|
-
OptionParser.new do |opts|
|
6
|
+
opt = OptionParser.new do |opts|
|
7
7
|
opts.banner = "Usage: nephos-status [appli directory]"
|
8
|
+
|
9
|
+
opts.on("--rm") do
|
10
|
+
$remove = true
|
11
|
+
end
|
12
|
+
|
13
|
+
opts.on("--debug") do
|
14
|
+
$debug = true
|
15
|
+
end
|
16
|
+
|
8
17
|
end.parse!
|
9
18
|
|
10
|
-
$dir =
|
19
|
+
$dir = opt[0] || "."
|
11
20
|
|
12
21
|
begin
|
13
22
|
if Dir.exists? $dir
|
@@ -19,8 +28,13 @@ begin
|
|
19
28
|
i = File.read($gfl).split.index("nephos-server") + 1
|
20
29
|
version = File.read($gfl).split[i]
|
21
30
|
path = $gfl.gsub(/Gemfile\.lock$/, "")
|
31
|
+
n_controllers = 0
|
32
|
+
Dir[File.expand_path 'app/*.rb'].each do |f|
|
33
|
+
n_controllers += 1 if File.read(f).include? "< Nephos::Controller"
|
34
|
+
end
|
22
35
|
puts "Full path: #{path}"
|
23
36
|
puts "Installed nephos-version: #{version}"
|
37
|
+
puts "Controllers (#{n_controllers})"
|
24
38
|
end
|
25
39
|
else
|
26
40
|
raise "\"#{$dir}\" is not a valid directory"
|
data/lib/nephos-server.rb
CHANGED
@@ -13,3 +13,8 @@ require_relative 'nephos-server/controller'
|
|
13
13
|
require_relative 'nephos-server/router/main'
|
14
14
|
# server
|
15
15
|
require_relative 'nephos-server/server/main'
|
16
|
+
|
17
|
+
module Nephos
|
18
|
+
VERSION_FILE = __FILE__.split("/")[0..-3].join("/") + "/version"
|
19
|
+
VERSION = File.read(VERSION_FILE).strip
|
20
|
+
end
|
data/nephos-server.gemspec
CHANGED
data/test/generator.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class TestNephosServerGenerator < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_generator_application
|
4
|
+
# Dir.chdir("/tmp")
|
5
|
+
# name = Time.now.to_i.to_s
|
6
|
+
# `nephos-server a #{name}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_generator_controller
|
10
|
+
`rm -f app/test.rb`
|
11
|
+
|
12
|
+
`nephos-generator --debug c test`
|
13
|
+
assert File.exists? "app/test.rb"
|
14
|
+
assert_equal "class TestController < Nephos::Controller", File.read("app/test.rb").split("\n").first
|
15
|
+
`rm -f app/test.rb`
|
16
|
+
|
17
|
+
`nephos-generator c test --debug`
|
18
|
+
assert File.exists? "app/test.rb"
|
19
|
+
assert_equal "class TestController < Nephos::Controller", File.read("app/test.rb").split("\n").first
|
20
|
+
`rm -f app/test.rb`
|
21
|
+
end
|
22
|
+
|
23
|
+
# test simple and rm
|
24
|
+
def test_generator_route1
|
25
|
+
s1 = File.read("routes.rb")
|
26
|
+
`./bin/nephos-generator --debug r get test ctr#mth`
|
27
|
+
s2 = File.read("routes.rb")
|
28
|
+
`./bin/nephos-generator --debug r get test ctr#mth --rm`
|
29
|
+
s3 = File.read("routes.rb")
|
30
|
+
assert_equal s1, s3
|
31
|
+
assert_not_equal s1, s2
|
32
|
+
end
|
33
|
+
|
34
|
+
# test if ctr#mth == ctr mth
|
35
|
+
def test_generator_route2
|
36
|
+
s1 = File.read("routes.rb")
|
37
|
+
`./bin/nephos-generator --debug r get test ctr#mth`
|
38
|
+
s2 = File.read("routes.rb")
|
39
|
+
`./bin/nephos-generator --debug r get test ctr mth`
|
40
|
+
s3 = File.read("routes.rb")
|
41
|
+
`./bin/nephos-generator --debug r get test ctr mth --rm`
|
42
|
+
s4 = File.read("routes.rb")
|
43
|
+
assert_equal s2, s3
|
44
|
+
assert_equal s1, s4
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nephos-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poulet_a
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nomorebeer
|
@@ -78,6 +78,7 @@ email:
|
|
78
78
|
- test/router.rb
|
79
79
|
- test/params.rb
|
80
80
|
- test/controller.rb
|
81
|
+
- test/generator.rb
|
81
82
|
- routes.rb
|
82
83
|
- app/dataset.rb
|
83
84
|
- app/image.jpg
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- nephos-server.gemspec
|
117
118
|
- routes.rb
|
118
119
|
- test/controller.rb
|
120
|
+
- test/generator.rb
|
119
121
|
- test/params.rb
|
120
122
|
- test/responder.rb
|
121
123
|
- test/router.rb
|