Sha256: 27b98864c83b31638f79b01ded9635fc9042258b7daeab6b1456ac62f30a675f

Contents?: true

Size: 871 Bytes

Versions: 7

Compression:

Stored size: 871 Bytes

Contents

module Vp
  module Pears
    class VpTheme < ::Pears::Provider::LocalFile
      class InvalidVpTheme < StandardError; end;

      # Get all
      THEMES = Dir[
        "#{__FILE__}".split('/')
            .slice(0..-4)
            .join('/')
            .+('/themes/*')
      ]

      MAP = Hash[
        THEMES.map do |fil|
          fil.split('/')
              .last
              .delete_suffix('.yml')
        end.zip(THEMES)
      ].with_indifferent_access.freeze

      def initialize(name, on_failure: :raise)
        file = MAP[name.downcase]
        raise InvalidVpTheme.new(name) unless file.present?

        super(file, on_failure: on_failure)
      rescue InvalidVpTheme => e
        if on_failure == :null
          @data = {}
        else
          raise e
        end
      end
    end

    ::Pears::Provider::Builder.enable_provider VpTheme
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vp-themes-0.1.9 lib/vp/pears/vp_theme.rb
vp-themes-0.1.8 lib/vp/pears/vp_theme.rb
vp-themes-0.1.7 lib/vp/pears/vp_theme.rb
vp-themes-0.1.5 lib/vp/pears/vp_theme.rb
vp-themes-0.1.4 lib/vp/pears/vp_theme.rb
vp-themes-0.1.3 lib/vp/pears/vp_theme.rb
vp-themes-0.1.2 lib/vp/pears/vp_theme.rb