Class: Forms::FieldLocks
- Inherits:
-
Object
- Object
- Forms::FieldLocks
- Defined in:
- lib/forms/field_locks.rb
Instance Attribute Summary collapse
-
#locks ⇒ Object
{ object_name: [method_name, method_name1] }.
Instance Method Summary collapse
- #has_locks? ⇒ Boolean
-
#initialize(params = {}) ⇒ FieldLocks
constructor
@param a instance of some ActiveRecord model.
- #lock(object_name, method) ⇒ Object
- #locked?(object_name, method) ⇒ Boolean
- #resolve(object_name, method, value) ⇒ Object?
- #to_params ⇒ Hash
- #unlock(object_name, method) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ FieldLocks
@param a instance of some ActiveRecord model
10 11 12 13 |
# File 'lib/forms/field_locks.rb', line 10 def initialize(params = {}) @locks = params @locks ||= {} end |
Instance Attribute Details
#locks ⇒ Object
object_name: [method_name, method_name1]
7 8 9 |
# File 'lib/forms/field_locks.rb', line 7 def locks @locks end |
Instance Method Details
#has_locks? ⇒ Boolean
23 24 25 |
# File 'lib/forms/field_locks.rb', line 23 def has_locks? locks.keys.any? end |
#lock(object_name, method) ⇒ Object
48 49 50 51 |
# File 'lib/forms/field_locks.rb', line 48 def lock(object_name, method) locks[object_name] ||= {} locks[object_name].merge!(method => 1) end |
#locked?(object_name, method) ⇒ Boolean
18 19 20 |
# File 'lib/forms/field_locks.rb', line 18 def locked?(object_name, method) (locks[object_name.to_s] && locks[object_name.to_s][method.to_s].to_s == '1') ? true : false end |
#resolve(object_name, method, value) ⇒ Object?
36 37 38 39 40 41 42 43 |
# File 'lib/forms/field_locks.rb', line 36 def resolve(object_name, method, value) return nil if value.nil? if locked?(object_name.to_s, method.to_s) value else nil end end |
#to_params ⇒ Hash
28 29 30 |
# File 'lib/forms/field_locks.rb', line 28 def to_params locks end |
#unlock(object_name, method) ⇒ Object
56 57 58 |
# File 'lib/forms/field_locks.rb', line 56 def unlock(object_name, method) locks[object_name].delete(method) end |