Class: Landable::Directory
- Inherits:
-
Object
- Object
- Landable::Directory
- Includes:
- ActiveModel::SerializerSupport
- Defined in:
- app/models/landable/directory.rb
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#subdirectories ⇒ Object
readonly
Returns the value of attribute subdirectories.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, subdirectories = [], pages = []) ⇒ Directory
constructor
A new instance of Directory.
Constructor Details
#initialize(path, subdirectories = [], pages = []) ⇒ Directory
Returns a new instance of Directory.
17 18 19 20 21 |
# File 'app/models/landable/directory.rb', line 17 def initialize(path, subdirectories = [], pages = []) @path = path.squeeze '/' @subdirectories = subdirectories @pages = pages end |
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
14 15 16 |
# File 'app/models/landable/directory.rb', line 14 def pages @pages end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'app/models/landable/directory.rb', line 14 def path @path end |
#subdirectories ⇒ Object (readonly)
Returns the value of attribute subdirectories.
14 15 16 |
# File 'app/models/landable/directory.rb', line 14 def subdirectories @subdirectories end |
Class Method Details
.listing(parent) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/models/landable/directory.rb', line 5 def self.listing(parent) parent_with_slash = parent.gsub(%r{^(.*?)\/?$}, '\1/') pages = Page.where('path LIKE ?', "#{parent_with_slash}%").to_a subdirs = pages.group_by { |page| page.directory_after(parent_with_slash) } notdirs = subdirs.delete(nil) || [] subdirs = subdirs.map { |name, _contents| Directory.new("#{parent}/#{name}") } Directory.new(parent, subdirs.sort_by(&:path), notdirs.sort_by(&:path)) end |