Module: Adjective::Vulnerable

Defined in:
lib/modules/vulnerable.rb

Constant Summary collapse

VULNERABLE_ATTRIBUTES =
[:hitpoints, :max_hitpoints]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adjective_add_columns(klass) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/modules/vulnerable.rb', line 47

def self.adjective_add_columns(klass)
  columns = <<-RUBY
# Vulnerable Attributes
add_column {{klass}}, :hitpoints, :integer
add_column {{klass}}, :max_hitpoints, :integer
RUBY
  columns.gsub("{{klass}}", ":#{klass.downcase}")
end

.adjective_columnsObject



39
40
41
42
43
44
45
# File 'lib/modules/vulnerable.rb', line 39

def self.adjective_columns
  <<-RUBY
  # Vulnerable Attributes
  t.integer :hitpoints
  t.integer :max_hitpoints
  RUBY
end

Instance Method Details

#define_vulnerable_instance_variables(args) ⇒ Object



32
33
34
35
36
37
# File 'lib/modules/vulnerable.rb', line 32

def define_vulnerable_instance_variables(args)
  args.each do |key, value|
    self.class.send(:attr_accessor, key)
    self.instance_variable_set("@#{key.to_s}", value)
  end 
end

#init_vulnerable(args = {}) {|_self| ... } ⇒ Object

write the other logic

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
17
18
19
# File 'lib/modules/vulnerable.rb', line 13

def init_vulnerable(args = {}, &block)
  if !Adjective.configuration.use_active_record
    define_vulnerable_instance_variables(vulnerable_default_data)
  end
  yield(self) if block_given?
  # validate_vulnerable_attributes(args)
end

#set_vulnerable_data(args) ⇒ Object



28
29
30
# File 'lib/modules/vulnerable.rb', line 28

def set_vulnerable_data(args)

end

#vulnerable_default_dataObject



21
22
23
24
25
26
# File 'lib/modules/vulnerable.rb', line 21

def vulnerable_default_data
  {
    hitpoints: 1,
    max_hitpoints: 10
  }
end