Sha256: dc161746fe6c1cb1e48b8651b63bbb744ed28c6cf136b899b31d902c219a96de

Contents?: true

Size: 969 Bytes

Versions: 13

Compression:

Stored size: 969 Bytes

Contents

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

        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 can_delete?
            actions_dataset.empty?
        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

13 entries across 13 versions & 1 rubygems

Version Path
perus-0.1.15 lib/perus/server/models/script.rb
perus-0.1.14 lib/perus/server/models/script.rb
perus-0.1.13 lib/perus/server/models/script.rb
perus-0.1.12 lib/perus/server/models/script.rb
perus-0.1.11 lib/perus/server/models/script.rb
perus-0.1.10 lib/perus/server/models/script.rb
perus-0.1.9 lib/perus/server/models/script.rb
perus-0.1.8 lib/perus/server/models/script.rb
perus-0.1.7 lib/perus/server/models/script.rb
perus-0.1.6 lib/perus/server/models/script.rb
perus-0.1.5 lib/perus/server/models/script.rb
perus-0.1.4 lib/perus/server/models/script.rb
perus-0.1.3 lib/perus/server/models/script.rb