evertils 0.3.7 → 0.3.8

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/bin/evertils +7 -38
  3. data/evertils.gemspec +1 -1
  4. data/lib/evertils/config.rb +55 -0
  5. data/lib/evertils/controller.rb +69 -0
  6. data/lib/{controllers → evertils/controllers}/convert.rb +1 -1
  7. data/lib/evertils/controllers/firstrun.rb +24 -0
  8. data/lib/{controllers → evertils/controllers}/generate.rb +11 -27
  9. data/lib/{controllers → evertils/controllers}/get.rb +3 -3
  10. data/lib/{controllers → evertils/controllers}/status.rb +2 -2
  11. data/lib/{helper.rb → evertils/helper.rb} +3 -3
  12. data/lib/{helpers → evertils/helpers}/api-enml-handler.rb +3 -10
  13. data/lib/{helpers → evertils/helpers}/evernote-markdown.rb +14 -14
  14. data/lib/{helpers → evertils/helpers}/formatting.rb +29 -27
  15. data/lib/evertils/request.rb +31 -0
  16. data/lib/evertils/router.rb +56 -0
  17. data/lib/{type.rb → evertils/type.rb} +8 -2
  18. data/lib/{types → evertils/types}/daily.rb +2 -5
  19. data/lib/{types → evertils/types}/monthly-task-summary.rb +2 -11
  20. data/lib/{types → evertils/types}/monthly.rb +3 -6
  21. data/lib/{types → evertils/types}/priority-queue.rb +3 -5
  22. data/lib/{types → evertils/types}/weekly.rb +4 -8
  23. data/lib/{utils.rb → evertils/utils.rb} +4 -4
  24. data/lib/evertils/version.rb +3 -0
  25. data/lib/evertils.rb +39 -0
  26. metadata +33 -34
  27. data/lib/command.rb +0 -179
  28. data/lib/config.rb +0 -65
  29. data/lib/controller.rb +0 -117
  30. data/lib/log.rb +0 -111
  31. data/lib/logs.rb +0 -34
  32. data/lib/request.rb +0 -23
  33. data/lib/router.rb +0 -67
  34. data/lib/version.rb +0 -3
  35. /data/lib/{configs → evertils/configs}/templates/daily.enml +0 -0
  36. /data/lib/{configs/templates/mts.enml → evertils/configs/templates/monthly-task-summaries.enml} +0 -0
  37. /data/lib/{configs → evertils/configs}/templates/monthly.enml +0 -0
  38. /data/lib/{configs → evertils/configs}/templates/pq.enml +0 -0
  39. /data/lib/{configs → evertils/configs}/templates/weekly.enml +0 -0
  40. /data/lib/{controllers → evertils/controllers}/new.rb +0 -0
  41. /data/lib/{helpers → evertils/helpers}/evernote-enml.rb +0 -0
  42. /data/lib/{helpers → evertils/helpers}/results.rb +0 -0
  43. /data/lib/{helpers → evertils/helpers}/time.rb +0 -0
  44. /data/lib/{kernel.rb → evertils/kernel.rb} +0 -0
@@ -1,11 +1,14 @@
1
1
  module Evertils
2
2
  module Type
3
3
  class Base
4
+ attr_reader :title, :content, :notebook
5
+
4
6
  #
5
7
  # @since 0.3.7
6
- def initialize(*args)
8
+ def initialize(config, *args)
7
9
  @model = Evertils::Common::Query::Simple.new
8
10
  @format = Evertils::Helper.load('Formatting')
11
+ @config = config if config
9
12
  @args = args unless args.size.zero?
10
13
  end
11
14
 
@@ -28,7 +31,10 @@ module Evertils
28
31
  #
29
32
  # @since 0.3.7
30
33
  def should_create?
31
- raise 'Should be overwritten in sub classes'
34
+ note_title = @format.date_templates[NOTEBOOK]
35
+ found = @model.find_note_contents(note_title)
36
+
37
+ found.entity.nil?
32
38
  end
33
39
  end
34
40
  end
@@ -1,18 +1,15 @@
1
1
  module Evertils
2
2
  module Type
3
3
  class Daily < Type::Base
4
- attr_reader :title, :content, :notebook
5
-
6
4
  NOTEBOOK = :Daily
7
5
 
8
6
  #
9
7
  # @since 0.3.7
10
- def initialize
11
- super
8
+ def initialize(config, *args)
9
+ super(config, *args)
12
10
 
13
11
  @title = @format.date_templates[NOTEBOOK]
