duck_map 0.9.1 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86ec3b2f41916cd82223eef468e8f6427c6f58fc
4
- data.tar.gz: f5ca2a9974f3d7bfd16d3589c00e4956712b0b06
3
+ metadata.gz: 9540576082cb9cb20dd6d835390ad5a6cca063f1
4
+ data.tar.gz: 3153fb9d81fa3d651aadf987b7ec1cb6571e4c27
5
5
  SHA512:
6
- metadata.gz: d248d028bfc527ecc8a7da12deae494b05de4fe80bd5a27854aa1e5e4f9fa431133c79995563dee93380b7f312ab6bb5cd4ca661f7ff82f36069a2b2c3e95bc6
7
- data.tar.gz: 841e71bb490bf9b476e9ba04ad71be66a6dce110e3ed43688dfadb0c87d372df05857f470a2ab1b86a0df90c039e0805d80c45e967bd6a083230d9214be42695
6
+ metadata.gz: 4e569a54d332b30812e6cc55ce36a1f395fb9f97f414fb56d119b67566f519ffcc87f54420fed31e7271acd566d42baab40133ea4d0d416e4b1b03a64793aa69
7
+ data.tar.gz: b27d61b5c622da9ce98a0ba95769999a6bdc6fe7d95f111339a9c66d9b6e1e55f96c074250279f78b0d3865050a396f5173467b177e5c7230ecba6363a247e42
@@ -60,7 +60,9 @@ module DuckMap
60
60
  ActiveRecord::Base.send :include, InheritableClassAttributes
61
61
  ActiveRecord::Base.send :include, Attributes
62
62
  ActiveRecord::Base.send :include, SitemapObject
63
-
63
+ ActiveRecord::Relation.send :include, InheritableClassAttributes
64
+ ActiveRecord::Relation.send :include, Attributes
65
+ ActiveRecord::Relation.send :include, SitemapObject
64
66
  end
65
67
 
66
68
  ActiveSupport.on_load(:before_initialize) do
@@ -24,11 +24,30 @@ module DuckMap
24
24
  config = {controller: :sitemap, url_limit: nil}.merge(options)
25
25
 
26
26
  sitemap_raw_route_name = "#{name}_sitemap"
27
+ sitemap_route_name = name_for_action(sitemap_raw_route_name, nil)
27
28
 
28
29
  begin
29
30
 
30
- # create a route for the sitemap using the name that was passed to the sitemap method inside config/routes.
31
- match %(/#{name}.:format), controller: config[:controller], action: name, via: [:get], as: sitemap_raw_route_name
31
+ unless @set.routes.find {|route| route.name.eql?(sitemap_route_name)}
32
+
33
+ # create a route for the sitemap using the name that was passed to the sitemap method inside config/routes.
34
+ match %(/#{name}.:format), controller: config[:controller], action: name, via: [:get], as: sitemap_raw_route_name
35
+
36
+ # if not found here, then, there must be a real problem.
37
+ # later, i will implement an exception, etc.
38
+ sitemap_route = @set.routes.find {|route| route.name.eql?(sitemap_route_name)}
39
+
40
+ # identify the route as a "sitemap" route and build it's full name.
41
+ sitemap_route.is_sitemap = true
42
+ sitemap_route.url_limit = config[:url_limit]
43
+ sitemap_route.sitemap_route_name = sitemap_route_name
44
+ sitemap_route.sitemap_raw_route_name = sitemap_raw_route_name
45
+
46
+ # this is how I am faking to always point to the SitemapController
47
+ # regardless of namespace
48
+ sitemap_route.defaults[:controller] = "sitemap"
49
+
50
+ end
32
51
 
33
52
  rescue ArgumentError => e
34
53
  unless e.message.include?("Invalid route name")
@@ -36,36 +55,10 @@ module DuckMap
36
55
  end
37
56
  end
38
57
 
39
- # the current Rails implementation keeps the routes in an array. Also, it does nothing to prevent duplicate routes from being added.
40
- # at the time of development, the route is always at the end of the list, so, it is pretty safe to assume
41
- # the last route in the list is the sitemap route we just added.
42
-
43
- # last_route_name is used after we check to see if we just added a duplicate route.
44
- #last_route_name = @set.routes.last.route_name
45
- last_route_name = @set.routes.last.name
46
-
47
- # identify the route as a "sitemap" route and build it's full name.
48
- @set.routes.last.is_sitemap = true
49
- @set.routes.last.url_limit = config[:url_limit]
50
- @set.routes.last.sitemap_route_name = last_route_name
51
- @set.routes.last.sitemap_raw_route_name = sitemap_raw_route_name
52
-
53
- # this is how I am faking to always point to the SitemapController
54
- # regardless of namespace
55
- @set.routes.last.defaults[:controller] = "sitemap"
56
-
57
- # determine if we added a duplicate route.
58
- # The gem defines a default sitemap in config/routes.rb (inside the gem, not the app).
59
- # So, it is very likely that most apps will be creating duplicates since most of the code is geared towards
60
- # automagically configuring as much as possible.
61
- sitemap_routes = @set.routes.find_all {|route| route.is_sitemap? && route.name.eql?(last_route_name) }
62
-
63
- # if there are more than one routes with the same name, then, we must have added a duplicate. so, remove it.
64
- #@set.routes.pop if sitemap_routes.length > 1
65
- @set.routes.routes.pop if sitemap_routes.length > 1
66
-
67
- # now, find the route again.
68
- sitemap_route = @set.routes.find {|route| route.is_sitemap? && route.name.eql?(last_route_name) }
58
+ # now, find the route again, because, we need to set the following boolean and there might be several
59
+ # calls to sitemap without a block. if we were to set this boolean in the code above when checking
60
+ # if the route already exists, then, the boolean may never be set.
61
+ sitemap_route = @set.routes.find {|route| route.is_sitemap? && route.name.eql?(sitemap_route_name) }
69
62
 
70
63
  # once a sitemap route has been flagged as being defined with a block, then, you should never set it back to false.
71
64
  # one of the features is to be able to encapsulate a set of routes within a sitemap as many times as you need.
@@ -3,15 +3,11 @@ module DuckMap
3
3
 
4
4
  class MongoidEngine < Rails::Engine
5
5
 
6
- ActiveSupport.on_load(:active_record) do
6
+ Mongoid::Document.send :include, InheritableClassAttributes
7
+ Mongoid::Document.send :include, Attributes
8
+ Mongoid::Document.send :include, SitemapObject
7
9
 
8
- Mongoid::Document.send :include, InheritableClassAttributes
9
- Mongoid::Document.send :include, Attributes
10
- Mongoid::Document.send :include, SitemapObject
11
-
12
- Model::Supported.models.push(Mongoid::Document)
13
-
14
- end
10
+ Model::Supported.models.push(Mongoid::Document)
15
11
 
16
12
  end
17
13
 
@@ -1,3 +1,3 @@
1
1
  module DuckMap
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duck_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Duckett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails