Class: DuckMap::Config
- Inherits:
-
Object
- Object
- DuckMap::Config
- Includes:
- Attributes, SitemapObject
- Defined in:
- lib/duck_map/config.rb
Overview
Config holds default values and attributes for sitemap and meta tags. see Guide
Class Method Summary collapse
-
.attributes ⇒ Object
Returns the entire attributes Hash.
-
.attributes=(value) ⇒ Object
Sets the entire attributes Hash.
-
.copy_attributes ⇒ Object
Returns a copy of the entire attributes Hash.
-
.copy_sitemap_attributes_hash ⇒ Object
Returns a copy of the entire sitemap_attributes_hash Hash.
-
.method_missing(meth, *args, &block) ⇒ Object
Performs a get or set on all of the key/values contained in the attributes class variable.
-
.reset(name = :all) ⇒ NilClass
Resets Config.sitemap_attributes_hash and Config.attributes to the defaults.
-
.sitemap_attributes_defined ⇒ TrueClass, FalseClass
This method needs to exist since Attributes is included in this class.
-
.sitemap_attributes_defined=(value) ⇒ TrueClass, FalseClass
Setter method for sitemap_attributes_defined.
-
.sitemap_attributes_hash ⇒ Hash
Class-level accessor method.
-
.sitemap_attributes_hash=(value) ⇒ Hash
Class-level accessor method.
Methods included from SitemapObject
#sitemap_capture_attributes, #sitemap_capture_segments
Methods included from Attributes
#is_sitemap_attributes_defined?, #sitemap_attributes, #sitemap_stripped_attributes
Class Method Details
.attributes ⇒ Object
Returns the entire attributes Hash. return [Hash]
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/duck_map/config.rb', line 143 def self.attributes # set the default values. if !defined?(@@attributes) || @@attributes.nil? # set default values @@attributes = { title: "Untitled", keywords: nil, description: nil, lastmod: Time.now, changefreq: "monthly", priority: "0.5", canonical: nil, canonical_host: nil, canonical_port: nil, compression: :compressed, sitemap_content: :xml, static_host: nil, static_port: nil, static_target: nil, url_format: "html", url_limit: 50000 } end return @@attributes end |
.attributes=(value) ⇒ Object
Sets the entire attributes Hash. return [Hash]
174 175 176 |
# File 'lib/duck_map/config.rb', line 174 def self.attributes=(value) @@attributes = value end |
.copy_attributes ⇒ Object
Returns a copy of the entire attributes Hash. return [Hash]
181 182 183 |
# File 'lib/duck_map/config.rb', line 181 def self.copy_attributes return {}.merge(self.attributes) end |
.copy_sitemap_attributes_hash ⇒ Object
Returns a copy of the entire sitemap_attributes_hash Hash. return [Hash]
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/duck_map/config.rb', line 116 def self.copy_sitemap_attributes_hash values = {} # I actually have code to do a deep clone of a Hash, however, I can't release it right now. # I will in a later release. For now, I will commit another sin. self.sitemap_attributes_hash.each do |item| values[item.first] = {}.merge(item.last) values[item.first][:handler] = {}.merge(item.last[:handler]) end return values end |
.method_missing(meth, *args, &block) ⇒ Object
Performs a get or set on all of the key/values contained in the attributes class variable. To get a value, simply call DuckMap::Config with the method name.
DuckMap::Config.title # => Untitled
To set a value, simply call DuckMap::Config with the method name and an assignment.
DuckMap::Config.title # => Untitled
DuckMap::Config.title = "My App"
DuckMap::Config.title # => My App
I choose to go this route since this ONLY applies to DuckMap::Config and to reduce the amount of accessor methods needed to get/set attributes.
return [Object] Value stored via key.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/duck_map/config.rb', line 201 def self.method_missing(meth, *args, &block) value = nil if meth.to_s =~ /=$/ key = meth.to_s key = key.slice(0, key.length - 1).to_sym self.attributes[key] = args.first else # all tests showed that meth is a Symbol value = self.attributes[meth] end return value end |
.reset(name = :all) ⇒ NilClass
Resets sitemap_attributes_hash and attributes to the defaults.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/duck_map/config.rb', line 18 def self.reset(name = :all) name = name.blank? ? :all : name.to_sym if name.eql?(:all) || name.eql?(:sitemap_attributes_hash) self.sitemap_attributes_hash = nil end if name.eql?(:all) || name.eql?(:attributes) self.attributes = nil end if name.eql?(:all) || name.eql?(:sitemap_attributes_defined) self.sitemap_attributes_defined = nil end return nil end |
.sitemap_attributes_defined ⇒ TrueClass, FalseClass
This method needs to exist since Attributes is included in this class.
See Attributes#is_sitemap_attributes_defined? for details.
42 43 44 45 46 47 48 49 |
# File 'lib/duck_map/config.rb', line 42 def self.sitemap_attributes_defined if !defined?(@@sitemap_attributes_defined) || @@sitemap_attributes_defined.nil? @@sitemap_attributes_defined = false end return @@sitemap_attributes_defined end |
.sitemap_attributes_defined=(value) ⇒ TrueClass, FalseClass
Setter method for sitemap_attributes_defined
54 55 56 |
# File 'lib/duck_map/config.rb', line 54 def self.sitemap_attributes_defined=(value) @@sitemap_attributes_defined = value end |
.sitemap_attributes_hash ⇒ Hash
Class-level accessor method. The value of the class variable @@sitemap_attributes_hash is checked prior to returning a reference to it. If the variable has not been defined or is nil, then, it is initialized with default values.
See Attributes::ClassMethods#sitemap_attributes for an explanation.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/duck_map/config.rb', line 66 def self.sitemap_attributes_hash if !defined?(@@sitemap_attributes_hash) || @@sitemap_attributes_hash.nil? # many tests are sensitive to the values generated by this method. # changes to this structure will make tests fails until you edit # some of the .yml file(s) in the tests directory values = { title: :title, keywords: :keywords, description: :description, lastmod: :updated_at, changefreq: nil, priority: nil, canonical: nil, canonical_host: nil, canonical_port: nil, #compression: nil, # don't need it here. #sitemap_content: nil, # don't need it here. static_host: nil, static_port: nil, #static_target: nil, # don't need it here. url_format: nil, url_limit: nil } @@sitemap_attributes_hash = {} @@sitemap_attributes_hash[:default] = {}.merge(values) @@sitemap_attributes_hash[:default][:handler] = {action_name: :sitemap_index, first_model: false} @@sitemap_attributes_hash[:edit] = {}.merge(values) @@sitemap_attributes_hash[:edit][:handler] = {action_name: :sitemap_edit, first_model: true} @@sitemap_attributes_hash[:index] = {}.merge(values) @@sitemap_attributes_hash[:index][:handler] = {action_name: :sitemap_index, first_model: true} @@sitemap_attributes_hash[:new] = {}.merge(values) @@sitemap_attributes_hash[:new][:handler] = {action_name: :sitemap_new, first_model: true} @@sitemap_attributes_hash[:show] = {}.merge(values) @@sitemap_attributes_hash[:show][:handler] = {action_name: :sitemap_show, first_model: true} end return @@sitemap_attributes_hash end |
.sitemap_attributes_hash=(value) ⇒ Hash
Class-level accessor method. Sets the value of the class variable @@sitemap_attributes_hash. Setting the value to nil will cause it to be re-initialized on the next call to the get method: class variable sitemap_attributes_hash
135 136 137 138 |
# File 'lib/duck_map/config.rb', line 135 def self.sitemap_attributes_hash=(value) @@sitemap_attributes_hash = value return @@sitemap_attributes_hash end |