Class: OpenvasCli::VasBase

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Dirty, ActiveModel::Validations, ConnAddin, XmlAddin
Defined in:
lib/openvas-cli/vas_base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConnAddin

included

Methods included from XmlAddin

included

Constructor Details

#initialize(attributes = {}) ⇒ VasBase



22
23
24
25
26
27
# File 'lib/openvas-cli/vas_base.rb', line 22

def initialize(attributes={})
  attributes.each { |key, value|
    send("#{key}=".to_sym, value) if public_methods.include?("#{key}=")
  }
  reset_changes
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



20
21
22
# File 'lib/openvas-cli/vas_base.rb', line 20

def id
  @id
end

Class Method Details

.get_by_id(id) ⇒ Object



72
73
74
# File 'lib/openvas-cli/vas_base.rb', line 72

def self.get_by_id(id)
  get_all(:id => id).first
end

Instance Method Details

#create_or_updateObject



76
77
78
# File 'lib/openvas-cli/vas_base.rb', line 76

def create_or_update
  true
end

#delete_recordObject



80
81
82
# File 'lib/openvas-cli/vas_base.rb', line 80

def delete_record
  true
end

#destroyObject



68
69
70
# File 'lib/openvas-cli/vas_base.rb', line 68

def destroy
  delete_record
end

#destroy!Object



64
65
66
# File 'lib/openvas-cli/vas_base.rb', line 64

def destroy!
  delete_record || raise(VasExceptions::RecordNotSaved)
end

#new_record?Boolean



35
36
37
# File 'lib/openvas-cli/vas_base.rb', line 35

def new_record?
  @id == nil || @id.empty?
end

#reset_changesObject



39
40
41
# File 'lib/openvas-cli/vas_base.rb', line 39

def reset_changes
  @changed_attributes.clear if @changed_attributes 
end

#saveObject



60
61
62
# File 'lib/openvas-cli/vas_base.rb', line 60

def save
  create_or_update if valid?      
end

#save!Object



55
56
57
58
# File 'lib/openvas-cli/vas_base.rb', line 55

def save!
  raise(VasExceptions::RecordNotSaved) unless valid?
  create_or_update || raise(VasExceptions::RecordNotSaved)
end

#to_keyObject



47
48
49
50
51
52
53
# File 'lib/openvas-cli/vas_base.rb', line 47

def to_key
  if new_record?
    nil
  else
    [@id]
  end
end

#to_paramObject



43
44
45
# File 'lib/openvas-cli/vas_base.rb', line 43

def to_param
  id
end

#update_attributes(attrs = {}) ⇒ Object



29
30
31
32
33
# File 'lib/openvas-cli/vas_base.rb', line 29

def update_attributes(attrs={})
  attrs.each { |key, value|
    send("#{key}=".to_sym, value) if public_methods.include?("#{key}=")
  }
end