14
12
  @content = @format.template_contents(NOTEBOOK)
15
- @content += to_enml($config.custom_sections[NOTEBOOK]) unless $config.custom_sections.nil?
16
13
  end
17
14
  end
18
15
  end
@@ -1,19 +1,16 @@
1
1
  module Evertils
2
2
  module Type
3
3
  class MonthlyTaskSummary < Type::Base
4
- attr_reader :title, :content, :notebook
5
-
6
4
  NOTEBOOK = :'Monthly Task Summaries'
7
5
 
8
6
  #
9
7
  # @since 0.3.7
10
- def initialize(*args)
11
- super(*args)
8
+ def initialize(config, *args)
9
+ super(config, *args)
12
10
 
13
11
  @name = @args.first
14
12
  @title = "#{@name} #{DateTime.now.strftime('%m-%Y')}"
15
13
  @content = @format.template_contents(NOTEBOOK)
16
- @content += to_enml($config.custom_sections[NOTEBOOK]) unless $config.custom_sections.nil?
17
14
 
18
15
  # BUG: inability to tag notes lies somewhere in evertils-common,
19
16
  # specifically in how note.tag works
@@ -26,12 +23,6 @@ module Evertils
26
23
  # client_tag = tag_manager.find_or_create(@name)
27
24
  # mts_note.tag(client_tag.prop(:name))
28
25
  end
29
-
30
- #
31
- # @since 0.3.7
32
- def notebook
33
- NOTEBOOK
34
- end
35
26
  end
36
27
  end
37
28
  end
@@ -1,18 +1,15 @@
1
1
  module Evertils
2
2
  module Type
3
3
  class Monthly < Type::Base
4
- attr_reader :title, :content, :notebook
5
-
6
4
  NOTEBOOK = :Monthly
7
5
 
8
6
  #
9
7
  # @since 0.3.7
10
- def initialize
11
- super
8
+ def initialize(config, *args)
9
+ super(config, *args)
12
10
 
13
11
  @title = @format.date_templates[NOTEBOOK]
14
12
  @content = @format.template_contents(NOTEBOOK)
15
- @content += to_enml($config.custom_sections[NOTEBOOK]) unless $config.custom_sections.nil?
16
13
 
17
14
  # BUG: inability to tag notes lies somewhere in evertils-common,
18
15
  # specifically in how note.tag works
@@ -30,7 +27,7 @@ module Evertils
30
27
  monthly_note_title = @format.date_templates[NOTEBOOK]
31
28
  found = @model.find_note_contents(monthly_note_title)
32
29
 
33
- !found.entity.nil? && today_is_first_of_month
30
+ found.entity.nil? && today_is_first_of_month
34
31
  end
35
32
  end
36
33
  end
@@ -1,16 +1,14 @@
1
1
  module Evertils
2
2
  module Type
3
3
  class PriorityQueue < Type::Base
4
- attr_reader :title, :content, :notebook
5
-
6
4
  NOTEBOOK = :'Priority Queue'
7
5
 
8
6
  #
9
7
  # @since 0.3.7
10
- def initialize
11
- super
8
+ def initialize(config, *args)
9
+ super(config, *args)
12
10
 
13
- @handler = Evertils::Helper.load('ApiEnmlHandler')
11
+ @handler = Evertils::Helper.load('ApiEnmlHandler', @config)
14
12
 
15
13
  if Date.today.monday?
16
14
  @title, @content = condition_monday
@@ -1,18 +1,15 @@
1
1
  module Evertils
2
2
  module Type
3
3
  class Weekly < Type::Base
4
- attr_reader :title, :content, :notebook
5
-
6
4
  NOTEBOOK = :Weekly
7
5
 
8
6
  #
9
7
  # @since 0.3.7
10
- def initialize
11
- super
8
+ def initialize(config, *args)
9
+ super(config, *args)
12
10
 
13
11
  @title = @format.date_templates[NOTEBOOK]
14
12
  @content = @format.template_contents(NOTEBOOK)
15
- @content += to_enml($config.custom_sections[NOTEBOOK]) unless $config.custom_sections.nil?
16
13
 
17
14
  # BUG: inability to tag notes lies somewhere in evertils-common,
18
15
  # specifically in how note.tag works
@@ -25,13 +22,12 @@ module Evertils
25
22
  #
26
23
  # @since 0.3.7
27
24
  def should_create?
28
- today = Date.today
29
- is_monday = today.monday?
25
+ is_monday = Date.today.monday?
30
26
 
