class Blufin::SiteResolver

Constants

PORT_RANGE_CRITERIA_ARRAY
SITE
SITE_ALIAS
SITE_NAME
SITE_PORTS
SITE_TITLE

Public Class Methods

get_available_apis() click to toggle source

Get an array of available APIs (for use in Blufin::Terminal messages). @return Array

# File lib/core/site/site_resolver.rb, line 79
def self.get_available_apis
    apis_names = []
    apis_output = []
    apis = Blufin::Projects::get_apis
    apis.each { |api| apis_names << api[1][Blufin::Projects::PROJECT_NAME] }
    api_max_text = apis_names.max_by(&:length).length
    apis.each do |api|
        api = api[1]
        apis_output << "\x1B[38;5;154m#{api[Blufin::Projects::PROJECT_NAME].rjust(api_max_text, ' ')}\x1B[0m\x1B[38;5;240m \xe2\x86\x92 #{get_path_sites}/#{api[Blufin::Projects::PROJECT_NAME]} \x1B[38;5;67m[#{api[Blufin::Projects::PORT_RANGE]}] \x1B[38;5;154m#{api[Blufin::Projects::ALIAS]}"
    end
    apis_output
end
get_site_details_for_validation() click to toggle source

Get an Array of Hashes used for validation, listing purposes. @return Array (of Hash)

# File lib/core/site/site_resolver.rb, line 94
def self.get_site_details_for_validation
    validation_details = {
        :existing_locations => [],
        :existing_titles => [],
        :existing_aliases => [],
        :existing_names => [],
        :existing_ports => []
    }
    get_sitemap(false).each do |key, site|
        nil if key
        validation_details[:existing_locations] << site[:site_location].to_s
        validation_details[:existing_titles] << site[:site_title]
        validation_details[:existing_aliases] << site[:site_alias]
        validation_details[:existing_names] << site[:site_name]
        validation_details[:existing_names_camel_cased] << site[:site_name_camel_cased]
        validation_details[:existing_ports] << site[:site_ports].port_range_raw
    end
    validation_details[:existing_locations].uniq!
    validation_details[:existing_titles].uniq!
    validation_details[:existing_aliases].uniq!
    validation_details[:existing_names].uniq!
    validation_details[:existing_ports].uniq!
    validation_details
end
get_site_domain(site) click to toggle source

Gets the site domain. @return String

# File lib/core/site/site_resolver.rb, line 25
def self.get_site_domain(site)
    validate_site(site)
    get_sitemap[site][:site_domain]
end
get_site_location(site) click to toggle source

Gets the PATH to the site repository. @return String

# File lib/core/site/site_resolver.rb, line 18
def self.get_site_location(site)
    validate_site(site)
    get_sitemap[site][:site_location]
end
get_site_name(site) click to toggle source

Gets the (repository) name of the site. @return String

# File lib/core/site/site_resolver.rb, line 32
def self.get_site_name(site)
    validate_site(site)
    get_sitemap[site][:site_name]
end
get_site_name_camel_cased(site) click to toggle source

Gets the (repository) name of the site in camel-cased version. @return String

# File lib/core/site/site_resolver.rb, line 39
def self.get_site_name_camel_cased(site)
    validate_site(site)
    get_sitemap[site][:site_name_camel_cased]
end
get_site_ports(site) click to toggle source

Gets an object containing all the site ports. @return Blufin::SitePorts

# File lib/core/site/site_resolver.rb, line 53
def self.get_site_ports(site)
    validate_site(site)
    get_sitemap[site][:site_ports]
end
get_site_title(site) click to toggle source

Gets the full name of the site. @return String

# File lib/core/site/site_resolver.rb, line 46
def self.get_site_title(site)
    validate_site(site)
    get_sitemap[site][:site_title]
end
invalidate_sitemap() click to toggle source

Invalidates the sitemap so data will have to be re-retrieved. @return void

# File lib/core/site/site_resolver.rb, line 137
def self.invalidate_sitemap
    @sitemap = nil
end
validate_ports(site_ports) click to toggle source

