evertils 0.4.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 63960e7260e09b841d48009ae22eb7a5fd61171e
4
- data.tar.gz: 596c479a8841329ab8ddb7186f7c8a2a6f2f7d96
2
+ SHA256:
3
+ metadata.gz: '090e7c596124e90b0ef20118f78f1609906eac814fc70f5c68b8c10f8509d867'
4
+ data.tar.gz: fdeda657569494c3fba6a650820f15dae663be3624d7f6650549bc3e240f4847
5
5
  SHA512:
6
- metadata.gz: 0bd824fcdadc08541ecaf17fad468b6c9bff456564da6464f6a2c695149c74835f2be78ea8ee454623248d0368b957a345742a82a3df90d4bcbb7fb4d296154b
7
- data.tar.gz: 83d02e678a531b7cac51102f9330283632830fc7e0a3b4d1b5b5e29f078ee0e5b0ce304d32037ad255c1df686362f461dd57004d8d62c20dcc9996a5f237dcd4
6
+ metadata.gz: 0c98eedc392dfac24e4e23f28a59cbac12667df4aeb250c4db768bc0ad19890446788329021a19fdb2578ed26338076b0c7f1a3d8caff0aeebde3189dbf7baa5
7
+ data.tar.gz: 12dea2af67a4415d7deaa52d7ccb23e6b96ea0cb047100a4fec638cdf76c11c0a57e9278fa3c47ca0e91e83e99c5cc2275531d393c56bbd3443cb5b8925271d9
@@ -44,6 +44,7 @@ module Evertils
44
44
  # +name+:: String/symbol key value
45
45
  def get(name, child = nil)
46
46
  return @yml[name.to_sym][child.to_sym] unless child.nil?
47
+
47
48
  @yml[name.to_sym]
48
49
  end
49
50
 
@@ -52,9 +53,26 @@ module Evertils
52
53
  # +name+:: String/symbol key value
53
54
  def exist?(name, child = nil)
54
55
  return @yml[name].key?(child.to_sym) unless child.nil?
56
+
55
57
  @yml.key?(name.to_sym)
56
58
  end
57
59
 
60
+ # Merge a hash into config data
61
+ # Params:
62
+ # +hash+:: Any arbitrary hash
63
+ def merge(hash)
64
+ @yml.merge!(hash)
65
+ self
66
+ end
67
+
68
+ def symbolize!
69
+ @yml = @yml.inject({}) { |h, (k, v)| h[k.to_sym] = v; h}
70
+ end
71
+
72
+ def pluck(*args)
73
+ @yml.slice(*args)
74
+ end
75
+
58
76
  private
59
77
 
60
78
  # Check if configuration data exists
@@ -48,13 +48,17 @@ module Evertils
48
48
  # Determines if the command can execute
49
49
  # Params:
50
50
  # +command+:: Symbol containing the command we want to execute
51
- def can_exec?(command)
51
+ # +config+:: Configuration data
52
+ def can_exec?(command, config)
52
53
  # no command was passed, check if controller has a default method
53
54
  if command.nil? && respond_to?(:default)
54
55
  @method = :default
55
56
  elsif respond_to? command
56
57
  # check the controller for the requested method
57
58
  @method = command
59
+ elsif is_a? Evertils::Controller::Render
60
+ @method = :from_file
61
+ @request.param = config.pluck(:path, :notebook)
58
62
  else
59
63
  raise NoMethodError, "Invalid method: #{command}"
60
64
  end
@@ -18,7 +18,7 @@ module Evertils
18
18
  append: text
19
19
  }
20
20
 
21
- return Notify.error("Note not found") if note.entity.nil?
21
+ return Notify.error('Note not found') if note.entity.nil?
22
22
 
23
23
  modify(note, edit_conf)
24
24
  end
@@ -31,9 +31,9 @@ module Evertils
31
31
  xml_helper = Evertils::Helper.load('Xml', xml)
32
32
 
33
33
  time = Time.now.strftime('%I:%M')
34
- target = xml.search("div:contains('#{conf[:search]}')").first.next_element
34
+ target = xml.search("h2:contains('#{conf[:search]}')").first
35
35
 
36
- return Notify.error('Unable to log message') if target.nil?
36
+ return Notify.error('Unable to log message, triage section not found') if target.nil?
37
37
 
38
38
  log_message_txt = xml_helper.span("#{time} - #{conf[:append]}")
39
39
  log_message_el = xml_helper.li(log_message_txt)
@@ -0,0 +1,25 @@
1
+ require 'evertils/common/query/simple'
2
+
3
+ module Evertils
4
+ module Controller
5
+ class Render < Controller::Base
6
+ def from_file(config)
7
+ @config = config
8
+ return Notify.warning("Note already exists\n- #{@link}") if note_exists?
9
+
10
+ Notify.info 'Note not found, creating a new one'
11
+
12
+ query = Evertils::Common::Query::Simple.new
13
+ query.create_note_from_yml(@config[:path])
14
+ end
15
+
16
+ def note_exists?
17
+ helper = Evertils::Helper.load('Note')
18
+ note = helper.wait_for(@config[:notebook].to_sym, 3)
19
+ @link = helper.external_url_for(note.entity) unless note.entity.nil?
20
+
21
+ note.exists?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -38,7 +38,7 @@ module Evertils
38
38
  # Template string for note title
39
39
  def date_templates
40
40
  current_date = Date.today
41
- week_stub = day_of_week(current_date.strftime('%a'))
41
+ week_stub = current_date.strftime('%a')
42
42
  start_of_week = Date.commercial(current_date.year, current_date.cweek, 1)
43
43
  end_of_week = Date.commercial(current_date.year, current_date.cweek, 5)
44
44
 
