Module: AmberComponent::Assets::ClassMethods
- Included in:
- Base
- Defined in:
- lib/amber_component/assets.rb
Overview
Class methods for assets.
Instance Method Summary collapse
-
#all_asset_dir_paths ⇒ Array<Pathname>
Get an array of all folders containing component assets.
- #asset_dir_from_name ⇒ Pathname?
- #asset_dir_path ⇒ Pathname
-
#asset_file_names(type_regexp) ⇒ Array<String>
Returns the name of the file inside the asset directory of this component that matches the provided ‘Regexp`.
- #asset_path(file_name) ⇒ Pathname?
Instance Method Details
#all_asset_dir_paths ⇒ Array<Pathname>
Get an array of all folders containing component assets. This method should only be used on the parent class ‘AmberComponent::Base` or `ApplicationComponent`.
27 28 29 |
# File 'lib/amber_component/assets.rb', line 27 def all_asset_dir_paths subclasses.map(&:asset_dir_path) end |
#asset_dir_from_name ⇒ Pathname?
17 18 19 20 21 |
# File 'lib/amber_component/assets.rb', line 17 def asset_dir_from_name return unless defined?(::Rails) ::Rails.root / 'app' / 'components' / name.underscore end |
#asset_dir_path ⇒ Pathname
9 10 11 12 13 14 |
# File 'lib/amber_component/assets.rb', line 9 def asset_dir_path component_file_path = source_location.first return asset_dir_from_name unless component_file_path ::Pathname.new component_file_path.delete_suffix('.rb') end |
#asset_file_names(type_regexp) ⇒ Array<String>
Returns the name of the file inside the asset directory of this component that matches the provided ‘Regexp`
44 45 46 47 48 49 50 51 52 |
# File 'lib/amber_component/assets.rb', line 44 def asset_file_names(type_regexp) return [] unless ::File.directory?(asset_dir_path) ::Dir.entries(asset_dir_path).select do |file| next unless ::File.file?(asset_dir_path / file) file.match? type_regexp end end |
#asset_path(file_name) ⇒ Pathname?
33 34 35 36 37 |
# File 'lib/amber_component/assets.rb', line 33 def asset_path(file_name) return unless file_name asset_dir_path / file_name end |