Class: FileBrowser::Path
- Inherits:
-
Object
- Object
- FileBrowser::Path
- Defined in:
- app/models/file_browser/path.rb
Defined Under Namespace
Classes: NotFoundError
Constant Summary collapse
- BASE =
'/'
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #base ⇒ Object
- #file_list ⇒ Object
- #get_entries ⇒ Object
-
#initialize(name) ⇒ Path
constructor
A new instance of Path.
- #root? ⇒ Boolean
- #validate(name) ⇒ Object
Constructor Details
#initialize(name) ⇒ Path
Returns a new instance of Path.
21 22 23 24 25 |
# File 'app/models/file_browser/path.rb', line 21 def initialize(name) validate(name) @name = name @entries = get_entries end |
Class Attribute Details
.base ⇒ Object
9 10 11 |
# File 'app/models/file_browser/path.rb', line 9 def base @base ||= BASE end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
14 15 16 |
# File 'app/models/file_browser/path.rb', line 14 def entries @entries end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'app/models/file_browser/path.rb', line 14 def name @name end |
Class Method Details
.name_from_params(params) ⇒ Object
16 17 18 19 |
# File 'app/models/file_browser/path.rb', line 16 def self.name_from_params(params) name = params[:id] name == 'root' ? base : name end |
Instance Method Details
#base ⇒ Object
43 44 45 |
# File 'app/models/file_browser/path.rb', line 43 def base self.class.base end |
#file_list ⇒ Object
33 34 35 36 37 |
# File 'app/models/file_browser/path.rb', line 33 def file_list list = Dir.glob("#{name}/*") list.unshift '..' unless root? list end |
#get_entries ⇒ Object
27 28 29 30 31 |
# File 'app/models/file_browser/path.rb', line 27 def get_entries file_list.map do |entry_name| Entry.new(entry_name) end end |
#root? ⇒ Boolean
39 40 41 |
# File 'app/models/file_browser/path.rb', line 39 def root? name == base end |
#validate(name) ⇒ Object
47 48 49 |
# File 'app/models/file_browser/path.rb', line 47 def validate(name) raise NotFoundError unless File.exists?(name) end |