Sha256: 0e746006b6ae3bcc93aef70913ea52fc727f225fc696a49699b4008ae49b89c8

Contents?: true

Size: 965 Bytes

Versions: 28

Compression:

Stored size: 965 Bytes

Contents

module Perus::Server
    class Script < Sequel::Model
        plugin :validation_helpers
        one_to_many :script_commands, order: :order
        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

28 entries across 28 versions & 1 rubygems

Version Path
perus-1.0.7 lib/perus/server/models/script.rb
perus-1.0.6 lib/perus/server/models/script.rb
perus-1.0.5 lib/perus/server/models/script.rb
perus-1.0.4 lib/perus/server/models/script.rb
perus-1.0.3 lib/perus/server/models/script.rb
perus-1.0.2 lib/perus/server/models/script.rb
perus-1.0.1 lib/perus/server/models/script.rb
perus-1.0.0 lib/perus/server/models/script.rb
perus-0.1.35 lib/perus/server/models/script.rb
perus-0.1.34 lib/perus/server/models/script.rb
perus-0.1.33 lib/perus/server/models/script.rb
perus-0.1.32 lib/perus/server/models/script.rb
perus-0.1.31 lib/perus/server/models/script.rb
perus-0.1.30 lib/perus/server/models/script.rb
perus-0.1.29 lib/perus/server/models/script.rb
perus-0.1.28 lib/perus/server/models/script.rb
perus-0.1.27 lib/perus/server/models/script.rb
perus-0.1.26 lib/perus/server/models/script.rb
perus-0.1.25 lib/perus/server/models/script.rb
perus-0.1.24 lib/perus/server/models/script.rb