Class: Vitreous::Share::LocalStructure
- Inherits:
-
CommonStructure
- Object
- CommonStructure
- Vitreous::Share::LocalStructure
- Defined in:
- lib/vitreous/share/local_structure.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate(path = @path) ⇒ Object
-
#initialize(path) ⇒ LocalStructure
constructor
A new instance of LocalStructure.
- #tree(path) ⇒ Object
- #uri(path) ⇒ Object
Methods inherited from CommonStructure
Constructor Details
#initialize(path) ⇒ LocalStructure
Returns a new instance of LocalStructure.
5 6 7 |
# File 'lib/vitreous/share/local_structure.rb', line 5 def initialize( path ) @path = path end |
Class Method Details
.base_uri ⇒ Object
30 31 32 |
# File 'lib/vitreous/share/local_structure.rb', line 30 def self.base_uri "" end |
Instance Method Details
#generate(path = @path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vitreous/share/local_structure.rb', line 9 def generate( path = @path ) { 'name' => path == @path ? File.basename( File.dirname( path ) ) : File.basename( path ), 'path' => path == @path ? '/' : path.gsub( @path, '' ), 'uri' => uri( path ), 'type' => File.directory?( path ) ? 'directory' : 'file', 'elements' => File.directory?( path ) ? tree( path ) : [], 'content' => CommonStructure.txt?( path ) ? File.read( path ).force_encoding('utf-8') : nil } end |
#tree(path) ⇒ Object
20 21 22 23 24 |
# File 'lib/vitreous/share/local_structure.rb', line 20 def tree( path ) Dir.glob( File.join( path, '*' ) ).sort.map do |e| generate( e ) end end |
#uri(path) ⇒ Object
26 27 28 |
# File 'lib/vitreous/share/local_structure.rb', line 26 def uri( path ) "#{Vitreous::Share::LocalStructure.base_uri}#{path.gsub( @path, '' )}" end |