<commit_before>require 'rake/tasklib'
require 'bora/stack'

module Bora
  class Tasks < Rake::TaskLib
    def initialize(stack_name)
      @stack_name = stack_name
      @stack = Stack.new(stack_name)
      @colorize = true
      yield self if block_given?
      define_tasks
    end

    attr_accessor :stack_options, :colorize

    private

    def define_tasks
      define_apply_task
      define_delete_task
      define_diff_task
      define_events_task
      define_template_task
      define_new_template_task
    end

    def define_apply_task
      within_namespace do
        desc "Creates (or updates) the #{@stack_name} stack"
        task :apply do
          invoke_action(@stack.exists? ? "update" : "create", stack_options)
        end
      end
    end

    def define_delete_task
      within_namespace do
        desc "Deletes the #{@stack_name} stack"
        task :delete do
          invoke_action("delete")
        end
      end
    end

    def define_diff_task
      within_namespace do
        desc "Diffs the new template with the #{@stack_name} stack's current template"
        task :diff do
          puts @stack.diff(@stack_options).to_s(@colorize ? :color : :text)
        end
      end
    end

    def define_events_task
      within_namespace do
        desc "Outputs the latest events from the #{@stack_name} stack"
        task :events do
          events = @stack.events
          if events.length > 0
            @stack.events.each { |e| puts e }
          else
            puts "No events for stack #{@stack_name}"
          end
        end
      end
    end

    def define_template_task
      within_namespace do
        desc "Shows the current template for #{@stack_name} stack"
        task :template do
          template = @stack.template
          puts template ? template : "Stack #{@stack_name} does not exist"
        end
      end
    end

    def define_new_template_task
      within_namespace do<commit_msg>Rename 'template' task to 'current_template' to avoid confusion<commit_after>require 'rake/tasklib'
require 'bora/stack'

module Bora
  class Tasks < Rake::TaskLib
    def initialize(stack_name)
      @stack_name = stack_name
      @stack = Stack.new(stack_name)
      @colorize = true
      yield self if block_given?
      define_tasks
    end

    attr_accessor :stack_options, :colorize

    private

    def define_tasks
      define_apply_task
      define_current_template_task
      define_delete_task
      define_diff_task
      define_events_task
      define_new_template_task
    end

    def define_apply_task
      within_namespace do
        desc "Creates (or updates) the #{@stack_name} stack"
        task :apply do
          invoke_action(@stack.exists? ? "update" : "create", stack_options)
        end
      end
    end

    def define_current_template_task
      within_namespace do
        desc "Shows the current template for #{@stack_name} stack"
        task :current_template do
          template = @stack.template
          puts template ? template : "Stack #{@stack_name} does not exist"
        end
      end
    end

    def define_delete_task
      within_namespace do
        desc "Deletes the #{@stack_name} stack"
        task :delete do
          invoke_action("delete")
        end
      end
    end

    def define_diff_task
      within_namespace do
        desc "Diffs the new template with the #{@stack_name} stack's current template"
        task :diff do
          puts @stack.diff(@stack_options).to_s(@colorize ? :color : :text)
        end
      end
    end

    def define_events_task
      within_namespace do
        desc "Outputs the latest events from the #{@stack_name} stack"
        task :events do
          events = @stack.events
          if events.length > 0
            @stack.events.each { |e| puts e }
          else
            puts "No events for stack #{@stack_name}"
          end
        end
      end
    end

    def define_new_template_task
      within_namespace do
{'fraction_non_alphanumeric': 0.06253126563281641, 'fraction_numerical': 0.0005002501250625312, 'mean_word_length': 2.1193447737909517, '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': '3779917', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1130, 'n_words': 338}