Module: Ak
- Extended by:
- Ak
- Included in:
- Ak
- Defined in:
- lib/ak.rb,
lib/ak/version.rb
Defined Under Namespace
Classes: HotFile, Inflector, Registry
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
6
7
8
|
# File 'lib/ak.rb', line 6
def env
@env
end
|
#root ⇒ Object
Returns the value of attribute root.
6
7
8
|
# File 'lib/ak.rb', line 6
def root
@root
end
|
Class Method Details
.version ⇒ Object
2
3
4
|
# File 'lib/ak/version.rb', line 2
def self.version
'0.0.1'
end
|
Instance Method Details
#registry ⇒ Object
183
184
185
|
# File 'lib/ak.rb', line 183
def registry
@registry ||= Registry.new
end
|
#reload(path, **options) ⇒ Object
140
141
142
|
# File 'lib/ak.rb', line 140
def reload(path, **options)
registry.load(path, options.merge(require: false))
end
|
#reload_folders(*paths) ⇒ Object
150
151
152
153
154
|
# File 'lib/ak.rb', line 150
def reload_folders(*paths)
get_files paths do |file|
reload file, options
end
end
|
#require(path, **options) ⇒ Object
128
129
130
131
|
# File 'lib/ak.rb', line 128
def require(path, **options)
return super path unless development?
registry.load(path, options.merge(require: true))
end
|
#require_folders(*paths) ⇒ Object
144
145
146
147
148
|
# File 'lib/ak.rb', line 144
def require_folders(*paths)
get_files paths do |file|
require_relative file
end
end
|
#require_relative(path, **options) ⇒ Object
133
134
135
136
137
138
|
# File 'lib/ak.rb', line 133
def require_relative(path, **options)
return super path unless development?
caller_path = File.dirname(caller_locations.first.path)
path = File.expand_path(path, caller_path)
registry.load(path, options.merge(require: true))
end
|
#start ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/ak.rb', line 156
def start
return unless development?
dirs = registry.files.map { |file| File.dirname(file.name) }.uniq
filewatcher = Filewatcher.new(dirs)
Thread.new(filewatcher) do |filewatcher|
filewatcher.watch do |filename, event|
begin
puts "\n\n#{event.capitalize} #{filename.gsub("#{root}/", '')}\n\n"
file = registry.find_by(:name, filename)
if file
file.load if event == :created
file.reload if event == :updated
file.unload_and_reload if event == :deleted
else
require(filename)
end
rescue Exception => e
puts "\nError on event #{event}:\n#{'=' * 20}\n#{e}\n"
end
end
end
end
|