<commit_before>require "itamae/resource/base"

module Itamae
  module Plugin
    module Resource
      class Cask < Itamae::Resource::Base
        BREW_CASK = '/usr/local/bin/brew-cask'

        define_attribute :action, default: :install
        define_attribute :target, type: String, default_name: true
        define_attribute :options, type: String, default: "--appdir=/Applications"

        def set_current_attributes
          super
          ensure_brew_cask_availability

          result = run_command("#{BREW_CASK} list | grep '#{attributes.target}$'", error: false)
          current.exist = result.exit_status == 0
        end

        def action_install(options)
          unless current.exist
            run_command([BREW_CASK, "install", attributes.target])
          end
        end

        def action_alfred(options)
          run_command([BREW_CASK, "alfred", attributes.target])
        end

        private

        def ensure_brew_cask_availability
          if run_command("#{BREW_CASK} > /dev/null", error: false).exit_status != 0
            raise "`brew cask` command is not available. Please install brew cask."
          end
        end
      end<commit_msg>Don't depend on default brew prefix<commit_after>require "itamae/resource/base"

module Itamae
  module Plugin
    module Resource
      class Cask < Itamae::Resource::Base
        BREW_CASK = 'brew-cask'

        define_attribute :action, default: :install
        define_attribute :target, type: String, default_name: true
        define_attribute :options, type: String, default: "--appdir=/Applications"

        def set_current_attributes
          super
          ensure_brew_cask_availability

          result = run_command("#{BREW_CASK} list | grep '#{attributes.target}$'", error: false)
          current.exist = result.exit_status == 0
        end

        def action_install(options)
          unless current.exist
            run_command([BREW_CASK, "install", attributes.target])
          end
        end

        def action_alfred(options)
          run_command([BREW_CASK, "alfred", attributes.target])
        end

        private

        def ensure_brew_cask_availability
          if run_command("#{BREW_CASK} > /dev/null", error: false).exit_status != 0
            raise "`brew cask` command is not available. Please install brew cask."
          end
        end
      end
{'fraction_non_alphanumeric': 0.08846960167714885, 'fraction_numerical': 0.0016771488469601676, 'mean_word_length': 2.36056338028169, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1989357', 'n_tokens_mistral': 692, 'n_tokens_neox': 650, 'n_words': 168}