Class: PgHaMigrations::LockMode
- Inherits:
-
Object
- Object
- PgHaMigrations::LockMode
- Includes:
- Comparable
- Defined in:
- lib/pg_ha_migrations/lock_mode.rb
Constant Summary collapse
- MODE_CONFLICTS =
ActiveSupport::OrderedHash.new
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #conflicts_with?(other) ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(mode) ⇒ LockMode
constructor
A new instance of LockMode.
- #to_sql ⇒ Object
Constructor Details
#initialize(mode) ⇒ LockMode
Returns a new instance of LockMode.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 73 def initialize(mode) @mode = mode .to_s .underscore .delete_suffix("_lock") .to_sym if !MODE_CONFLICTS.keys.include?(@mode) raise ArgumentError, "Unrecognized lock mode #{@mode.inspect}. Valid modes: #{MODE_CONFLICTS.keys}" end end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
69 70 71 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 69 def mode @mode end |
Instance Method Details
#<=>(other) ⇒ Object
92 93 94 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 92 def <=>(other) MODE_CONFLICTS.keys.index(mode) <=> MODE_CONFLICTS.keys.index(other.mode) end |
#==(other) ⇒ Object
100 101 102 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 100 def ==(other) eql?(other) end |
#conflicts_with?(other) ⇒ Boolean
108 109 110 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 108 def conflicts_with?(other) MODE_CONFLICTS[mode].include?(other.mode) end |
#eql?(other) ⇒ Boolean
96 97 98 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 96 def eql?(other) other.is_a?(LockMode) && mode == other.mode end |
#hash ⇒ Object
104 105 106 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 104 def hash mode.hash end |
#to_sql ⇒ Object
85 86 87 88 89 90 |
# File 'lib/pg_ha_migrations/lock_mode.rb', line 85 def to_sql mode .to_s .upcase .gsub("_", " ") end |