Sha256: 306607b0f8fb2a8c781eec316eb56a5baa1f874221eab9c95193bf8c48a769fb

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

# frozen_string_literal: true

module Evertils
  module Controller
    class Render < Controller::Base
      def from_file(config)
        @config = config.translate_placeholders.pluck(:title, :notebook, :path, :action)

        return Notify.warning("Note already exists\n- #{@link}") if note_exists?

        Notify.info 'Note not found, creating a new one'

        execute_action(@config[:action].to_sym || :create)
      end

      def note_exists?
        helper = Evertils::Helper.load('Note')
        note = helper.wait_for_by_title(@config[:title], @config[:notebook], 3)
        @link = helper.external_url_for(note.entity) unless note.entity.nil?

        note.exists?
      end

      def execute_action(action)
        case action
        when :duplicate_previous
          Action::DuplicatePrevious.new(@config)
        else
          Action::Create.new(@config)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evertils-1.0.2 lib/evertils/controllers/render.rb