Sha256: e850c99b8c8089ce27c52bf6625d56eff1119ca619808e7f04de32ce1d902db5

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

require "maglove/helper/log_helper"
require "maglove/asset/theme"
module MagLove
  module Commands
    class Base < Thor
      include MagLove::Helper::LogHelper

      def initialize(args, opts, config)
        namespace = self.class.name.split("::").last.underscore
        command = config[:current_command].name
        Logging.mdc["full_command"] = "#{namespace}:#{command}"
        super
        theme.load(options.theme) if options.theme? and options.theme != theme.identifier
      end

      private

      def theme
        Maglove.theme
      end

      def magloft_api
        @magloft_api ||= MagLoft::Api.client(options[:token])
      end

      def reset_invocations(*commands)
        reset_command_invocations(self.class, *commands)
      end

      def reset_command_invocations(parent, *commands)
        if commands.length.zero?
          @_invocations[parent] = []
        else
          commands.each do |command|
            @_invocations[parent].delete(command.to_s)
          end
        end
      end
    end

    module OptionValidator
      def self.validate(switch, value)
        case switch
        when "--theme"
          File.directory?("src/themes/#{value}")
        else
          true
        end
      end

      def self.message(switch, value)
        case switch
        when "--theme"
          "The theme '#{value}' does not exist!"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
maglove-2.0.11 lib/maglove/commands/base.rb
maglove-2.0.10 lib/maglove/commands/base.rb
maglove-2.0.9 lib/maglove/commands/base.rb
maglove-2.0.8 lib/maglove/commands/base.rb
maglove-2.0.7 lib/maglove/commands/base.rb