Module: Neo4j::Rails::Timestamps
- Extended by:
- ActiveSupport::Concern
- Included in:
- Model, Relationship
- Defined in:
- lib/neo4j/rails/timestamps.rb
Overview
Handle all the created_at, updated_at, created_on, updated_on type stuff.
Defined Under Namespace
Modules: ClassMethods
Constant Summary
- TIMESTAMP_PROPERTIES =
[:created_at, :created_on, :updated_at, :updated_on]
Instance Method Summary (collapse)
-
- (Object) create_timestamp
Set the timestamps for this model if timestamps is set to true in the config and the model is set up with the correct property name, e.g.:.
- - (Boolean) new_or_changed?
-
- (Object) update_timestamp
Set the timestamps for this model if timestamps is set to true in the config and the model is set up with the correct property name, e.g.:.
-
- (Object) write_date_or_timestamp(attribute)
Write the timestamp as a Date, DateTime or Time depending on the property type.
Instance Method Details
- (Object) create_timestamp
Set the timestamps for this model if timestamps is set to true in the config and the model is set up with the correct property name, e.g.:
class Trackable < Neo4j::Rails::Model
property :created_at, :type => DateTime
end
29 30 31 |
# File 'lib/neo4j/rails/timestamps.rb', line 29 def #definition provided whenever an :created_at property is defined end |
- (Boolean) new_or_changed?
46 47 48 |
# File 'lib/neo4j/rails/timestamps.rb', line 46 def new_or_changed? self.new? or self.changed? end |
- (Object) update_timestamp
Set the timestamps for this model if timestamps is set to true in the config and the model is set up with the correct property name, e.g.:
class Trackable < Neo4j::Rails::Model
property :updated_at, :type => DateTime
end
19 20 21 |
# File 'lib/neo4j/rails/timestamps.rb', line 19 def #definition provided whenever an :updated_at property is defined end |
- (Object) write_date_or_timestamp(attribute)
Write the timestamp as a Date, DateTime or Time depending on the property type
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/neo4j/rails/timestamps.rb', line 34 def (attribute) value = case self.class._decl_props[attribute.to_sym][:type].to_s when "DateTime" DateTime.now when "Date" Date.today when "Time" Time.now end send("#{attribute}=", value) end |