class Ladybug::ScriptRepository
Constants
- ROOT_URL
todo: would be nice to dynamically set this to the server name
Public Class Methods
new()
click to toggle source
todo: accept path as param?
# File lib/ladybug/script_repository.rb, line 12 def initialize @scripts = enumerate_scripts end
Public Instance Methods
all()
click to toggle source
# File lib/ladybug/script_repository.rb, line 16 def all @scripts end
find(args)
click to toggle source
# File lib/ladybug/script_repository.rb, line 20 def find(args) @scripts.find do |script| args.all? do |key, value| script[key] == value end end end
Private Instance Methods
enumerate_scripts()
click to toggle source
Return a list of Scripts with all attributes populated
# File lib/ladybug/script_repository.rb, line 31 def enumerate_scripts Dir.glob("**/*"). reject { |f| File.directory?(f) }. select { |f| File.extname(f) == ".rb" }. map do |filename| stat = File.stat(filename) OpenStruct.new( id: SecureRandom.uuid, path: filename, absolute_path: File.expand_path(filename), virtual_url: "#{ROOT_URL}/#{filename}", size: stat.size, last_modified_time: stat.mtime ) end end