duck_map 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/duck_map/handlers/index.rb +36 -10
- data/lib/duck_map/handlers/show.rb +54 -0
- data/lib/duck_map/mapper.rb +4 -6
- data/lib/duck_map/route.rb +232 -211
- data/lib/duck_map/route_set.rb +1 -0
- data/lib/duck_map/version.rb +1 -1
- metadata +2 -2
@@ -4,15 +4,6 @@ module DuckMap
|
|
4
4
|
module Handlers
|
5
5
|
|
6
6
|
##################################################################################
|
7
|
-
# get default values and assign to local variable containing all values from a single url node
|
8
|
-
# and meta tag values for the index action. the local variable is referred to as "values".
|
9
|
-
# - user can override method and manipulate the default values...
|
10
|
-
# index action is called.
|
11
|
-
# - uses existing values generated via the index method
|
12
|
-
# - gives the developer a chance to set instance values to handle special cases
|
13
|
-
# lastmod is obtained from locale and merged with "values".
|
14
|
-
# call sitemap_capture_attributes on the controller to capture values of the current state and merge them with "values".
|
15
|
-
#
|
16
7
|
module Index
|
17
8
|
extend ActiveSupport::Concern
|
18
9
|
|
@@ -27,6 +18,40 @@ module DuckMap
|
|
27
18
|
end
|
28
19
|
|
29
20
|
##################################################################################
|
21
|
+
# Default handler method for index actions.
|
22
|
+
#
|
23
|
+
# The source of a request for data can be from two sources.
|
24
|
+
# - sitemap requesting url nodes for a given route.
|
25
|
+
# - meta tag requesting data for HEAD section meta tags.
|
26
|
+
#
|
27
|
+
# This method will return an Array of Hashes that represent url nodes of a sitemap. Also,
|
28
|
+
# sitemap_meta_data is populated with a single Hash for meta tags. So, this is considered
|
29
|
+
# a shared method.
|
30
|
+
#
|
31
|
+
# The basic procedure is as follows:
|
32
|
+
#
|
33
|
+
# - default values are obtained from {DuckMap::Config} and stored in a return Hash.
|
34
|
+
# - if request source is :sitemap, then, the index method of the controller is called.
|
35
|
+
# This will allow you to set instance variables, etc. within the index method of a controller.
|
36
|
+
# - static last-modified date is obtained from config/locales/sitemap.yml
|
37
|
+
# - sitemap_capture_attributes is called directly on the controller. Any values are merged with the return Hash.
|
38
|
+
# - process some type of model in the following order of precedence depending on configuration.
|
39
|
+
# - process block
|
40
|
+
# if the controller was configured with a block, then, execute the block and use the return value
|
41
|
+
# as the data source for values.
|
42
|
+
# - process model configured via the handler
|
43
|
+
# if a model class was assigned to the handler, then, execute "all" method on the model and use the return value
|
44
|
+
# as the data source for values.
|
45
|
+
# - first model object automagically found on the controller
|
46
|
+
# unless "first_model" has been set to false, find the first instance of a model object on the controller
|
47
|
+
# and use it as the data source for values.
|
48
|
+
# - once a data source object has been established, call sitemap_capture_attributes to obtain values and merge
|
49
|
+
# them with the return Hash.
|
50
|
+
# - unless a canonical url has been obtained during any of the preceding steps, build the canonical url
|
51
|
+
# based on the route and data source object found during preceding steps.
|
52
|
+
# - add the return Hash to the return Array and set the meta tag instance variable.
|
53
|
+
# - done.
|
54
|
+
# @return [Array]
|
30
55
|
def sitemap_index(options = {})
|
31
56
|
rows = []
|
32
57
|
|
@@ -50,7 +75,6 @@ module DuckMap
|
|
50
75
|
|
51
76
|
end
|
52
77
|
|
53
|
-
|
54
78
|
lastmod = self.sitemap_static_lastmod(options[:controller_name], options[:action_name])
|
55
79
|
unless lastmod.blank?
|
56
80
|
values[:lastmod] = lastmod
|
@@ -115,6 +139,7 @@ module DuckMap
|
|
115
139
|
# i'm really being lazy here, but, if the current route is
|
116
140
|
# the root, then, reassign the url to eliminate ?format=html, etc.
|
117
141
|
# from the url.
|
142
|
+
# index actions do not require segment keys, therefore, no need to process them.
|
118
143
|
if !route.name.blank? && route.name.eql?("root")
|
119
144
|
url_options.delete(:format)
|
120
145
|
values[:canonical] = root_url(url_options)
|
@@ -127,6 +152,7 @@ module DuckMap
|
|
127
152
|
values[:loc] = values[:canonical]
|
128
153
|
end
|
129
154
|
|
155
|
+
# push the merged hash and set the instance variable for the meta tag
|
130
156
|
rows.push(values)
|
131
157
|
|
132
158
|
self.sitemap_meta_data = values
|
@@ -8,6 +8,60 @@ module DuckMap
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
##################################################################################
|
11
|
+
# Default handler method for show actions.
|
12
|
+
#
|
13
|
+
# The source of a request for data can be from two sources.
|
14
|
+
# - sitemap requesting url nodes for a given route.
|
15
|
+
# - meta tag requesting data for HEAD section meta tags.
|
16
|
+
#
|
17
|
+
# This method will return an Array of Hashes that represent url nodes of a sitemap. Also,
|
18
|
+
# sitemap_meta_data is populated with a single Hash for meta tags. So, this is considered
|
19
|
+
# a shared method.
|
20
|
+
#
|
21
|
+
# The basic procedure is as follows:
|
22
|
+
#
|
23
|
+
# - default values are obtained from {DuckMap::Config} and stored in a return Hash.
|
24
|
+
# - the controller "show" action method is never called as it is not needed.
|
25
|
+
# - if the request is a meta tag, then, the show method has already been called.
|
26
|
+
# - if the request is a sitemap, then, we would looking for a list of rows instead of just one
|
27
|
+
# row, because, a show route would always be pointing to a single item and the sitemap would want to show
|
28
|
+
# all of those items or at least a defined list of them.
|
29
|
+
# - static last-modified date is obtained from config/locales/sitemap.yml
|
30
|
+
# - sitemap_capture_attributes is called directly on the controller. Any values are merged with the return Hash.
|
31
|
+
# - now, the processing splits based on the type of request.
|
32
|
+
# - if meta tag
|
33
|
+
# - first model object automagically found on the controller
|
34
|
+
# unless "first_model" has been set to false, find the first instance of a model object on the controller
|
35
|
+
# and use it as the data source for values.
|
36
|
+
# - unless a canonical url has been obtained during any of the preceding steps, build the canonical url
|
37
|
+
# based on the route and data source object found during preceding steps. the segment keys are NOT processed
|
38
|
+
# as the values should be automagically part of the url building since this is being called as part of an
|
39
|
+
# HTTP request. The segment key should simply already be there.
|
40
|
+
# - add the return Hash to the return Array and set the meta tag instance variable.
|
41
|
+
# - otherwise, assume sitemap
|
42
|
+
# - process some type of model in the following order of precedence depending on configuration.
|
43
|
+
# - process block
|
44
|
+
# if the controller was configured with a block, then, execute the block and use the return value
|
45
|
+
# as the data source for values.
|
46
|
+
# - process model configured via the handler
|
47
|
+
# if a model class was assigned to the handler, then, execute "all" method on the model and use the return value
|
48
|
+
# as the data source for values.
|
49
|
+
# - model object automagically found by the sitemap_build method.
|
50
|
+
# the "all" method is called on the model object.
|
51
|
+
# - first model object is never processed for the show method when the request is via a sitemap.
|
52
|
+
# the reason is the show method is never called, therefore, an instance of a model would not exist on the controller.
|
53
|
+
# - the goal is ALWAYS to work with a list of model objects. once a list has been established,
|
54
|
+
# process all of the model objects in the list.
|
55
|
+
# - for each object
|
56
|
+
# - build a row Hash based copied from all of the values captured thus far.
|
57
|
+
# - call sitemap_capture_attributes on the model to obtain values and merge them with the row Hash.
|
58
|
+
# - unless a canonical url has been obtained during any of the preceding steps, build the canonical url
|
59
|
+
# based on the route and data source object found during preceding steps. segment keys are build via a call
|
60
|
+
# to sitemap_capture_segments on the model.
|
61
|
+
# - add the row Hash to the return Array
|
62
|
+
# - do nothing to the meta tag instance variable.
|
63
|
+
# - done.
|
64
|
+
# @return [Array]
|
11
65
|
def sitemap_show(options = {})
|
12
66
|
rows = []
|
13
67
|
|
data/lib/duck_map/mapper.rb
CHANGED
@@ -125,13 +125,11 @@ module DuckMap
|
|
125
125
|
# this is where the actual filtering of routes occurs and is based on the current sitemap filter settings.
|
126
126
|
# if the route passes the criteria, then, it is "marked" as part of the sitemap.
|
127
127
|
# no need to evaluate it every time a sitemap is requested. evaluate it now and mark it.
|
128
|
-
|
129
|
-
|
130
|
-
if @set.include_route?(@set.routes.routes[index]) && !sitemap_route_name.blank?
|
128
|
+
unless @set.routes.routes[index].blank?
|
129
|
+
if @set.routes.routes[index].sitemap_route_name.blank?
|
131
130
|
@set.routes.routes[index].sitemap_route_name = sitemap_route_name
|
132
|
-
|
133
|
-
|
134
|
-
@set.routes.routes[index].sitemap_route_name = "do_not_use"
|
131
|
+
@set.routes.routes[index].available = @set.include_route?(@set.routes.routes[index])
|
132
|
+
total += @set.routes.routes[index].is_available? ? 1 : 0
|
135
133
|
end
|
136
134
|
end
|
137
135
|
|
data/lib/duck_map/route.rb
CHANGED
@@ -16,260 +16,281 @@ module DuckMap
|
|
16
16
|
extend ActiveSupport::Concern
|
17
17
|
include DuckMap::ArrayHelper
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# Identifies the current routes as being a sitemap route.
|
23
|
-
attr_accessor :is_sitemap
|
19
|
+
# Identifies the current routes as being a sitemap route.
|
20
|
+
attr_accessor :is_sitemap
|
24
21
|
|
25
|
-
|
26
|
-
|
22
|
+
# The route name of the sitemap which the current route is assigned.
|
23
|
+
attr_accessor :sitemap_route_name
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
# The route name of the sitemap without the namespace.
|
26
|
+
attr_accessor :sitemap_raw_route_name
|
30
27
|
|
31
|
-
|
32
|
-
|
28
|
+
# Identifies that the current sitemap route was defined with a block.
|
29
|
+
attr_accessor :sitemap_with_block
|
33
30
|
|
34
|
-
|
35
|
-
|
31
|
+
# Total amount of URL nodes allowed in the sitemap.
|
32
|
+
attr_accessor :url_limit
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
##################################################################################
|
35
|
+
# Returns a boolean indicating if the route is available for use.
|
36
|
+
# @return [FalseClass, TrueClass]
|
37
|
+
def available
|
38
|
+
unless defined?(@available)
|
39
|
+
@available = true
|
42
40
|
end
|
41
|
+
return @available
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
44
|
+
##################################################################################
|
45
|
+
# Sets a boolean indicating if the route is available for use.
|
46
|
+
# @param [FalseClass, TrueClass] value Boolean indicating if the route is available for use.
|
47
|
+
# @return [FalseClass, TrueClass]
|
48
|
+
def available=(value)
|
49
|
+
@available = value
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
52
|
+
##################################################################################
|
53
|
+
# Returns a boolean indicating if the route is available for use.
|
54
|
+
# @return [FalseClass, TrueClass]
|
55
|
+
def is_available?
|
56
|
+
return self.available
|
57
|
+
end
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
##################################################################################
|
60
|
+
# Identifies the current routes as being a sitemap route.
|
61
|
+
# @return [Boolean] True if the route is a sitemap route, otherwise, false.
|
62
|
+
def is_sitemap?
|
63
|
+
@is_sitemap = @is_sitemap.nil? ? false : @is_sitemap
|
64
|
+
end
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
##################################################################################
|
67
|
+
# @return [String] Namespace prefix used when creating the route.
|
68
|
+
def namespace_prefix
|
69
|
+
value = nil
|
64
70
|
|
65
|
-
|
71
|
+
unless self.sitemap_raw_route_name.blank?
|
72
|
+
value = self.sitemap_route_name.gsub(self.sitemap_raw_route_name, "")
|
66
73
|
end
|
67
74
|
|
68
|
-
|
69
|
-
|
70
|
-
# @return [Boolean] True if the route was defined with a block, otherwise, false.
|
71
|
-
def sitemap_with_block?
|
72
|
-
@sitemap_with_block = @sitemap_with_block.nil? ? false : @sitemap_with_block
|
73
|
-
end
|
75
|
+
return value
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
# @return [String] Name assigned to the route.
|
79
|
-
def route_name
|
80
|
-
return "#{self.name}"
|
81
|
-
end
|
78
|
+
##################################################################################
|
79
|
+
def namespace_prefix_underscores
|
80
|
+
value = 0
|
82
81
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
def controller_name
|
87
|
-
return self.requirements[:controller].blank? ? "" : self.requirements[:controller].to_s
|
82
|
+
buffer = self.namespace_prefix
|
83
|
+
unless buffer.blank?
|
84
|
+
value = buffer.split("_").length
|
88
85
|
end
|
89
86
|
|
90
|
-
|
91
|
-
|
92
|
-
# @return [String] Action name assigned to the route.
|
93
|
-
def action_name
|
94
|
-
return self.requirements[:action].blank? ? "" : self.requirements[:action].to_s
|
95
|
-
end
|
87
|
+
return value
|
88
|
+
end
|
96
89
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
90
|
+
##################################################################################
|
91
|
+
# Identifies that the current sitemap route was defined with a block.
|
92
|
+
# @return [Boolean] True if the route was defined with a block, otherwise, false.
|
93
|
+
def sitemap_with_block?
|
94
|
+
@sitemap_with_block = @sitemap_with_block.nil? ? false : @sitemap_with_block
|
95
|
+
end
|
104
96
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
#
|
113
|
-
# end
|
114
|
-
#
|
115
|
-
# produces url's like the following:
|
116
|
-
#
|
117
|
-
# <url>
|
118
|
-
# <loc>http://localhost:3000/trucks/1.html</loc>
|
119
|
-
# <lastmod>2011-10-13T06:16:24+00:00</lastmod>
|
120
|
-
# <changefreq>daily</changefreq>
|
121
|
-
# <priority>0.5</priority>
|
122
|
-
# </url>
|
123
|
-
#
|
124
|
-
# @return [String] Current value of changefreq.
|
125
|
-
def changefreq
|
126
|
-
return self.defaults[:changefreq]
|
127
|
-
end
|
97
|
+
##################################################################################
|
98
|
+
# Conveience method to return the name assigned to the route. There is no need for nil
|
99
|
+
# checking the return value of this method. It will simply return an empty String.
|
100
|
+
# @return [String] Name assigned to the route.
|
101
|
+
def route_name
|
102
|
+
return "#{self.name}"
|
103
|
+
end
|
128
104
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
# resources :trucks, :priority => "0.4"
|
136
|
-
#
|
137
|
-
# end
|
138
|
-
#
|
139
|
-
# produces url's like the following:
|
140
|
-
#
|
141
|
-
# <url>
|
142
|
-
# <loc>http://localhost:3000/trucks/1.html</loc>
|
143
|
-
# <lastmod>2011-10-13T06:16:24+00:00</lastmod>
|
144
|
-
# <changefreq>monthly</changefreq>
|
145
|
-
# <priority>0.4</priority>
|
146
|
-
# </url>
|
147
|
-
#
|
148
|
-
# @return [String] Current value of priority.
|
149
|
-
def priority
|
150
|
-
return self.defaults[:priority]
|
151
|
-
end
|
105
|
+
##################################################################################
|
106
|
+
# Returns the controller_name assigned to the route.
|
107
|
+
# @return [String] Controller_name name assigned to the route.
|
108
|
+
def controller_name
|
109
|
+
return self.requirements[:controller].blank? ? "" : self.requirements[:controller].to_s
|
110
|
+
end
|
152
111
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
#
|
160
|
-
# end
|
161
|
-
#
|
162
|
-
# produces url's like the following:
|
163
|
-
#
|
164
|
-
# <loc>http://localhost:3000/trucks/1.xml</loc>
|
165
|
-
# <loc>http://localhost:3000/trucks/2.xml</loc>
|
166
|
-
#
|
167
|
-
# @return [String]
|
168
|
-
def url_format
|
169
|
-
# a quick hack to default the extension for the root url to :none
|
170
|
-
return self.defaults[:url_format].blank? && self.route_name.eql?("root") ? :none : self.defaults[:url_format]
|
171
|
-
end
|
112
|
+
##################################################################################
|
113
|
+
# Returns the action assigned to the route.
|
114
|
+
# @return [String] Action name assigned to the route.
|
115
|
+
def action_name
|
116
|
+
return self.requirements[:action].blank? ? "" : self.requirements[:action].to_s
|
117
|
+
end
|
172
118
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
119
|
+
##################################################################################
|
120
|
+
# The class name (as a String) of a model to be used as the source of rows for a route
|
121
|
+
# when generating sitemap content.
|
122
|
+
# @return [String]
|
123
|
+
def model
|
124
|
+
return self.defaults[:model]
|
125
|
+
end
|
177
126
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
127
|
+
##################################################################################
|
128
|
+
# Setting changefreq directly on the route will override values set within a controller and model.
|
129
|
+
# This value will be used when generating a sitemap for the specific route.
|
130
|
+
#
|
131
|
+
# MyApp::Application.routes.draw do
|
132
|
+
#
|
133
|
+
# resources :trucks, :changefreq => "daily"
|
134
|
+
#
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# produces url's like the following:
|
138
|
+
#
|
139
|
+
# <url>
|
140
|
+
# <loc>http://localhost:3000/trucks/1.html</loc>
|
141
|
+
# <lastmod>2011-10-13T06:16:24+00:00</lastmod>
|
142
|
+
# <changefreq>daily</changefreq>
|
143
|
+
# <priority>0.5</priority>
|
144
|
+
# </url>
|
145
|
+
#
|
146
|
+
# @return [String] Current value of changefreq.
|
147
|
+
def changefreq
|
148
|
+
return self.defaults[:changefreq]
|
149
|
+
end
|
182
150
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
151
|
+
##################################################################################
|
152
|
+
# Setting priority directly on the route will override values set within a controller and model.
|
153
|
+
# This value will be used when generating a sitemap for the specific route.
|
154
|
+
#
|
155
|
+
# MyApp::Application.routes.draw do
|
156
|
+
#
|
157
|
+
# resources :trucks, :priority => "0.4"
|
158
|
+
#
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# produces url's like the following:
|
162
|
+
#
|
163
|
+
# <url>
|
164
|
+
# <loc>http://localhost:3000/trucks/1.html</loc>
|
165
|
+
# <lastmod>2011-10-13T06:16:24+00:00</lastmod>
|
166
|
+
# <changefreq>monthly</changefreq>
|
167
|
+
# <priority>0.4</priority>
|
168
|
+
# </url>
|
169
|
+
#
|
170
|
+
# @return [String] Current value of priority.
|
171
|
+
def priority
|
172
|
+
return self.defaults[:priority]
|
173
|
+
end
|
187
174
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
175
|
+
##################################################################################
|
176
|
+
# Specifies the extension that should be used when generating a url for the route within a sitemap.
|
177
|
+
#
|
178
|
+
# MyApp::Application.routes.draw do
|
179
|
+
#
|
180
|
+
# resources :trucks, :url_format => "xml"
|
181
|
+
#
|
182
|
+
# end
|
183
|
+
#
|
184
|
+
# produces url's like the following:
|
185
|
+
#
|
186
|
+
# <loc>http://localhost:3000/trucks/1.xml</loc>
|
187
|
+
# <loc>http://localhost:3000/trucks/2.xml</loc>
|
188
|
+
#
|
189
|
+
# @return [String]
|
190
|
+
def url_format
|
191
|
+
# a quick hack to default the extension for the root url to :none
|
192
|
+
return self.defaults[:url_format].blank? && self.route_name.eql?("root") ? :none : self.defaults[:url_format]
|
193
|
+
end
|
192
194
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
195
|
+
##################################################################################
|
196
|
+
def exclude_actions
|
197
|
+
return self.duckmap_defaults(:exclude_actions)
|
198
|
+
end
|
197
199
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
200
|
+
##################################################################################
|
201
|
+
def exclude_controllers
|
202
|
+
return self.duckmap_defaults(:exclude_controllers)
|
203
|
+
end
|
202
204
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
205
|
+
##################################################################################
|
206
|
+
def exclude_names
|
207
|
+
return self.duckmap_defaults(:exclude_names)
|
208
|
+
end
|
207
209
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
210
|
+
##################################################################################
|
211
|
+
def exclude_verbs
|
212
|
+
return self.duckmap_defaults(:exclude_verbs)
|
213
|
+
end
|
212
214
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
buffer = self.verb.to_s.downcase
|
218
|
-
if buffer.include?("delete")
|
219
|
-
value = :delete
|
215
|
+
##################################################################################
|
216
|
+
def include_actions
|
217
|
+
return self.duckmap_defaults(:include_actions)
|
218
|
+
end
|
220
219
|
|
221
|
-
|
222
|
-
|
220
|
+
##################################################################################
|
221
|
+
def include_controllers
|
222
|
+
return self.duckmap_defaults(:include_controllers)
|
223
|
+
end
|
223
224
|
|
224
|
-
|
225
|
-
|
225
|
+
##################################################################################
|
226
|
+
def include_names
|
227
|
+
return self.convert_to(self.duckmap_defaults(:include_names), :string)
|
228
|
+
end
|
226
229
|
|
227
|
-
|
228
|
-
|
230
|
+
##################################################################################
|
231
|
+
def include_verbs
|
232
|
+
return self.duckmap_defaults(:include_verbs)
|
233
|
+
end
|
229
234
|
|
230
|
-
|
235
|
+
##################################################################################
|
236
|
+
def verb_symbol
|
237
|
+
value = nil
|
238
|
+
unless self.verb.blank?
|
239
|
+
buffer = self.verb.to_s.downcase
|
240
|
+
if buffer.include?("delete")
|
241
|
+
value = :delete
|
231
242
|
|
232
|
-
|
233
|
-
|
234
|
-
end
|
243
|
+
elsif buffer.include?("get")
|
244
|
+
value = :get
|
235
245
|
|
236
|
-
|
237
|
-
|
238
|
-
# @return [Boolean] True if keys are required to generate a url, otherwise, false.
|
239
|
-
def keys_required?
|
240
|
-
keys = self.segment_keys.dup
|
241
|
-
keys.delete(:format)
|
242
|
-
return keys.length > 0 ? true : false
|
243
|
-
end
|
246
|
+
elsif buffer.include?("post")
|
247
|
+
value = :post
|
244
248
|
|
245
|
-
|
246
|
-
|
247
|
-
# If found:
|
248
|
-
# - determine the type of value:
|
249
|
-
# - If Array, return the array.
|
250
|
-
# - If String, create an array, add the String to it, and return the array.
|
251
|
-
# - If Symbol, create an array, add the Symbol to it, and return the array.
|
252
|
-
# If nothing found, return an empty array.
|
253
|
-
# returns [Array]
|
254
|
-
def duckmap_defaults(key)
|
255
|
-
values = []
|
249
|
+
elsif buffer.include?("put")
|
250
|
+
value = :put
|
256
251
|
|
257
|
-
|
258
|
-
if self.defaults[key].kind_of?(Array)
|
259
|
-
values = self.defaults[key]
|
252
|
+
end
|
260
253
|
|
261
|
-
|
262
|
-
|
254
|
+
end
|
255
|
+
return value
|
256
|
+
end
|
263
257
|
|
264
|
-
|
265
|
-
|
258
|
+
##################################################################################
|
259
|
+
# Indicates if the current route requirements segments keys to generate a url.
|
260
|
+
# @return [Boolean] True if keys are required to generate a url, otherwise, false.
|
261
|
+
def keys_required?
|
262
|
+
keys = self.segment_keys.dup
|
263
|
+
keys.delete(:format)
|
264
|
+
return keys.length > 0 ? true : false
|
265
|
+
end
|
266
266
|
|
267
|
-
|
268
|
-
|
267
|
+
##################################################################################
|
268
|
+
# Looks for a key within ActionDispatch::Routing::Route.defaults.
|
269
|
+
# If found:
|
270
|
+
# - determine the type of value:
|
271
|
+
# - If Array, return the array.
|
272
|
+
# - If String, create an array, add the String to it, and return the array.
|
273
|
+
# - If Symbol, create an array, add the Symbol to it, and return the array.
|
274
|
+
# If nothing found, return an empty array.
|
275
|
+
# returns [Array]
|
276
|
+
def duckmap_defaults(key)
|
277
|
+
values = []
|
278
|
+
|
279
|
+
if self.defaults && self.defaults[key]
|
280
|
+
if self.defaults[key].kind_of?(Array)
|
281
|
+
values = self.defaults[key]
|
282
|
+
|
283
|
+
elsif self.defaults[key].kind_of?(String)
|
284
|
+
values.push(self.defaults[key])
|
285
|
+
|
286
|
+
elsif self.defaults[key].kind_of?(Symbol)
|
287
|
+
values.push(self.defaults[key])
|
269
288
|
|
270
|
-
|
289
|
+
end
|
271
290
|
end
|
272
|
-
|
291
|
+
|
292
|
+
return values
|
293
|
+
end
|
273
294
|
|
274
295
|
end
|
275
296
|
end
|
data/lib/duck_map/route_set.rb
CHANGED
data/lib/duck_map/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duck_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|