31
27
  weekly_note_title = @format.date_templates[NOTEBOOK]
32
28
  found = @model.find_note_contents(weekly_note_title)
33
29
 
34
- !found.entity.nil? && is_monday
30
+ found.entity.nil? && is_monday
35
31
  end
36
32
  end
37
33
  end
@@ -1,7 +1,7 @@
1
1
  module Evertils
2
2
  class Utils
3
3
  @cache = Hash.new
4
-
4
+
5
5
  # Gets a list of files from the current directory with a specific extension
6
6
  def self.get_files(ext)
7
7
  @cache[:files] ||= Hash.new
@@ -48,7 +48,7 @@ module Evertils
48
48
  @cache[:files][ext].push file.strip.match(/[A-Z ]+(.*)/)[1]
49
49
  end
50
50
  end
51
-
51
+
52
52
  @cache[:files][ext]
53
53
  end
54
54
 
@@ -94,8 +94,8 @@ module Evertils
94
94
  raise TypeError, "unknown os: #{host_os.inspect}"
95
95
  end
96
96
  )
97
- rescue err
98
- Notify.error(err.message)
97
+ rescue e
98
+ Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
99
99
  end
100
100
  end
101
101
 
@@ -0,0 +1,3 @@
1
+ module Evertils
2
+ VERSION = '0.3.8'.freeze
3
+ end
data/lib/evertils.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'date'
2
+ require 'time'
3
+ require 'json'
4
+ require 'optparse'
5
+ require 'rbconfig'
6
+ require 'evernote-thrift'
7
+ require 'net/http'
8
+ require 'uri'
9
+ require 'fileutils'
10
+ require 'cgi'
11
+ require 'notifaction'
12
+ require 'digest/md5'
13
+ require 'mime/types'
14
+ require 'evertils/common'
15
+ require 'yaml'
16
+ require 'nokogiri'
17
+
18
+ # include required files
19
+ require 'evertils/kernel'
20
+ require 'evertils/version'
21
+ require 'evertils/type'
22
+ require 'evertils/helpers/time'
23
+ require 'evertils/helpers/results'
24
+ require 'evertils/helpers/api-enml-handler'
25
+ require 'evertils/config'
26
+ require 'evertils/request'
27
+ require 'evertils/utils'
28
+ require 'evertils/controller'
29
+ require 'evertils/router'
30
+ require 'evertils/helper'
31
+ require 'evertils/helpers/formatting'
32
+ require 'evertils/helpers/evernote-enml'
33
+
34
+ module Evertils
35
+ # Flag to determine if module is running in test mode
36
+ def self.test?
37
+ false
38
+ end
39
+ 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.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -108,39 +108,38 @@ files:
108
108
  - bin/evertils
109
109
  - bin/setup
110
110
  - evertils.gemspec
111
- - lib/command.rb
112
- - lib/config.rb
113
- - lib/configs/templates/daily.enml
114
- - lib/configs/templates/monthly.enml
115
- - lib/configs/templates/mts.enml
116
- - lib/configs/templates/pq.enml
117
- - lib/configs/templates/weekly.enml
118
- - lib/controller.rb
119
- - lib/controllers/convert.rb
120
- - lib/controllers/generate.rb
121
- - lib/controllers/get.rb
122
- - lib/controllers/new.rb
123
- - lib/controllers/status.rb
124
- - lib/helper.rb
125
- - lib/helpers/api-enml-handler.rb
126
- - lib/helpers/evernote-enml.rb
127
- - lib/helpers/evernote-markdown.rb
128
- - lib/helpers/formatting.rb
129
- - lib/helpers/results.rb
130
- - lib/helpers/time.rb
131
- - lib/kernel.rb
132
- - lib/log.rb
133
- - lib/logs.rb
134
- - lib/request.rb
135
- - lib/router.rb
136
- - lib/type.rb
137
- - lib/types/daily.rb
138
- - lib/types/monthly-task-summary.rb
139
- - lib/types/monthly.rb
140
- - lib/types/priority-queue.rb
141
- - lib/types/weekly.rb
142
- - lib/utils.rb
143
- - lib/version.rb
111
+ - lib/evertils.rb
112
+ - lib/evertils/config.rb
113
+ - lib/evertils/configs/templates/daily.enml
114
+ - lib/evertils/configs/templates/monthly-task-summaries.enml
115
+ - lib/evertils/configs/templates/monthly.enml
116
+ - lib/evertils/configs/templates/pq.enml
117
+ - lib/evertils/configs/templates/weekly.enml
118
+ - lib/evertils/controller.rb
119
+ - lib/evertils/controllers/convert.rb
120
+ - lib/evertils/controllers/firstrun.rb
121
+ - lib/evertils/controllers/generate.rb
122
+ - lib/evertils/controllers/get.rb
123
+ - lib/evertils/controllers/new.rb
124
+ - lib/evertils/controllers/status.rb
125
+ - lib/evertils/helper.rb
126
+ - lib/evertils/helpers/api-enml-handler.rb
127
+ - lib/evertils/helpers/evernote-enml.rb
128
+ - lib/evertils/helpers/evernote-markdown.rb
129
+ - lib/evertils/helpers/formatting.rb
130
+ - lib/evertils/helpers/results.rb
131
+ - lib/evertils/helpers/time.rb
132
+ - lib/evertils/kernel.rb
133
+ - lib/evertils/request.rb
134
+ - lib/evertils/router.rb
135
+ - lib/evertils/type.rb
136
+ - lib/evertils/types/daily.rb
137
+ - lib/evertils/types/monthly-task-summary.rb
138
+ - lib/evertils/types/monthly.rb
139
+ - lib/evertils/types/priority-queue.rb
140
+ - lib/evertils/types/weekly.rb
141
+ - lib/evertils/utils.rb
142
+ - lib/evertils/version.rb
144
143
  - logs/.gitignore
