Class: FeideeUtils::Record::ModifiedRecord
- Inherits:
-
Object
- Object
- FeideeUtils::Record::ModifiedRecord
- Defined in:
- lib/feidee_utils/record/modified_record.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ValuePair
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#modified_fields ⇒ Object
readonly
Returns the value of attribute modified_fields.
-
#poid ⇒ Object
readonly
Returns the value of attribute poid.
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(poid, base, head) ⇒ ModifiedRecord
constructor
A new instance of ModifiedRecord.
- #touched? ⇒ Boolean
Constructor Details
#initialize(poid, base, head) ⇒ ModifiedRecord
Returns a new instance of ModifiedRecord.
8 9 10 11 12 13 14 15 |
# File 'lib/feidee_utils/record/modified_record.rb', line 8 def initialize(poid, base, head) raise "Base row doesn't have the given poid." if base.poid != poid raise "Head row doesn't have the given poid." if head.poid != poid @poid = poid @base = base @head = head @modified_fields = self.class.fields_diff(base.field, head.field) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/feidee_utils/record/modified_record.rb', line 5 def base @base end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
5 6 7 |
# File 'lib/feidee_utils/record/modified_record.rb', line 5 def head @head end |
#modified_fields ⇒ Object (readonly)
Returns the value of attribute modified_fields.
6 7 8 |
# File 'lib/feidee_utils/record/modified_record.rb', line 6 def modified_fields @modified_fields end |
#poid ⇒ Object (readonly)
Returns the value of attribute poid.
4 5 6 |
# File 'lib/feidee_utils/record/modified_record.rb', line 4 def poid @poid end |
Class Method Details
.fields_diff(base, head) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/feidee_utils/record/modified_record.rb', line 25 def self.fields_diff base, head (base.keys.sort | head.keys.sort).inject({}) do |hash, key| if base[key] != head[key] hash[key] = ValuePair.new(base[key], head[key]) end hash end end |
Instance Method Details
#changed? ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/feidee_utils/record/modified_record.rb', line 38 def changed? methods.inject(false) do |acc, name| if name.to_s.end_with? "_changed?" acc ||= send name end acc end end |
#touched? ⇒ Boolean
34 35 36 |
# File 'lib/feidee_utils/record/modified_record.rb', line 34 def touched? !modified_fields.empty? end |