Class: Locomotive::Mounter::Reader::ThemeAssetsArray
- Inherits:
-
Object
- Object
- Locomotive::Mounter::Reader::ThemeAssetsArray
- Defined in:
- lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
Instance Method Summary collapse
-
#exclude?(file) ⇒ Boolean
Tell if the file has to be excluded from the array of theme assets.
-
#initialize(root_dir) ⇒ ThemeAssetsArray
constructor
A new instance of ThemeAssetsArray.
- #list ⇒ Object (also: #values)
-
#method_missing(name, *args, &block) ⇒ Object
This class acts a proxy of an array.
Constructor Details
#initialize(root_dir) ⇒ ThemeAssetsArray
Returns a new instance of ThemeAssetsArray.
35 36 37 |
# File 'lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb', line 35 def initialize(root_dir) self.root_dir = root_dir end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
This class acts a proxy of an array
76 77 78 |
# File 'lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb', line 76 def method_missing(name, *args, &block) self.list.send(name.to_sym, *args, &block) end |
Instance Attribute Details
#root_dir ⇒ Object
Returns the value of attribute root_dir.
33 34 35 |
# File 'lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb', line 33 def root_dir @root_dir end |
Instance Method Details
#exclude?(file) ⇒ Boolean
Tell if the file has to be excluded from the array of theme assets. It does not have to be a folder or be in the samples folder or owns a name starting with the underscore character.
69 70 71 72 73 |
# File 'lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb', line 69 def exclude?(file) File.directory?(file) || file.starts_with?(File.join(self.root_dir, 'samples')) || File.basename(file).starts_with?('_') end |
#list ⇒ Object Also known as: values
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb', line 39 def list return @list unless @list.nil? # Follows symlinks and makes sure subdirectories are handled glob_pattern = '**/*/**/*' @list = [].tap do |list| Dir.glob(File.join(self.root_dir, glob_pattern)).each do |file| next if self.exclude?(file) folder = File.dirname(file.gsub("#{self.root_dir}/", '')) asset = Locomotive::Mounter::Models::ThemeAsset.new(folder: folder, filepath: file) list << asset end end end |