Class: ROM::Plugins::Command::Timestamps
- Inherits:
-
Module
- Object
- Module
- ROM::Plugins::Command::Timestamps
- Defined in:
- lib/rom/plugins/command/timestamps.rb
Overview
A plugin for automatically adding timestamp values when executing a command
Set up attributes to timestamp when the command is called
Defined Under Namespace
Modules: ClassInterface, InstanceMethods
Instance Attribute Summary collapse
- #datestamps ⇒ Object readonly
- #timestamps ⇒ Object readonly
Instance Method Summary collapse
- #included(klass) ⇒ Object private
-
#initialize(timestamps: [], datestamps: []) ⇒ Timestamps
constructor
A new instance of Timestamps.
- #initialize_timestamp_attributes(klass) ⇒ Object
- #store_attributes(attr) ⇒ Object private
Constructor Details
#initialize(timestamps: [], datestamps: []) ⇒ Timestamps
Returns a new instance of Timestamps.
28 29 30 31 |
# File 'lib/rom/plugins/command/timestamps.rb', line 28 def initialize(timestamps: [], datestamps: []) @timestamps = store_attributes() @datestamps = store_attributes(datestamps) end |
Instance Attribute Details
#datestamps ⇒ Object (readonly)
26 27 28 |
# File 'lib/rom/plugins/command/timestamps.rb', line 26 def datestamps @datestamps end |
#timestamps ⇒ Object (readonly)
26 27 28 |
# File 'lib/rom/plugins/command/timestamps.rb', line 26 def @timestamps end |
Instance Method Details
#included(klass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 |
# File 'lib/rom/plugins/command/timestamps.rb', line 39 def included(klass) (klass) klass.include(InstanceMethods) klass.extend(ClassInterface) super end |
#initialize_timestamp_attributes(klass) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/rom/plugins/command/timestamps.rb', line 46 def (klass) klass.setting :timestamp_columns, default: Set.new, reader: true klass.setting :datestamp_columns, default: Set.new, reader: true klass.before :set_timestamps klass.config. = klass..merge() if .any? klass.config.datestamp_columns = klass.datestamp_columns.merge(datestamps) if datestamps.any? end |
#store_attributes(attr) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/rom/plugins/command/timestamps.rb', line 34 def store_attributes(attr) attr.is_a?(Array) ? attr : Array[attr] end |