Module: Upkeep::Runtime::Install
- Defined in:
- lib/upkeep/runtime.rb
Class Method Summary collapse
- .call ⇒ Object
- .current_attribute_names(klass) ⇒ Object
- .install_action_dispatch_observers ⇒ Object
- .install_current_attributes_observer ⇒ Object
- .install_warden_observer ⇒ Object
Class Method Details
.call ⇒ Object
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/upkeep/runtime.rb', line 1157 def call return if @installed install_current_attributes_observer install_warden_observer install_action_dispatch_observers ActiveRecord::AttributeMethods::Read.prepend(AttributeObserver) ActiveRecord::Base.prepend(PersistenceObserver) unless ActiveRecord::Base < PersistenceObserver ActiveRecord::Base.prepend(CacheKeyObserver) unless ActiveRecord::Base < CacheKeyObserver ActiveRecord::Relation.prepend(RelationObserver) ActiveRecord::Base.after_commit do |record| ChangeLog.record(ChangeEvents.active_record_commit(record)) end @installed = true end |
.current_attribute_names(klass) ⇒ Object
1208 1209 1210 1211 1212 1213 1214 |
# File 'lib/upkeep/runtime.rb', line 1208 def current_attribute_names(klass) if klass.respond_to?(:defaults) klass.defaults.keys else [] end end |
.install_action_dispatch_observers ⇒ Object
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 |
# File 'lib/upkeep/runtime.rb', line 1194 def install_action_dispatch_observers if defined?(::ActionDispatch::Request::Session) && !(::ActionDispatch::Request::Session < SessionObserver) ::ActionDispatch::Request::Session.prepend(SessionObserver) end if defined?(::ActionDispatch::Cookies::CookieJar) && !(::ActionDispatch::Cookies::CookieJar < CookieObserver) ::ActionDispatch::Cookies::CookieJar.prepend(CookieObserver) end if defined?(::ActionDispatch::Request) && !(::ActionDispatch::Request < RequestObserver) ::ActionDispatch::Request.prepend(RequestObserver) end end |
.install_current_attributes_observer ⇒ Object
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
# File 'lib/upkeep/runtime.rb', line 1176 def install_current_attributes_observer singleton = class << ActiveSupport::CurrentAttributes; self; end singleton.prepend(CurrentAttributesClassObserver) unless singleton < CurrentAttributesClassObserver ObjectSpace.each_object(Class) do |klass| next unless klass < ActiveSupport::CurrentAttributes Runtime.wrap_current_attribute_readers(klass, current_attribute_names(klass)) end end |
.install_warden_observer ⇒ Object
1187 1188 1189 1190 1191 1192 |
# File 'lib/upkeep/runtime.rb', line 1187 def install_warden_observer return unless defined?(::Warden::Proxy) return if ::Warden::Proxy < WardenObserver ::Warden::Proxy.prepend(WardenObserver) end |