145
144
  homepage: http://rubygems.org/gems/evertils
146
145
  licenses:
data/lib/command.rb DELETED
@@ -1,179 +0,0 @@
1
- module Evertils
2
- module Command
3
- class Exec
4
- attr_reader :response, :exitcode
5
- attr_accessor :enable_logging
6
-
7
- #
8
- # class methods
9
- #
10
- class << self
11
- def git_queue_status
12
- if global("git log origin/#{git_current_branch}..HEAD --oneline")
13
- response = @response.split("\n")
14
- response.size > 0
15
- end
16
- end
17
-
18
- def git_push
19
- global("git push -q origin #{git_current_branch}")
20
- end
21
-
22
- def git_checkout
23
- begin
24
- curr_branch = git_current_branch
25
- branch = $request.custom.nil? ? curr_branch : $request.custom[0]
26
-
27
- if !git_branch_verify branch
28
- raise "Requested branch not found in the working copy: #{branch}"
29
- end
30
-
31
- if branch == curr_branch
32
- return Notify.warning("Requested branch is already checked out, skipping checkout")
33
- else
34
- global("git checkout -q #{branch}")
35
- end
36
-
37
- # not found locally, checkout from origin
38
- if !@response
39
- branch = "origin/#{branch}"
40
- global("git checkout -q #{branch}")
41
- end
42
-
43
- if !@response
44
- Notify.error("Unable to locate #{branch} on the remote server or local working copy")
45
- end
46
-
47
- branch
48
- rescue SystemExit, Interrupt
49
- Notify.error("Interrupt caught, exiting")
50
- rescue RuntimeError => e
51
- Notify.error(e.message)
52
- end
53
- end
54
-
55
- def git_current_branch
56
- global("git rev-parse --abbrev-ref HEAD")
57
- end
58
-
59
- def git_branch_verify(branch = nil)
60
- if branch.nil?
61
- branch = git_current_branch
62
- end
63
-
64
- global("git rev-parse --verify #{branch}")
65
- end
66
-
67
- def global(command, file = nil)
68
- begin
69
- # disable logging if user settings prohibit it
70
- #file = nil if !@enable_logging
71
- # default value for exit code is an error
72
- @exitcode = 1
73
-
74
- @response = `#{command}`.chomp
75
- @exitcode = $?.exitstatus
76
-
77
- # Log output to a file
78
- # This method is better than redirecting output to a file because now
79
- # the response is always populated instead of being empty when output
80
- # is sent to the log file
81
- if file
82
- File.open(file.path, 'w+') do |f|
83
- f.write(@response)
84
- end
85
- end
86
-
87
- @response
88
- rescue SystemExit, Interrupt
89
- Notify.error("Interrupt caught, exiting")
90
- end
91
- end
92
- end
93
-
94
- #
95
- # instance methods
96
- #
97
- def minify(file, destination)
98
- begin
99
- min_file = "#{destination}#{File.basename(file, File.extname(file))}.min.js"
100
-
101
- @response = `uglifyjs #{file} -cm -o "#{min_file}"`
102
-
103
- Notify.success("Minified #{file}")
104
-
105
- $?.exitstatus == 0
106
- rescue SystemExit, Interrupt
107
- Notify.error("Interrupt caught, exiting")
108
- end
109
- end
110
-
111
- def lint(file, log_file)
112
- begin
113
- command = `coffeelint -f "#{Evertils::INSTALLED_DIR}/lib/configs/coffeelint.json" #{file}`
114
-
115
- @response = command.include?("Ok!")
116
-
117
- # only send errors to the log file
118
- if !@response
119
- File.open(log_file.path, 'a') do |f|
120
- f.write("Logged at #{Time.now}\n============================================================\n\n")
121
- f.write(command)
122
- end
123
- end
124
-
125
- $?.exitstatus == 0
126
- rescue SystemExit, Interrupt
127
- Notify.error("Interrupt caught, exiting")
128
- end
129
- end
130
-
131
- def open_editor(file=nil)
132
- begin
133
- log_file = file || Evertils::DEFAULT_LOG
134
-
135
- # System editor is not set/unavailable, use system default to open the
136
- # file
137
- if `echo $EDITOR` == ""
138
- if Utils.os == :macosx
139
- `open #{log_file.path}`
140
- else
141
- `xdg-open #{log_file.path}`
142
- end
143
- else
144
- `$EDITOR #{log_file.path}`
145
- end
146
- rescue SystemExit, Interrupt
147
- Notify.error("Interrupt caught, exiting")
148
- end
149
- end
150
-
151
- def arbitrary(command, file = nil)
152
- begin
153
- # default value for exit code is an error
154
- @exitcode = 1
155
- @response = `#{command}`.chomp
156
- @exitcode = $?.exitstatus
157
-
158
- # Log output to a file
159
- # This method is better than redirecting output to a file because now
160
- # the response is always populated instead of being empty when output
161
- # is sent to the log file
162
- if file
163
- File.open(file.path, 'w+') do |f|
164
- f.write("Logged at #{Time.now}\n============================================================\n\n")
165
- f.write(@response)
166
- end
167
- end
168
-
169
- @exitcode == 0
170
-
171
- # support chaining
172
- self
173
- rescue SystemExit, Interrupt
174
- Notify.error("Interrupt caught, exiting")
175
- end
176
- end
177
- end
178
- end
179
- end
data/lib/config.rb DELETED
@@ -1,65 +0,0 @@
1
- module Evertils
2
- PACKAGE_NAME = "evertils"
3
- INSTALLED_DIR = Gem::Specification.find_by_name(Evertils::PACKAGE_NAME).gem_dir
4
- LOG_DIR = INSTALLED_DIR + "/logs"
5
- DEFAULT_LOG = Evertils::Log.new # no args means default log
6
- HELPER_DIR = INSTALLED_DIR + "/lib/helpers/"
7
- CONTROLLER_DIR = INSTALLED_DIR + "/lib/controllers/"
8
- MODEL_DIR = INSTALLED_DIR + "/lib/models/"
9
- TEMPLATE_DIR = INSTALLED_DIR + "/lib/configs/templates/"
10
- LOG_DIGEST_LENGTH = 20
11
- DEBUG = false
12
-
13
- class Cfg
14
- attr_accessor :custom_sections, :custom_templates, :custom_path
15
-
16
- def bootstrap!
17
- load_user_customizations
18
- end
19
-
20
- def constant?(name)
21
- name == name.upcase
22
- end
23
-
24
- def options
25
- keys = Evertils.constants.select do |name|
26
- constant? name
27
- end
28
-
29
- hash = {}
30
- keys.each do |key|
31
- hash[key] = Evertils.const_get(key)
32
- end
33
- hash
34
- end
35
-
36
- #
37
- # @since 0.3.1
38
- def load_user_customizations
39
- conf_path = Dir.home + '/.evertils/'
40
- conf = recursive_symbolize_keys(YAML::load_file(conf_path + 'config.yml'))
41
-
42
- @custom_path = conf_path
43
- @custom_sections = conf[:sections] if conf[:sections]
44
- @custom_templates = conf[:templates] if conf[:templates]
45
- end
46
-
47
- #
48
- # @since 0.3.1
49
- def recursive_symbolize_keys(hash)
50
- hash.inject({}){|result, (key, value)|
51
- new_key = case key
52
- when String then key.to_sym
53
- else key
54
- end
55
- new_value = case value
56
- when Hash then recursive_symbolize_keys(value)
57
- else value
58
- end
59
- result[new_key] = new_value
60
- result
61
- }
62
- end
63
-
64
- end
65
- end
data/lib/controller.rb DELETED
@@ -1,117 +0,0 @@
1
- module Evertils
2
- module Controller
3
- class Base
4
- attr_accessor :model, :helper, :methods_require_internet, :default_method
5
-
6
- @@options = Hash.new
7
-
8
- # Perform pre-run tasks
9
- def pre_exec
10
- OptionParser.new do |opt|
11
- opt.banner = "#{Evertils::PACKAGE_NAME} controller command [...-flags]"
12
-
13
- opt.on("-v", "--verbose", "Verbose output") do |v|
14
- # short output
15
- @@options[:verbose] = v
16
- end
17
-
18
- opt.on("-V", "--version", "Show app version") do |v|
19
- # short output
20
- @version = Evertils::PACKAGE_VERSION
21
- end
22
- end.parse!
23
- end
24
-
25
- # Handle the request
26
- def exec(args = [])
27
- self.send(@default_method.to_sym)
28
- end
29
-
30
- # Perform post-run cleanup tasks, such as deleting old logs
31
- def post_exec(total_errors = 0, total_warnings = 0, total_files = 0)
32
- end
33
-
34
- # Determines if the command can execute
35
- def can_exec?(command = nil, name = nil)
36
- @helper = Evertils::Helper.const_get(command.capitalize).new rescue nil
37
- @methods_require_internet = []
38
-
39
- # get user-defined methods to use as a fallback
40
- user_defined_methods = []
41
-
42
- # timeout is the first system defined method after the user defined
43
- # ones
44
- for i in 0..public_methods.index(:to_json) -1
45
- user_defined_methods.push(public_methods[i].to_sym)
46
- end
47
-
48
- @default_method = name || user_defined_methods.first || :sample
49
-
50
- unless respond_to? @default_method.to_sym, true
51
- Notify.error("Command not found: #{name}")
52
- end
53
-
54
- true
55
- end
56
-
57
- # default method called by exec if no argument is passed
58
- def sample
59
- Notify.warning("Method not implemented");
60
- end
61
-
62
- def required_modules(*modules)
63
- auto_load_required(modules).each do |type, hash|
64
- # Make each auto-loaded module available as an instance variable
65
- # i.e. [:hound]: @hound_controller, @hound_model, @hound_helper
66
- # i.e. [:test]: @test_controller, @test_model, @test_helper
67
- # Only files that exist and can be called are loaded
68
- hash.each do |key, value|
69
- instance_variable_set("@#{key}_#{type}".to_sym, value)
70
- @last_model = instance_variable_get("@#{key}_model")
71
- end
72
- end
73
- end
74
-
75
- private
76
-
77
- # autoload and instantiate required libraries, models and helpers
78
- def auto_load_required(modules = [])
79
- loaded = {:controller => {}, :helper => {}, :model => {}}
80
-
81
- begin
82
- modules.each do |mod|
83
- if File.exists? "#{Evertils::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
84
- require "#{Evertils::INSTALLED_DIR}/lib/controllers/#{mod}.rb"
85
-
86
- loaded[:controller][mod] = Evertils::Controller.const_get(mod.capitalize).new
87
- else
88
- raise StandardError, "Controller not found: #{mod}"
89
- end
90
-
91
- if File.exists? "#{Evertils::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
92
- require "#{Evertils::INSTALLED_DIR}/lib/helpers/#{mod}.rb"
93
- loaded[:helper][mod] = Evertils::Helper.const_get(mod.capitalize).new
94
-
95
- # auto-instantiate new instance of helper for the new instance of the controller
96
- loaded[:controller][mod].helper = loaded[:helper][mod]
97
- end
98
-
99
- if File.exists? "#{Evertils::INSTALLED_DIR}/lib/models/#{mod}.rb"
100
- require "#{Evertils::INSTALLED_DIR}/lib/models/#{mod}.rb"
101
- loaded[:model][mod] = Evertils::Model.const_get(mod.capitalize).new
102
-
103
- # auto-instantiate new instance of model for the new instance of the controller
104
- loaded[:controller][mod].model = loaded[:model][mod]
105
- else
106
- loaded[:controller][mod].model = Model::Base.new
107
- end
108
- end
109
-
110
- loaded
111
- rescue StandardError => e
112
- Notify.error(e.message)
113
- end
114
- end
115
- end
116
- end
117
- end