Validates ports. Needs to be in form of -> 6000-6019 @return boolean

# File lib/core/site/site_resolver.rb, line 121
def self.validate_ports(site_ports)
    return false unless site_ports.is_a?(String) && site_ports.include?('-')
    valid = true
    site_ports_split = site_ports.split('-')
    if site_ports_split.length == 2
        site_ports_split.each { |site_port| valid = false unless site_port =~ /\d{4}/ }
        valid = false unless site_ports_split[1].to_i - site_ports_split[0].to_i == 19
        valid = false unless site_ports_split[0].to_i % 10 == 0
    else
        valid = false
    end
    valid
end
validate_site(site, location = true) click to toggle source

Checks if the site exists and takes 'aliases' into account. Throws ERROR if site doesn'ts exist. @return String

# File lib/core/site/site_resolver.rb, line 61
def self.validate_site(site, location = true)
    if @site_valid[site].nil?
        sitemap = get_sitemap
        if !sitemap.keys.include?(site) || site.nil?
            Blufin::Terminal::error("An API by the name \"#{Blufin::Terminal::format_highlight(site.nil? ? '[nil]' : site)}\" cannot be found \xe2\x80\x94 available APIs are:", get_available_apis, true)
        else
            validate_location(get_sitemap[site][:site_location]) if location
            validate_ports_internal(get_sitemap[site][:site_ports].port_range_raw)
            @site_valid[site] = true
            site
        end
    else
        site
    end
end

Private Class Methods

convert_site_ports_to_object(site_ports) click to toggle source

Converts 6000-6019 to a Blufin::SitePorts object. @return Blufin::SitePorts

# File lib/core/site/site_resolver.rb, line 169
def self.convert_site_ports_to_object(site_ports)
    raise RuntimeError, "Expected a String (port-range), instead got:#{site_ports.class}" unless site_ports.is_a?(String)
    site_ports_split = site_ports.split('-')
    base_port = site_ports_split[0].to_i
    spo = Blufin::SitePorts.new
    spo.port_range_raw = site_ports
    spo.port_numbers_used = (site_ports_split[0]..site_ports_split[1]).to_a
    spo.api = base_port + 0
    spo.cron = base_port + 1
    spo.worker = base_port + 3
    spo.api_admin = base_port + 10
    spo.cron_admin = base_port + 11
    spo.worker_admin = base_port + 13
    spo
end
get_path_sites() click to toggle source

Gets path to sites. @return String

# File lib/core/site/site_resolver.rb, line 270
def self.get_path_sites
    Blufin::Config::get_path('Paths', 'Sites')
end
get_sitemap(with_aliases = true) click to toggle source

Generates the sitemap (only once during each script-run). If 'with_aliases' == TRUE, returns aliases as keys with identical data to original site-name. @return void

# File lib/core/site/site_resolver.rb, line 146
def self.get_sitemap(with_aliases = true)
    if @sitemap.nil?
        @sitemap = {}
        Blufin::Projects::get_apis.each do |project|
            project = project[1]
            sl = "#{get_path_sites}/#{project[Blufin::Projects::PROJECT_NAME]}"
            @sitemap[project[Blufin::Projects::PROJECT_NAME]] = {
                :site_location => sl,
                :site_title => project[Blufin::Projects::TITLE],
                :site_alias => project[Blufin::Projects::ALIAS],
                :site_name => project[Blufin::Projects::PROJECT_NAME],
                :site_name_camel_cased => project[Blufin::Projects::PROJECT_NAME_PASCAL_CASE],
                :site_domain => project[Blufin::Projects::DOMAIN],
                :site_ports => convert_site_ports_to_object(project[Blufin::Projects::PORT_RANGE])
            }
            @sitemap[project[Blufin::Projects::ALIAS]] = @sitemap[project[Blufin::Projects::PROJECT_NAME]] if with_aliases
        end
    end
    @sitemap
end
path_to_blufin_java() click to toggle source

Returns the path to the Blufin Java library from root -> IE: /Users/<your-name>/…/blufin-java @return String

# File lib/core/site/site_resolver.rb, line 252
def self.path_to_blufin_java
    File.expand_path(Blufin::Config::get_path('Paths', 'BlufinJava'))
end
path_to_java_api(site) click to toggle source

Returns the path to Java Api from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-api @return String

# File lib/core/site/site_resolver.rb, line 204
def self.path_to_java_api(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::API}"
end
path_to_java_cron(site) click to toggle source

Returns the path to Java Cron from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-cron @return String

# File lib/core/site/site_resolver.rb, line 210
def self.path_to_java_cron(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::CRON}"
end
path_to_java_lib(site) click to toggle source

Returns the path to Java Lib from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-lib @return String

# File lib/core/site/site_resolver.rb, line 216
def self.path_to_java_lib(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::LIB}"
end
path_to_java_sdk(site) click to toggle source

Returns the path to Java SDK from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-sdk @return String

# File lib/core/site/site_resolver.rb, line 222
def self.path_to_java_sdk(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}"
end
path_to_java_sdk_core(site) click to toggle source

Returns the path to Java SDK from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-sdk/<site-name>-sdk-core @return String

# File lib/core/site/site_resolver.rb, line 228
def self.path_to_java_sdk_core(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}-core"
end
path_to_java_sdk_internal(site) click to toggle source

Returns the path to Java SDK from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-sdk/<site-name>-sdk-internal @return String

# File lib/core/site/site_resolver.rb, line 234
def self.path_to_java_sdk_internal(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}-internal"
end
path_to_java_sdk_oauth(site) click to toggle source

Returns the path to Java SDK from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-sdk/<site-name>-sdk-oauth @return String

# File lib/core/site/site_resolver.rb, line 240
def self.path_to_java_sdk_oauth(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}/#{get_site_name(site)}-#{Blufin::SiteServices::SDK}-oauth"
end
path_to_java_worker(site) click to toggle source

Returns the path to Java Worker from root -> IE: /Users/<your-name>/…/app-infrastructure/<site-name>-worker @return String

# File lib/core/site/site_resolver.rb, line 246
def self.path_to_java_worker(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_APP_INFRASTRUCTURE}/#{get_site_name(site)}-#{Blufin::SiteServices::WORKER}"
end
path_to_sql(site) click to toggle source

Returns the path to SQL files from root -> IE: /Users/<your-name>/…/sql/ @return String

# File lib/core/site/site_resolver.rb, line 258
def self.path_to_sql(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_TO_SQL}"
end
path_to_yml(site) click to toggle source

Returns the path to YML files from root -> IE: /Users/<your-name>/…/yml/ @return String

# File lib/core/site/site_resolver.rb, line 264
def self.path_to_yml(site)
    "#{get_site_location(site)}/#{Blufin::Site::PATH_TO_YML}"
end
validate_location(site_location) click to toggle source

Checks that the site repo path exists. @return void

# File lib/core/site/site_resolver.rb, line 187
def self.validate_location(site_location)
    unless Blufin::Files::path_exists(File.expand_path(site_location))
        Blufin::Terminal::error("Location not found: #{Blufin::Terminal::format_directory(site_location)}", "Please check the #{Blufin::Terminal::format_highlight('path_sites')} value defined in your configuration file \xe2\x86\x92 #{Blufin::Terminal::format_command("#{App::GEM_NAME} x")}")
    end
end
validate_ports_internal(site_ports) click to toggle source

Checks that the ports have a range of 20 and start on a number divisible by 10. @return void

# File lib/core/site/site_resolver.rb, line 195
def self.validate_ports_internal(site_ports)
    raise RuntimeError, "Expected a String (port-range), instead got:#{site_ports.class}" unless site_ports.is_a?(String)
    unless validate_ports(site_ports)
        Blufin::Terminal::error("#{Blufin::Terminal::format_highlight('Port-range')} is in wrong format: #{Blufin::Terminal::format_invalid(site_ports)}. A valid #{Blufin::Terminal::format_highlight('port-range')} must meet the following criteria:", PORT_RANGE_CRITERIA_ARRAY, true)
    end
end