Sha256: 561d0d2ecad9b22b8ecd556099521cf28ff21841c49966bbae69c0343480d043

Contents?: true

Size: 868 Bytes

Versions: 3

Compression:

Stored size: 868 Bytes

Contents

module Perus::Server
    class Script < Sequel::Model
        plugin :validation_helpers
        one_to_many :script_commands, order: 'name asc'

        def code_name
            name.gsub(' ', '_').camelize
        end

        def config_hash
            {
                id: id,
                type: 'Script',
                options: {
                    commands: script_commands.collect(&:config_hash)
                }
            }
        end

        def largest_order
            if script_commands.empty?
                0
            else
                script_commands.last.order
            end
        end

        def validate
            super
            validates_presence  :name
            validates_unique    :name
        end

        def after_destroy
            super
            script_commands.each(&:destroy)
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
perus-0.1.2 lib/perus/server/models/script.rb
perus-0.1.1 lib/perus/server/models/script.rb
perus-0.1.0 lib/perus/server/models/script.rb