class Perus::Server::Action

Public Class Methods

add(system_id, params) click to toggle source
# File lib/perus/server/models/action.rb, line 71
def self.add(system_id, params)
    action = Action.new
    action.system_id = system_id

    if params['script_id']
        action.script_id = params['script_id']
    else
        command_config = CommandConfig.create_with_params(params)
        action.command_config_id = command_config.id
    end

    begin
        action.save
    rescue
        if action.command_config_id
            CommandConfig.with_pk!(action.command_config_id).destroy
        end
    end
end

Public Instance Methods

after_destroy() click to toggle source
Calls superclass method
# File lib/perus/server/models/action.rb, line 59
def after_destroy
    super
    
    if command_config_id
        command_config.destroy
    end

    if file
        File.unlink(file_path)
    end
end
command_name() click to toggle source
# File lib/perus/server/models/action.rb, line 24
def command_name
    if script_id
        script.name
    else
        command_config.command
    end
end
config_hash() click to toggle source
# File lib/perus/server/models/action.rb, line 12
def config_hash
    if command_config_id
        hash = command_config.config_hash
    else
        hash = script.config_hash
    end

    # replace the command config/script id with the action's id
    hash['id'] = id
    hash
end
file_name() click to toggle source
# File lib/perus/server/models/action.rb, line 40
def file_name
    file['original_name']
end
file_path() click to toggle source
# File lib/perus/server/models/action.rb, line 50
def file_path
    File.join(system.uploads_dir, file['filename'])
end
file_url() click to toggle source
# File lib/perus/server/models/action.rb, line 44
def file_url
    prefix = URI(Server.options.uploads_url)
    path = File.join(system_id.to_s, file['filename'])
    (prefix + path).to_s
end
options() click to toggle source
# File lib/perus/server/models/action.rb, line 32
def options
    if script_id
        {}
    else
        command_config.options
    end
end
validate() click to toggle source
Calls superclass method
# File lib/perus/server/models/action.rb, line 54
def validate
    super
    validates_presence :system_id
end