surveillance_authority 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -105,7 +105,7 @@ Withing your plugin, you will be able to access your options simply by calling `
105
105
 
106
106
 
107
107
  class VarnishSweeper < SurveillanceAuthority::Sanctions
108
- default_config {:method => :purge}
108
+ default_config(:method => :purge)
109
109
 
110
110
  def sweep(url, options = {})
111
111
  options.reverse_merge(
@@ -142,10 +142,29 @@ If you want to access the config of other plugins, use:
142
142
 
143
143
  Note that you can easily provide default options for your plugin by calling `default_config` in your plugin file:
144
144
 
145
- default_config {:method => :purge}
145
+ default_config(:method => :purge)
146
146
 
147
147
  which comes in handy if some config options of your plugin do not need to be set by the users.
148
148
 
149
+ ### Configuration Validator
150
+
151
+ If your want to make sure that all configuration values of your plugin are valid, you can define a method called `validate_configuration` that does the necessary checks. It gets called after calling `default_config` and `config=` and should get called by methods that take in options that can overwrite the configuration. It should take care of the situation. If `validate_configuration` validates it should return the `@config` variable as its result gets returned when calling `config=`.
152
+
153
+ class VarnishSweeper < SurveillanceAuthority::Sanctions
154
+ default_config(:method => :purge)
155
+
156
+ def validate_configuration
157
+ # make sure the method option is either set to :purge or :header_invalidation
158
+ raise "invalid config" unless [:purge, :header_invalidation].include?( @config[:method] )
159
+ @config
160
+ end
161
+
162
+ def sweep(url, options = {})
163
+ options = validate_configuration( self.config.merge(options) )
164
+ ...
165
+ end
166
+ end
167
+
149
168
 
150
169
  Copyright
151
170
  ---------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -8,17 +8,23 @@ class SurveillanceAuthority
8
8
 
9
9
  def self.default_config(options = {})
10
10
  self.instance.config = options
11
+ self.instance.validate_configuration
11
12
  end
12
13
 
13
14
  def config=(options = {})
14
15
  @config ||= {}
15
16
  @config = @config.merge(options)
17
+ validate_configuration
16
18
  end
17
19
 
18
20
  def config
19
21
  @config ||= {}
20
22
  end
21
23
 
24
+ def validate_configuration
25
+ @config
26
+ end
27
+
22
28
  VALID_HOOKS = [:validation, :validation_on_create, :save, :create]
23
29
  @@plugins = []
24
30
 
@@ -3,6 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  class Notify < SurveillanceAuthority::Sanction
4
4
  default_config(:default_config => "I am a default option")
5
5
 
6
+ def validate_configuration
7
+ raise unless ["I am a default option", "I am not a default option"].include?( @config[:default_config] )
8
+ @config
9
+ end
10
+
6
11
  def my_config
7
12
  config
8
13
  end
@@ -41,6 +46,19 @@ describe "plugin configuration" do
41
46
  SurveillanceAuthority.config(Notify, :what => "ever")
42
47
  Notify.instance.config[:default_config].should == "I am a default option"
43
48
  end
49
+
50
+ it "should throw an exception if we pass in an invalid option through SurveillanceAuthority.config" do
51
+ lambda {
52
+ SurveillanceAuthority.config(Notify, :default_config => "ha ha -- I am full invalid dude")
53
+ }.should raise_error
54
+ end
55
+
56
+ it "should throw an exception if we pass in an invalid option through Plugin.config = " do
57
+ lambda {
58
+ Notify.config = {:default_config => "ho ho ho -- valid I am not"}
59
+ }.should raise_error
60
+ end
61
+
44
62
 
45
63
  # ALWAYS LAST:
46
64
  it "should be possible for plugins to overwrite default options" do
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{surveillance_authority}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Bornkessel"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Bornkessel
@@ -252,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
252
  requirements:
253
253
  - - ">="
254
254
  - !ruby/object:Gem::Version
255
- hash: -2654120252079229652
255
+ hash: -4373169688177034088
256
256
  segments:
257
257
  - 0
258
258
  version: "0"