nephos-server 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nephos-generator +39 -14
  3. data/version +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 597ef096f14958c9c1139eb49d340783a4903bba
4
- data.tar.gz: 91f587c2e6a54091835bfa374f031a4f19a3baef
3
+ metadata.gz: e144905879152af79fc251c1b0b2d3a178dfa066
4
+ data.tar.gz: d31444aa6d75c9dec7fe795bef0204067e257d86
5
5
  SHA512:
6
- metadata.gz: 4e0e0860affde008dfdd112563fb7d5eb0e8eb2420c92f891503e3d64345d3d3cffaf96e4065b1e8a742fdea7057b07d57e5d88e4b2c6e3351eca897552bbf0c
7
- data.tar.gz: 05396e4d53d8c8d0ce6c17c939246db518162344641af4a60da66755317b322be243fa7f7e9606e727486e01b95834ae9eeed472635a38233530b31b41380da9
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
- raise "You are not in a valid application directory" if not Nephos::Bin.is_a_valid_application?
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
- File.open("routes.rb", "a") do |f|
28
- f.puts line
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
- raise "You are not in a valid application directory" if not Nephos::Bin.is_a_valid_application?
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 ARGV[0]
105
+ case opt[0]
81
106
  when "c", "controller"
82
- if ARGV[1].to_s.match(/[\w\-\.]+/)
83
- generate_controller("#{ARGV[1].capitalize}Controller", "app/#{ARGV[1].downcase}.rb")
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 ARGV[1].to_s.empty?
89
- create_application_dir(ARGV[1])
90
- puts "Application #{ARGV[1]} created"
91
- move_to_application_dir(ARGV[1])
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(*(ARGV[1..4]))
121
+ generate_route(*(opt[1..4]))
97
122
  else
98
- puts "\"#{ARGV[0]}\" not recognized has a command"
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.0
1
+ 0.4.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nephos-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a