duck_map 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,8 @@ module DuckMap
6
6
  ##################################################################################
7
7
  class FilterStack
8
8
 
9
- #DEFAULT_FILTER = {actions: [:new, :create, :edit, :update, :destroy],
10
- #verbs: [:post, :put, :delete], names: [], controllers: []}
11
- DEFAULT_FILTER = {actions: [:index, :show], verbs: [], names: [], controllers: []}
9
+ DEFAULT_FILTER = {exclude: {actions: [], controllers: [], names: [], verbs: [:delete, :post, :put]},
10
+ include: {actions: [:index, :show], controllers: [], names: [], verbs: []}}
12
11
 
13
12
  ##################################################################################
14
13
  def initialize
@@ -41,10 +40,16 @@ module DuckMap
41
40
  # Copies a filter
42
41
  # @return [Hash]
43
42
  def copy_filter(filter)
44
- buffer = {}
45
- filter.each do |part|
46
- buffer[part[0]] = part[1].dup
43
+ buffer = {exclude: {}, include: {}}
44
+
45
+ filter[:exclude].each do |part|
46
+ buffer[:exclude][part[0]] = part[1].dup
47
+ end
48
+
49
+ filter[:include].each do |part|
50
+ buffer[:include][part[0]] = part[1].dup
47
51
  end
52
+
48
53
  return buffer
49
54
  end
50
55
 
@@ -79,6 +84,37 @@ module DuckMap
79
84
  return nil
80
85
  end
81
86
 
87
+ ##################################################################################
88
+ # Clears all types (:actions, :verbs, :names, :controllers) for the {#current_filter}.
89
+ # @return [Nil]
90
+ def clear_filters
91
+ self.current_filter = {exclude: {actions: [], verbs: [], names: [], controllers: []},
92
+ include: {actions: [], verbs: [], names: [], controllers: []}}
93
+ return nil
94
+ end
95
+
96
+ ##################################################################################
97
+ # Clears a single type of filter.
98
+ # @param [Symbol] section The section of filter to update. :exclude or :include.
99
+ # @param [Symbol] key The key of filter to update. :actions, :verbs, :names, :controllers.
100
+ # @return [Nil]
101
+ def clear_filter(section, key)
102
+ key = key.kind_of?(Symbol) ? key : key.to_sym
103
+ self.current_filter[section][key] = []
104
+ return nil
105
+ end
106
+
107
+ ##################################################################################
108
+ # Removes value(s) from the {#current_filter}. Basically, the opposite of {#include_filter}.
109
+ # @overload exclude_filter(key, value)
110
+ # @param [Symbol, String] key The type of filter to update. :actions, :verbs, :names, :controllers.
111
+ # @param [String, Symbol, Array] value A single or Array of items to be added to the filter section specified via key.
112
+ # @return [NilClass]
113
+ def exclude_filter(*args)
114
+ args.insert(0, :exclude)
115
+ return update_filter(*args)
116
+ end
117
+
82
118
  ##################################################################################
83
119
  # Adds a value(s) to the {#current_filter}. The filter stack is implemented as an Array of Hashes.
84
120
  # The {#current_filter} will always be a Hash of key/value pairs. Each key represents a type of filter:
@@ -152,47 +188,28 @@ module DuckMap
152
188
  end
153
189
  end
154
190
 
155
- if action == :include
191
+ self.current_filter[action][key].concat(list)
192
+ self.current_filter[action][key].uniq!
156
193
 
157
- # now, simply concatenate the resulting list and make sure the final array is unique
158
- self.current_filter[key].concat(list)
159
- self.current_filter[key].uniq!
194
+ opposite_action = action.eql?(:exclude) ? :include : :exclude
160
195
 
161
- elsif action == :exclude
196
+ self.current_filter[action][key].each do |value|
197
+ #puts "action: #{action} key: #{key} value: #{value}"
198
+ self.current_filter[opposite_action][key].delete(value)
199
+ end
162
200
 
163
- self.current_filter[key].reject! {|item| list.include?(item)}
201
+ #if action == :include
164
202
 
165
- end
203
+ ## now, simply concatenate the resulting list and make sure the final array is unique
204
+ #self.current_filter[key].concat(list)
205
+ #self.current_filter[key].uniq!
166
206
 
167
- return nil
168
- end
207
+ #elsif action == :exclude
169
208
 
