evertils 0.0.8 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/evertils +1 -0
- data/evertils.gemspec +3 -1
- data/lib/controller.rb +5 -0
- data/lib/request.rb +4 -2
- data/lib/router.rb +45 -32
- data/lib/version.rb +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2924b74cb4103d45e575f1de3f182ebe4ca26bfa
|
4
|
+
data.tar.gz: 42623fee026bc656875791940fc8ea2caadf4fc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaedf666d519a48d0e48c2f77769eb34719d214c166ef1ecf3a221b8e27ae81884c492c86c4e0ad50e509039900b1c3976e8f54af55a3b238449d1a85181c477
|
7
|
+
data.tar.gz: 6270782aa6fc8c4662ea21bdca1c1472cd30f9ebecc3d90f206a3a5f5d272af3124cadd02c27c69af1421efc9430d72285aa20b02bec0a80e22c51ba4e4e0fac
|
data/bin/evertils
CHANGED
data/evertils.gemspec
CHANGED
data/lib/controller.rb
CHANGED
data/lib/request.rb
CHANGED
@@ -3,9 +3,11 @@ module Granify
|
|
3
3
|
attr_reader :controller, :command, :custom, :flags, :raw_flags
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@controller =
|
7
|
-
|
6
|
+
@controller = nil
|
7
|
+
@flags = ARGV[0..ARGV.size].select { |f| f.start_with?('-') }.map { |f| f.split("=").map &:to_sym } || []
|
8
|
+
|
8
9
|
if ARGV.size > 1
|
10
|
+
@controller = ARGV[0].to_sym rescue nil
|
9
11
|
@command = ARGV[1].to_sym rescue nil
|
10
12
|
|
11
13
|
if ARGV.size > 2
|
data/lib/router.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
module Granify
|
2
2
|
class Router
|
3
3
|
def route
|
4
|
+
# setup options
|
5
|
+
OptionParser.new do |opt|
|
6
|
+
opt.banner = "#{Granify::PACKAGE_NAME} controller command [...-flags]"
|
7
|
+
|
8
|
+
opt.on("-V", "--version", "Show app version") do |v|
|
9
|
+
# short output
|
10
|
+
@version = Granify::VERSION
|
11
|
+
Notify.spit("#{Granify::PACKAGE_NAME} #{Granify::VERSION}")
|
12
|
+
end
|
13
|
+
end.parse!
|
14
|
+
|
4
15
|
# Populate request params
|
5
16
|
$request = Request.new
|
6
17
|
|
@@ -21,47 +32,49 @@ module Granify
|
|
21
32
|
|
22
33
|
# Create object context and pass it the required command line arguments
|
23
34
|
begin
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
if !$request.controller.nil?
|
36
|
+
controller = Granify::Controller.const_get $request.controller.capitalize rescue false
|
37
|
+
|
38
|
+
if !controller
|
39
|
+
raise "Controller not found: #{$request.controller.capitalize}"
|
40
|
+
end
|
29
41
|
|
30
|
-
|
42
|
+
context = controller.new
|
31
43
|
|
32
|
-
|
33
|
-
|
44
|
+
if context.can_exec? $request.controller, $request.command
|
45
|
+
context.pre_exec
|
34
46
|
|
35
|
-
|
36
|
-
|
47
|
+
# no command sent? Use default to populate model data
|
48
|
+
model_method = ($request.command ? $request.command : context.default_method).to_s + "_data"
|
37
49
|
|
38
|
-
|
39
|
-
|
50
|
+
# populate model data
|
51
|
+
method = context.model.public_method(model_method) rescue false
|
40
52
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
# model is not set, use Base model instead so the controller still has
|
54
|
+
# access to model methods
|
55
|
+
if context.model.nil?
|
56
|
+
context.model = Model::Base.new
|
57
|
+
end
|
58
|
+
|
59
|
+
# If the method exists, set model data accordingly
|
60
|
+
# If it doesn't exist then just fail silently, the model may not
|
61
|
+
# be required by some controllers
|
62
|
+
if method.respond_to? :call
|
63
|
+
context.model.data = method.call($request.custom || [])
|
64
|
+
end
|
53
65
|
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
if context.methods_require_internet.include? $request.command
|
67
|
+
if !Utils.has_internet_connection?
|
68
|
+
raise RuntimeError, "Command `#{Granify::PACKAGE_NAME} #{$request.controller} #{$request.command}` requires a connection to the internet.\nPlease check your network configuration settings."
|
69
|
+
end
|
57
70
|
end
|
58
|
-
end
|
59
71
|
|
60
|
-
|
61
|
-
|
72
|
+
# Run the controller
|
73
|
+
context.exec
|
62
74
|
|
63
|
-
|
64
|
-
|
75
|
+
# Run cleanup commands
|
76
|
+
context.post_exec
|
77
|
+
end
|
65
78
|
end
|
66
79
|
rescue RuntimeError => e
|
67
80
|
Notify.error("#{e.to_s}")
|
data/lib/version.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evertils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Priebe
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/request.rb
|
50
50
|
- lib/router.rb
|
51
51
|
- lib/utils.rb
|
52
|
+
- lib/version.rb
|
52
53
|
- logs/.gitignore
|
53
54
|
homepage: http://rubygems.org/gems/evertils
|
54
55
|
licenses:
|