@@ -12,15 +12,15 @@ module Evertils
12
12
  end
13
13
 
14
14
  # Wait for a note to exist
15
- def wait_for(notebook)
15
+ def wait_for(notebook, iterations = Evertils::Type::Base::MAX_SEARCH_SIZE)
16
16
  Notify.info("Waiting for #{notebook}...")
17
17
  note = find_note(notebook)
18
18
 
19
19
  begin
20
20
  # didn't find it the first time? wait and try again
21
21
  if note.entity.nil?
22
- (1..Evertils::Type::Base::MAX_SEARCH_SIZE).each do |iter|
23
- Notify.info(" (#{iter}) #{notebook}")
22
+ (1..iterations).each do |iter|
23
+ Notify.info(" (#{iter}) Looking for #{notebook.downcase}")
24
24
  note = find_note(notebook, true)
25
25
  break unless note.entity.nil? || iter == Evertils::Type::Base::MAX_SEARCH_SIZE
26
26
  end
@@ -46,6 +46,12 @@ module Evertils
46
46
  "evernote:///view/#{@user[:id]}/#{@shard}/#{note.guid}/#{note.guid}/"
47
47
  end
48
48
 
49
+ #
50
+ # @since 1.0.0
51
+ def external_url_for(note)
52
+ "https://www.evernote.com/Home.action#n=#{note.guid}&s=#{@shard}&ses=4&sh=2&sds=5"
53
+ end
54
+
49
55
  # Create a note
50
56
  def create(data)
51
57
  @model.create_note(data)
@@ -1,7 +1,7 @@
1
1
  module Evertils
2
2
  class Request
3
3
  # Access controller variable property externally
4
- attr_reader :controller
4
+ attr_accessor :controller
5
5
  # Access command variable property externally
6
6
  attr_reader :command
7
7
  # Access custom variable property externally
@@ -11,7 +11,7 @@ module Evertils
11
11
  # Access raw_flags variable property externally
12
12
  attr_reader :raw_flags
13
13
  # Access param variable property externally
14
- attr_reader :param
14
+ attr_accessor :param
15
15
 
16
16
  # Create the request object, parse ARGV for values
17
17
  def initialize
@@ -17,9 +17,11 @@ module Evertils
17
17
  # include helpers
18
18
  require "evertils/helpers/#{@request.controller}" if File.exist? "evertils/helpers/#{@request.controller}"
19
19
 
20
+ update_config if uses_config_file?
21
+
20
22
  # perform all required checks
21
23
  must_pass = Helper::Results.new
22
- @config.get(:required).each do |key, value|
24
+ @config.get(:required).each do |key, _|
23
25
  must_pass.add(send("verify_#{key}"))
24
26
  end
25
27
 
@@ -30,8 +32,8 @@ module Evertils
30
32
  Notify.error('Check failed: GPG key not found or not imported into your keychain')
31
33
  rescue RequiredCheckException
32
34
  Notify.error('One or more required checks failed')
33
- rescue LoadError
34
- Notify.error("Controller not found: #{@request.controller}")
35
+ rescue LoadError => e
36
+ Notify.error(e || "Controller not found: #{@request.controller}")
35
37
  end
36
38
  end
37
39
 
@@ -43,11 +45,12 @@ module Evertils
43
45
  begin
44
46
  unless @request.controller.nil?
45
47
  controller = Evertils::Controller.const_get @request.controller.capitalize
48
+ controller = Evertils::Controller::Render if @config.exist?(:path)
46
49
 
47
50
  # create an instance of the requested controller
48
51
  context = controller.new(@config, @request)
49
52
 
50
- if context.can_exec? @request.command
53
+ if context.can_exec? @request.command, @config
51
54
  # Set things up
52
55
  context.pre_exec
53
56
 
@@ -67,6 +70,21 @@ module Evertils
67
70
  end
68
71
  end
69
72
 
73
+ def uses_config_file?
74
+ @config_file_path = File.expand_path("~/.evertils/templates/type/#{@request.command}.yml")
75
+ File.exist? @config_file_path
76
+ end
77
+
78
+ def update_config
79
+ additional_config = { path: @config_file_path }.merge(YAML.safe_load(File.read(@config_file_path)))
80
+ @config.merge(additional_config).symbolize!
81
+ overwrite_controller_with :render
82
+ end
83
+
84
+ def overwrite_controller_with(new_controller)
85
+ @request.controller = new_controller
86
+ end
87
+
70
88
  # checks output of gpg --list-keys for the presence of a specific GPG key
71
89
  def verify_gpgKey
72
90
  # TODO: replace with Open3
@@ -1,3 +1,3 @@
1
1
  module Evertils
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/evertils.rb CHANGED
@@ -30,6 +30,7 @@ require 'evertils/required_check_exception'
30
30
  require 'evertils/config'
31
31
  require 'evertils/request'
32
32
  require 'evertils/controller'
33
+ require 'evertils/controllers/render'
33
34
  require 'evertils/router'
34
35
  require 'evertils/helper'
35
36
  require 'evertils/helpers/formatting'
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.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -124,6 +124,7 @@ files:
124
124
  - lib/evertils/controllers/get.rb
125
125
  - lib/evertils/controllers/log.rb
126
126
  - lib/evertils/controllers/new.rb
127
+ - lib/evertils/controllers/render.rb
127
128
  - lib/evertils/gpg_exception.rb
128
129
  - lib/evertils/helper.rb
129
130
  - lib/evertils/helpers/api-enml-handler.rb
@@ -166,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
167
  - !ruby/object:Gem::Version
167
168
  version: '0'
168
169
  requirements: []
169
- rubyforge_project:
170
- rubygems_version: 2.6.12
170
+ rubygems_version: 3.0.1
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: EN (heart) CLI