Class: SpreeCmCommissioner::VectorIcon
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::VectorIcon
- Includes:
- ActiveModel::Validations
- Defined in:
- app/models/spree_cm_commissioner/vector_icon.rb
Constant Summary collapse
- ACCEPTED_EXTENSIONS =
%w[.svg .png].freeze
- TYPES =
%w[cm backend payment_methods].freeze
Instance Attribute Summary collapse
-
#icon_name ⇒ Object
Returns the value of attribute icon_name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#set_name ⇒ Object
Returns the value of attribute set_name.
Class Method Summary collapse
- .all ⇒ Object
-
.asset_files ⇒ Object
rails assets:precompile.
- .search(path_prefix:, extension:, query:) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ VectorIcon
constructor
path: no-icon/backend-arrow-up.svg.
Constructor Details
#initialize(attributes = {}) ⇒ VectorIcon
path: no-icon/backend-arrow-up.svg
set_name: backend icon_name: arrow-up
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 17 def initialize(attributes = {}) path = attributes[:path] name = File.basename(path, '.*') set_name = name.split('-')[0] icon_name = name.delete_prefix("#{set_name}-") send('path=', path) send('set_name=', set_name) send('icon_name=', icon_name) end |
Instance Attribute Details
#icon_name ⇒ Object
Returns the value of attribute icon_name.
4 5 6 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 4 def icon_name @icon_name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 4 def path @path end |
#set_name ⇒ Object
Returns the value of attribute set_name.
4 5 6 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 4 def set_name @set_name end |
Class Method Details
.all ⇒ Object
39 40 41 42 43 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 39 def self.all @all ||= asset_files.filter_map do |path| SpreeCmCommissioner::VectorIcon.new(path: path) if path.end_with?(*ACCEPTED_EXTENSIONS) end end |
.asset_files ⇒ Object
rails assets:precompile
46 47 48 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 46 def self.asset_files @asset_files ||= Rails.application.assets_manifest.assets.keys end |
.search(path_prefix:, extension:, query:) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/models/spree_cm_commissioner/vector_icon.rb', line 29 def self.search(path_prefix:, extension:, query:) icons = all icons = icons.filter { |icon| icon.path.start_with?(path_prefix) } unless path_prefix.nil? icons = icons.filter { |icon| icon.path.end_with?(extension) } unless extension.nil? icons = icons.filter { |icon| query.in? icon.path } unless query.nil? Kaminari.paginate_array(icons) end |