Class: Yoda::Server::Session::FileStore
- Inherits:
-
Object
- Object
- Yoda::Server::Session::FileStore
- Defined in:
- lib/yoda/server/session.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get(uri_string) ⇒ String?
-
#initialize ⇒ FileStore
constructor
A new instance of FileStore.
- #load(uri_string) ⇒ Object
- #program_file_uri?(uri_string) ⇒ Boolean
- #read(uri_string) ⇒ Object
- #store(uri_string, text) ⇒ Object
Constructor Details
#initialize ⇒ FileStore
Returns a new instance of FileStore.
53 54 55 |
# File 'lib/yoda/server/session.rb', line 53 def initialize @cache = {} end |
Class Method Details
.path_of_uri(uri_string) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/yoda/server/session.rb', line 88 def self.path_of_uri(uri_string) uri = URI.parse(uri_string) return nil unless uri.scheme == 'file' uri.path rescue URI::InvalidURIError nil end |
.uri_of_path(path) ⇒ Object
83 84 85 |
# File 'lib/yoda/server/session.rb', line 83 def self.uri_of_path(path) "file://#{File.(path)}" end |
Instance Method Details
#get(uri_string) ⇒ String?
59 60 61 |
# File 'lib/yoda/server/session.rb', line 59 def get(uri_string) @cache[uri_string] end |
#load(uri_string) ⇒ Object
71 72 73 |
# File 'lib/yoda/server/session.rb', line 71 def load(uri_string) store(uri_string, read(uri_string)) end |
#program_file_uri?(uri_string) ⇒ Boolean
97 98 99 100 101 |
# File 'lib/yoda/server/session.rb', line 97 def program_file_uri?(uri_string) %w(.c .rb).include?(File.extname(URI.parse(uri_string).path)) rescue URI::InvalidURIError => _e false end |
#read(uri_string) ⇒ Object
76 77 78 79 80 |
# File 'lib/yoda/server/session.rb', line 76 def read(uri_string) path = self.class.path_of_uri(uri_string) fail ArgumentError unless path File.read(path) end |
#store(uri_string, text) ⇒ Object
65 66 67 68 |
# File 'lib/yoda/server/session.rb', line 65 def store(uri_string, text) return unless program_file_uri?(uri_string) @cache[uri_string] = text end |