Module: DuckMap::Handlers::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/duck_map/handlers/base.rb
Overview
Base module containing common code for all sitemap handler modules.
Instance Method Summary collapse
-
#sitemap_defaults(options = {}) ⇒ Hash
Returns a copy of the current values held by Config.attributes.
-
#sitemap_first_model(handler = {}) ⇒ ActiveRecord::Base
Finds the first instance of a model object on the current controller object.
- #sitemap_host_options(options = {}) ⇒ Hash
-
#sitemap_url_limit(rows, options = {}) ⇒ Array
Applies the current url limit to a result set.
- #sitemap_url_options(options = {}) ⇒ Hash
Instance Method Details
#sitemap_defaults(options = {}) ⇒ Hash
Returns a copy of the current values held by Config.attributes
50 51 52 |
# File 'lib/duck_map/handlers/base.rb', line 50 def sitemap_defaults( = {}) return DuckMap::Config.copy_attributes end |
#sitemap_first_model(handler = {}) ⇒ ActiveRecord::Base
Finds the first instance of a model object on the current controller object. sitemap_first_model will respect the current setting of :first_model. If :first_model is true, then, it will continue the search and return the first instance of a model object on the current controller object. Otherwise, it will return nil.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/duck_map/handlers/base.rb', line 24 def sitemap_first_model(handler = {}) value = nil begin # determine if we are suppose to look for the first model on the current controller. if handler.kind_of?(Hash) && handler[:first_model] first_model_object = self.find_first_model_object unless first_model_object.blank? value = first_model_object end end rescue Exception => e # expect this exception to occur EVERYTIME... end return value end |
#sitemap_host_options(options = {}) ⇒ Hash
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/duck_map/handlers/base.rb', line 88 def ( = {}) values = {} unless [:canonical_host].blank? values[:host] = [:canonical_host] end unless [:canonical_port].blank? values[:port] = [:canonical_port] end return values end |
#sitemap_url_limit(rows, options = {}) ⇒ Array
Applies the current url limit to a result set. This is really a helper method used by all of the handler methods that return a Array of Hashes numbering greater than one. Handler methods that would normally return one row need not use this helper method. Use it if you implement a custom handler method.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/duck_map/handlers/base.rb', line 63 def sitemap_url_limit(rows, = {}) unless [:url_limit].blank? if rows.length > [:url_limit] rows.slice!([:url_limit], rows.length) end end return rows end |
#sitemap_url_options(options = {}) ⇒ Hash
76 77 78 79 80 81 82 83 84 |
# File 'lib/duck_map/handlers/base.rb', line 76 def ( = {}) values = {} unless [:url_format].blank? values[:format] = [:url_format] end return values.merge(()) end |