Class: HuntersImprovement

Inherits:
ApplicationRecord show all
Defined in:
app/models/hunters_improvement.rb

Overview

Improvements taken by the Hunter One is unlocked every 5 Experience

Schema Information

Table name: hunters_improvements

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hunter_idInteger

Returns:

  • (Integer)

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/hunters_improvement.rb', line 18

class HuntersImprovement < ApplicationRecord
  belongs_to :hunter
  belongs_to :improvement

  after_create :apply_improvement
  validate :validate_hunter, on: :create
  validates :improvement_id, uniqueness: { scope: :hunter_id }

  def apply_improvement
    unless ImproveHunter.for(improvement).new(self).improve
      raise ActiveRecord::RecordInvalid
    end
    hunter.gain_experience(-5)
  end

  def validate_hunter
    ImproveHunter.for(improvement).new(self).valid?
  end

  # This is the Pundit Policy that governs HunterImprovement access
  #
  # @see HuntersImprovementPolicy
  def self.policy_class
    HuntersImprovementPolicy
  end
end

#idObject

Returns [].

Returns:


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/hunters_improvement.rb', line 18

class HuntersImprovement < ApplicationRecord
  belongs_to :hunter
  belongs_to :improvement

  after_create :apply_improvement
  validate :validate_hunter, on: :create
  validates :improvement_id, uniqueness: { scope: :hunter_id }

  def apply_improvement
    unless ImproveHunter.for(improvement).new(self).improve
      raise ActiveRecord::RecordInvalid
    end
    hunter.gain_experience(-5)
  end

  def validate_hunter
    ImproveHunter.for(improvement).new(self).valid?
  end

  # This is the Pundit Policy that governs HunterImprovement access
  #
  # @see HuntersImprovementPolicy
  def self.policy_class
    HuntersImprovementPolicy
  end
end

#improvableHash

Returns:

  • (Hash)

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/hunters_improvement.rb', line 18

class HuntersImprovement < ApplicationRecord
  belongs_to :hunter
  belongs_to :improvement

  after_create :apply_improvement
  validate :validate_hunter, on: :create
  validates :improvement_id, uniqueness: { scope: :hunter_id }

  def apply_improvement
    unless ImproveHunter.for(improvement).new(self).improve
      raise ActiveRecord::RecordInvalid
    end
    hunter.gain_experience(-5)
  end

  def validate_hunter
    ImproveHunter.for(improvement).new(self).valid?
  end

  # This is the Pundit Policy that governs HunterImprovement access
  #
  # @see HuntersImprovementPolicy
  def self.policy_class
    HuntersImprovementPolicy
  end
end

#improvement_idInteger

Returns:

  • (Integer)

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/hunters_improvement.rb', line 18

class HuntersImprovement < ApplicationRecord
  belongs_to :hunter
  belongs_to :improvement

  after_create :apply_improvement
  validate :validate_hunter, on: :create
  validates :improvement_id, uniqueness: { scope: :hunter_id }

  def apply_improvement
    unless ImproveHunter.for(improvement).new(self).improve
      raise ActiveRecord::RecordInvalid
    end
    hunter.gain_experience(-5)
  end

  def validate_hunter
    ImproveHunter.for(improvement).new(self).valid?
  end

  # This is the Pundit Policy that governs HunterImprovement access
  #
  # @see HuntersImprovementPolicy
  def self.policy_class
    HuntersImprovementPolicy
  end
end

Class Method Details

.policy_classObject

This is the Pundit Policy that governs HunterImprovement access


40
41
42
# File 'app/models/hunters_improvement.rb', line 40

def self.policy_class
  HuntersImprovementPolicy
end

Instance Method Details

#apply_improvementObject


26
27
28
29
30
31
# File 'app/models/hunters_improvement.rb', line 26

def apply_improvement
  unless ImproveHunter.for(improvement).new(self).improve
    raise ActiveRecord::RecordInvalid
  end
  hunter.gain_experience(-5)
end

#validate_hunterObject


33
34
35
# File 'app/models/hunters_improvement.rb', line 33

def validate_hunter
  ImproveHunter.for(improvement).new(self).valid?
end