Class: ROM::Filesystem::Dataset
- Inherits:
-
Object
- Object
- ROM::Filesystem::Dataset
- Defined in:
- lib/rom/filesystem/dataset.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(dir, options = {}) ⇒ Dataset
constructor
A new instance of Dataset.
- #select(*args) ⇒ Object
- #sort ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(dir, options = {}) ⇒ Dataset
Returns a new instance of Dataset.
4 5 6 7 8 9 |
# File 'lib/rom/filesystem/dataset.rb', line 4 def initialize(dir, = {}) @dir = dir = [:select] ||= ['*'] end |
Instance Method Details
#each(&block) ⇒ Object
19 20 21 |
# File 'lib/rom/filesystem/dataset.rb', line 19 def each(&block) to_a.each(&block) end |
#select(*args) ⇒ Object
11 12 13 |
# File 'lib/rom/filesystem/dataset.rb', line 11 def select(*args) self.class.new(@dir, .merge(select: args)) end |
#sort ⇒ Object
15 16 17 |
# File 'lib/rom/filesystem/dataset.rb', line 15 def sort self.class.new(@dir, .merge(sort: true)) end |
#to_a ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rom/filesystem/dataset.rb', line 23 def to_a root = Pathname.new(@dir.path) paths = [:select].map { |filter| "#{root}/#{filter}" } matches = Dir[*paths].reject { |f| f == '.' || f == '..' } matches = matches.sort if [:sort] matches.map do |filename| path = root.join(filename) { name: path.basename.to_s, path: path } end end |