Class: Gricer::Mongoid::Request
- Inherits:
-
Object
- Object
- Gricer::Mongoid::Request
- Includes:
- ActiveModel::Request, ActiveModel::Statistics, CounterCache, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/gricer/mongoid/request.rb
Class Method Summary collapse
-
.browsers ⇒ Mongoid::Criteria
Filter out anything that is not a Browser or MobileBrowser.
- .first_by_id(id) ⇒ Object
Instance Method Summary collapse
-
#agent_header=(agent_header) ⇒ Gricer::Agent
Find or Create Gricer::Agent corrosponding to the given user agent string as given in the HTTP header.
-
#init_session ⇒ Gricer::Session
Init the corrosponding Gricer::Session (called before create).
Methods included from ActiveModel::Statistics
Methods included from ActiveModel::Request
included, #ip_address=, #locale, #locale=, #params=, #referer=, #request=
Methods included from CounterCache
Class Method Details
.browsers ⇒ Mongoid::Criteria
Filter out anything that is not a Browser or MobileBrowser
52 53 54 |
# File 'app/models/gricer/mongoid/request.rb', line 52 def self.browsers any_in agent_id: Gricer::Mongoid::Agent.browsers.only(:id).map{|x| x.id} end |
.first_by_id(id) ⇒ Object
56 57 58 |
# File 'app/models/gricer/mongoid/request.rb', line 56 def self.first_by_id(id) where('_id' => id).first end |
Instance Method Details
#agent_header=(agent_header) ⇒ Gricer::Agent
Find or Create Gricer::Agent corrosponding to the given user agent string as given in the HTTP header
64 65 66 |
# File 'app/models/gricer/mongoid/request.rb', line 64 def agent_header=(agent_header) self.agent = "Gricer::#{model_type}::Agent".constantize.find_or_create_by request_header: agent_header end |
#init_session ⇒ Gricer::Session
Init the corrosponding Gricer::Session (called before create)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/gricer/mongoid/request.rb', line 72 def init_session if session if session.updated_at < Time.now - ::Gricer.config.max_session_duration self.session = Session.create previous_session: session, ip_address: @ip_address, agent: agent, requested_locale: @request_locale else self.session.touch end else self.is_first_in_session = true self.session = Session.create ip_address: @ip_address, agent: agent, requested_locale: @request_locale self.session.touch end session end |