170
- ##################################################################################
171
- # Removes value(s) from the {#current_filter}. Basically, the opposite of {#include_filter}.
172
- # @overload exclude_filter(key, value)
173
- # @param [Symbol, String] key The type of filter to update. :actions, :verbs, :names, :controllers.
174
- # @param [String, Symbol, Array] value A single or Array of items to be added to the filter section specified via key.
175
- # @return [NilClass]
176
- def exclude_filter(*args)
177
- args.insert(0, :exclude)
178
- return update_filter(*args)
179
- end
209
+ #self.current_filter[key].reject! {|item| list.include?(item)}
180
210
 
181
- ##################################################################################
182
- # Clears all types (:actions, :verbs, :names, :controllers) for the {#current_filter}.
183
- # @return [Nil]
184
- def clear_filters
185
- self.current_filter = {actions: [], verbs: [], names: [], controllers: []}
186
- return nil
187
- end
211
+ #end
188
212
 
189
- ##################################################################################
190
- # Clears a single type of filter.
191
- # @param [Symbol, String] key The type of filter to update. :actions, :verbs, :names, :controllers.
192
- # @return [Nil]
193
- def clear_filter(key)
194
- key = key.kind_of?(Symbol) ? key : key.to_sym
195
- self.current_filter[key] = []
196
213
  return nil
197
214
  end
198
215
 
@@ -156,8 +156,8 @@ module DuckMap
156
156
  end
157
157
 
158
158
  ##################################################################################
159
- def clear_filter(key)
160
- @set.sitemap_filters.clear_filter(key)
159
+ def clear_filter(section, key)
160
+ @set.sitemap_filters.clear_filter(section, key)
161
161
  end
162
162
 
163
163
  ##################################################################################
@@ -1,10 +1,3 @@
1
- # the rule is the filter criteria acts as a list of things to include. period.
2
- # include methods will add to the list of criteria to include.
3
- # exclude methods will remove from the list of criteria to include.
4
- # for route level evaluations, the list of criteria to include is empty. therefore, meaning nothing is included.
5
- # the include attributes are added to the list of criteria to include, then, the exclude attributes are processed
6
- # to remove attributes from the list of criteria to include.
7
- # this will match the default behavior of nothing being included unless explicitly included.
8
1
  require 'active_support/concern'
9
2
 
10
3
  module DuckMap
@@ -90,19 +83,35 @@ module DuckMap
90
83
 
91
84
  end
92
85
 
93
- if match_any?(route.action_name, self.sitemap_filters.current_filter[:actions])
86
+ if match_any?(route.action_name, self.sitemap_filters.current_filter[:exclude][:actions])
87
+ raise ExplicitExclude, "exclude"
88
+ end
89
+
90
+ if match_any?(route.verb_symbol, self.sitemap_filters.current_filter[:exclude][:verbs])
91
+ raise ExplicitExclude, "exclude"
92
+ end
93
+
94
+ if match_any?(route.controller_name, self.sitemap_filters.current_filter[:exclude][:controllers])
95
+ raise ExplicitExclude, "exclude"
96
+ end
97
+
98
+ if match_any?(route.name, self.sitemap_filters.current_filter[:exclude][:names])
99
+ raise ExplicitExclude, "exclude"
100
+ end
101
+
102
+ if match_any?(route.action_name, self.sitemap_filters.current_filter[:include][:actions])
94
103
  raise ExplicitInclude, "include"
95
104
  end
96
105
 
97
- if match_any?(route.verb_symbol, self.sitemap_filters.current_filter[:verbs])
106
+ if match_any?(route.verb_symbol, self.sitemap_filters.current_filter[:include][:verbs])
98
107
  raise ExplicitInclude, "include"
99
108
  end
100
109
 
101
- if match_any?(route.controller_name, self.sitemap_filters.current_filter[:controllers])
110
+ if match_any?(route.controller_name, self.sitemap_filters.current_filter[:include][:controllers])
102
111
  raise ExplicitInclude, "include"
103
112
  end
104
113
 
105
- if match_any?(route.name, self.sitemap_filters.current_filter[:names])
114
+ if match_any?(route.name, self.sitemap_filters.current_filter[:include][:names])
106
115
  raise ExplicitInclude, "include"
107
116
  end
108
117
 
@@ -122,6 +131,9 @@ module DuckMap
122
131
  DuckMap.logger.debug %(#{"Duckmap Include".rjust(30)} -> #{e})
123
132
  value = true
124
133
 
134
+ rescue ExplicitExclude => e
135
+ DuckMap.logger.debug %(#{"Explicit Exclude".rjust(30)} -> #{e})
136
+
125
137
  rescue ExplicitInclude => e
126
138
  DuckMap.logger.debug %(#{"Explicit Include".rjust(30)} -> #{e})
127
139
  value = true
@@ -1,3 +1,3 @@
1
1
  module DuckMap
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
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.3
4
+ version: 0.8.4
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-24 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline