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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5839f89cfdc5266017b3b89e81a1d9681d8ddaa5
4
- data.tar.gz: f6e724cd6b4e41dd952e8acce3aaa0546fcaab7b
3
+ metadata.gz: 2924b74cb4103d45e575f1de3f182ebe4ca26bfa
4
+ data.tar.gz: 42623fee026bc656875791940fc8ea2caadf4fc6
5
5
  SHA512:
6
- metadata.gz: db6c334971fe1d07be6e4d6223bbd8744f9ea634bf85f8f522f8a553f0a08bad4020af869f147ed6604abdb1dd562fce7c0435cb8cb7379b288f95bc8ef84ffd
7
- data.tar.gz: 44780fe32df6f19cc0f5cd70454d932fd8b64219b772b78a2c1a69228ed71b648d6134eedc3293cf4e8941b607c7b8d954db3598655c5cae497952edee0e31cd
6
+ metadata.gz: eaedf666d519a48d0e48c2f77769eb34719d214c166ef1ecf3a221b8e27ae81884c492c86c4e0ad50e509039900b1c3976e8f54af55a3b238449d1a85181c477
7
+ data.tar.gz: 6270782aa6fc8c4662ea21bdca1c1472cd30f9ebecc3d90f206a3a5f5d272af3124cadd02c27c69af1421efc9430d72285aa20b02bec0a80e22c51ba4e4e0fac
data/bin/evertils CHANGED
@@ -15,6 +15,7 @@ require 'digest/md5'
15
15
  require 'mime/types'
16
16
 
17
17
  # include required files
18
+ require_relative "../lib/version.rb"
18
19
  require_relative "../lib/helpers/time.rb"
19
20
  require_relative "../lib/config.rb"
20
21
  require_relative "../lib/request.rb"
data/evertils.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ require "./lib/version"
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'evertils'
3
- s.version = '0.0.8'
5
+ s.version = Granify::VERSION
4
6
  s.date = '2015-07-03'
5
7
  s.summary = "EN (heart) CLI"
6
8
  s.description = "Evernote utilities for your CLI workflow"
data/lib/controller.rb CHANGED
@@ -14,6 +14,11 @@ module Granify
14
14
  # short output
15
15
  @@options[:verbose] = v
16
16
  end
17
+
18
+ opt.on("-V", "--version", "Show app version") do |v|
19
+ # short output
20
+ @version = Granify::PACKAGE_VERSION
21
+ end
17
22
  end.parse!
18
23
  end
19
24
 
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 = ARGV[0].to_sym rescue nil
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
- controller = Granify::Controller.const_get $request.controller.capitalize rescue false
25
-
26
- if !controller
27
- raise "Controller not found: #{$request.controller.capitalize}"
28
- end
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
- context = controller.new
42
+ context = controller.new
31
43
 
32
- if context.can_exec? $request.controller, $request.command
33
- context.pre_exec
44
+ if context.can_exec? $request.controller, $request.command
45
+ context.pre_exec
34
46
 
35
- # no command sent? Use default to populate model data
36
- model_method = ($request.command ? $request.command : context.default_method).to_s + "_data"
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
- # populate model data
39
- method = context.model.public_method(model_method) rescue false
50
+ # populate model data
51
+ method = context.model.public_method(model_method) rescue false
40
52
 
41
- # model is not set, use Base model instead so the controller still has
42
- # access to model methods
43
- if context.model.nil?
44
- context.model = Model::Base.new
45
- end
46
-
47
- # If the method exists, set model data accordingly
48
- # If it doesn't exist then just fail silently, the model may not
49
- # be required by some controllers
50
- if method.respond_to? :call
51
- context.model.data = method.call($request.custom || [])
52
- end
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
- if context.methods_require_internet.include? $request.command
55
- if !Utils.has_internet_connection?
56
- raise RuntimeError, "Command `#{Granify::PACKAGE_NAME} #{$request.controller} #{$request.command}` requires a connection to the internet.\nPlease check your network configuration settings."
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
- # Run the controller
61
- context.exec
72
+ # Run the controller
73
+ context.exec
62
74
 
63
- # Run cleanup commands
64
- context.post_exec
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
@@ -0,0 +1,3 @@
1
+ module Granify
2
+ VERSION = '0.0.10'
3
+ end
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.8
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: