class Convoy::SetupAccessor

Attributes

global_instance[R]

Public Class Methods

new(global_instance) click to toggle source
# File lib/convoy/setup_accessor.rb, line 5
def initialize(global_instance)
    @global_instance = global_instance
end

Public Instance Methods

action_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 45
def action_for(context = [])
    with_context(context) do |current_context|
        action_block_from(current_context)
    end
end
add_global_command(name, options = {}, &block) click to toggle source
# File lib/convoy/setup_accessor.rb, line 113
def add_global_command(name, options = {}, &block)
    global_instance.command(name, options, &block)
end
add_global_option(name, desc, options = {}) click to toggle source
# File lib/convoy/setup_accessor.rb, line 106
def add_global_option(name, desc, options = {})
    with_context([]) do |current_context|
        options_object = options_object_from(current_context)
        options_object.opt name, desc, options
    end
end
arguments_required_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 51
def arguments_required_for(context = [])
    with_context(context) do |current_context|
        context_requires_arguments(current_context)
    end
end
canonical_command_names_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 39
def canonical_command_names_for(context = [])
    with_context(context) do |current_context|
        canonical_command_names_from(current_context)
    end
end
command_aliases_for(command_name, context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 99
def command_aliases_for(command_name, context = [])
    with_context(context) do |current_context|
        commands    = fetch_instance_variable_from(current_context, :commands)
        description = fetch_instance_variable_from(commands[command_name], :aliases)
    end
end
command_description_for(command_name, context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 85
def command_description_for(command_name, context = [])
    with_context(context) do |current_context|
        commands = fetch_instance_variable_from(current_context, :commands)
        fetch_instance_variable_from(commands[command_name], :description)
    end
end
command_names_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 33
def command_names_for(context = [])
    with_context(context) do |current_context|
        command_names_from(current_context)
    end
end
command_summary_for(command_name, context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 92
def command_summary_for(command_name, context = [])
    with_context(context) do |current_context|
        commands = fetch_instance_variable_from(current_context, :commands)
        fetch_instance_variable_from(commands[command_name], :summary)
    end
end
config_file() click to toggle source
# File lib/convoy/setup_accessor.rb, line 65
def config_file
    name = fetch_instance_variable_from(config_file_object, :name)
end
config_file_autocreatable?() click to toggle source
# File lib/convoy/setup_accessor.rb, line 61
def config_file_autocreatable?
    autocreatable = fetch_instance_variable_from(config_file_object, :autocreate)
end
conflicting_options_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 15
def conflicting_options_for(context = [])
    with_context(context) do |current_context|
        conflicts_hash_for(current_context)
    end
end
dependencies_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 27
def dependencies_for(context = [])
    with_context(context) do |current_context|
        dependencies_hash_from(current_context)
    end
end
description_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 79
def description_for(context = [])
    with_context(context) do |current_context|
        fetch_instance_variable_from(current_context, :description)
    end
end
has_config_file?() click to toggle source
# File lib/convoy/setup_accessor.rb, line 57
def has_config_file?
    config_file_object != nil
end
options_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 9
def options_for(context = [])
    with_context(context) do |current_context|
        options_hash_from(current_context)
    end
end
summary_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 73
def summary_for(context = [])
    with_context(context) do |current_context|
        fetch_instance_variable_from(current_context, :summary)
    end
end
validations_for(context = []) click to toggle source
# File lib/convoy/setup_accessor.rb, line 21
def validations_for(context = [])
    with_context(context) do |current_context|
        validations_hash_from(current_context)
    end
end
version() click to toggle source
# File lib/convoy/setup_accessor.rb, line 69
def version
    version_string = fetch_instance_variable_from(global_instance, :version)
end

Private Instance Methods

action_block_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 138
def action_block_from(context_object)
    action_object = fetch_instance_variable_from(context_object, :action)
    block         = fetch_instance_variable_from(action_object, :block)
    #TODO make sure that if there is no block we exit with a client error
end
canonical_command_names_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 150
def canonical_command_names_from(context_object)
    commands = fetch_instance_variable_from(context_object, :commands)
    commands.select do |key, command|
        aliases = fetch_instance_variable_from(command, :aliases)
        !aliases.include?(key)
    end.keys
    #TODO make sure there can be no errors here and at worst it is an empty array
end
command_names_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 144
def command_names_from(context_object)
    commands = fetch_instance_variable_from(context_object, :commands)
    commands.keys
    #TODO make sure there can be no errors here and at worst it is an empty array
end
config_file_object() click to toggle source
# File lib/convoy/setup_accessor.rb, line 119
def config_file_object
    config_file = fetch_instance_variable_from(global_instance, :config_file)
end
conflicts_hash_for(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 172
def conflicts_hash_for(context_object)
    ensure_context_object(context_object, {}) do
        options_object = options_object_from(context_object)
        fetch_instance_variable_from(options_object, :conflicts)
    end
end
context_requires_arguments(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 134
def context_requires_arguments(context_object)
    requires_arguments = fetch_instance_variable_from(context_object, :requires_arguments)
end
dependencies_hash_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 186
def dependencies_hash_from(context_object)
    ensure_context_object(context_object, {}) do
        options_object = options_object_from(context_object)
        fetch_instance_variable_from(options_object, :dependencies)
    end
end
ensure_context_object(context_object, default_value, &block) click to toggle source
# File lib/convoy/setup_accessor.rb, line 202
def ensure_context_object(context_object, default_value, &block)
    context_object ? block.call : default_value
end
fetch_instance_variable_from(instance, instance_variable) click to toggle source
# File lib/convoy/setup_accessor.rb, line 197
def fetch_instance_variable_from(instance, instance_variable)
    instance_variable_symbol = :"@#{instance_variable.to_s}"
    instance.instance_variable_get(instance_variable_symbol)
end
fetch_instance_variable_from_setup(instance_variable) click to toggle source
# File lib/convoy/setup_accessor.rb, line 193
def fetch_instance_variable_from_setup(instance_variable)
    fetch_instance_variable_from(global_instance, instance_variable)
end
options_hash_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 159
def options_hash_from(context_object)
    ensure_context_object(context_object, {}) do
        options_object = options_object_from(context_object)
        fetch_instance_variable_from(options_object, :options)
    end
end
options_object_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 166
def options_object_from(context_object)
    ensure_context_object(context_object, nil) do
        fetch_instance_variable_from(context_object, :options)
    end
end
validations_hash_from(context_object) click to toggle source
# File lib/convoy/setup_accessor.rb, line 179
def validations_hash_from(context_object)
    ensure_context_object(context_object, {}) do
        validations_object = fetch_instance_variable_from(context_object, :options)
        fetch_instance_variable_from(validations_object, :validations)
    end
end
with_context(context = [], &block) click to toggle source
# File lib/convoy/setup_accessor.rb, line 123
def with_context(context = [], &block)
    context         = [] if context.nil? || context.empty?
    context         = [context] unless context.kind_of?(Array)
    current_context = global_instance
    context.each do |command_name|
        commands        = fetch_instance_variable_from(current_context, :commands)
        current_context = commands[command_name.to_sym]
    end
    block.call(current_context)
end