Sha256: 88096b23979bd2b85f5e0cf2c8cd7767691cd3290d186d06dc869f1ee28fd59c

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

require 'erb'
require 'ostruct'
require 'fileutils'

require 'rubypitaya/core/main'

module RubyPitaya

  class RubyPitaya

    def self.run_server
      Main.new
    end

    def self.create_project(project_name, folder_path)
      project_path = File.join(folder_path, project_name)
      app_template_path = Path::APP_TEMPLATE_FOLDER_PATH

      FileUtils.cp_r app_template_path, project_path
    end

    def self.create_migration(migration_name)
      migration_name = "#{migration_name}_migration" unless migration_name.underscore.end_with?('migration')
      migration_timestamp = Time.now.utc.to_i
      migration_file_name = "#{migration_timestamp}_#{migration_name.underscore}.rb"
      migration_class_name = migration_name.camelcase

      template_struct = OpenStruct.new(
        class_name: migration_class_name,
      )

      template = File.open(Path::MIGRATION_TEMPLATE_PATH, &:read)
      template_result = ERB.new(template).result(template_struct.instance_eval { binding })

      migration_file_path = File.join(Path::MIGRATIONS_FOLDER_PATH, migration_file_name)
      File.open(migration_file_path, 'w') { |f| f.write(template_result) }

      migration_file_name
    end

    def self.add_plugin(plugin_git_link)
      Dir.mkdir(Path::PLUGINS_FOLDER_PATH) unless File.exists?(Path::PLUGINS_FOLDER_PATH)

      plugin_name = plugin_git_link.scan(/.+\/(.+)\.git/).flatten.first
      plugin_folder_path = File.join(Path::PLUGINS_FOLDER_PATH, plugin_name)
      plugin_git_path = File.join(plugin_folder_path, '.git/')

      FileUtils.rm_rf(plugin_folder_path) if File.exists?(plugin_folder_path)
      `git -C #{Path::PLUGINS_FOLDER_PATH} clone #{plugin_git_link}`
      FileUtils.rm_rf(plugin_git_path)

      plugin_name
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubypitaya-2.11.2 ./lib/rubypitaya.rb
rubypitaya-2.11.1 ./lib/rubypitaya.rb
rubypitaya-2.11.0 ./lib/rubypitaya.rb
rubypitaya-2.10.0 ./lib/rubypitaya.rb
rubypitaya-2.9.3 ./lib/rubypitaya.rb
rubypitaya-2.9.2 ./lib/rubypitaya.rb
rubypitaya-2.9.1 ./lib/rubypitaya.rb