Class: Perus::Server::Script

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/perus/server/models/script.rb

Instance Method Summary collapse

Instance Method Details

#after_destroyObject



39
40
41
42
# File 'lib/perus/server/models/script.rb', line 39

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

#can_delete?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/perus/server/models/script.rb', line 29

def can_delete?
    actions_dataset.empty?
end

#code_nameObject



7
8
9
# File 'lib/perus/server/models/script.rb', line 7

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

#config_hashObject



11
12
13
14
15
16
17
18
19
# File 'lib/perus/server/models/script.rb', line 11

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

#largest_orderObject



21
22
23
24
25
26
27
# File 'lib/perus/server/models/script.rb', line 21

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

#validateObject



33
34
35
36
37
# File 'lib/perus/server/models/script.rb', line 33

def validate
    super
    validates_presence  :name
    validates_unique    :name
end