surveillance_authority 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -103,9 +103,10 @@ Withing your plugin, you will be able to access your options simply by calling `
103
103
 
104
104
  #### Example: `VarnishSweep` needs to be configured with a base url to varnish
105
105
 
106
- <code>
107
106
 
108
107
  class VarnishSweeper < SurveillanceAuthority::Sanctions
108
+ default_config {:method => :purge}
109
+
109
110
  def sweep(url, options = {})
110
111
  options.reverse_merge(
111
112
  :method => :invalidate
@@ -128,21 +129,22 @@ Withing your plugin, you will be able to access your options simply by calling `
128
129
  end
129
130
  end
130
131
 
131
- </code>
132
132
 
133
133
  In the project using this plugin:
134
134
 
135
- <code>
136
135
 
137
136
  SurveillanceAuthority.config(VarnishSweeper, :base_url => "http://varnish.example.com")
138
-
139
137
  ...
140
- </code>
141
138
 
142
139
  If you want to access the config of other plugins, use:
143
140
 
144
141
  `SurveillanceAuthority.config_for(<plugin>)`
145
142
 
143
+ Note that you can easily provide default options for your plugin by calling `default_config` in your plugin file:
144
+
145
+ default_config {:method => :purge}
146
+
147
+ which comes in handy if some config options of your plugin do not need to be set by the users.
146
148
 
147
149
 
148
150
  Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -4,9 +4,21 @@ require 'singleton'
4
4
  class SurveillanceAuthority
5
5
 
6
6
  class Sanction
7
- attr_accessor :config
8
7
  include Singleton
9
8
 
9
+ def self.default_config(options = {})
10
+ self.instance.config = options
11
+ end
12
+
13
+ def config=(options = {})
14
+ @config ||= {}
15
+ @config = @config.merge(options)
16
+ end
17
+
18
+ def config
19
+ @config ||= {}
20
+ end
21
+
10
22
  VALID_HOOKS = [:validation, :validation_on_create, :save, :create]
11
23
  @@plugins = []
12
24
 
@@ -1,6 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  class Notify < SurveillanceAuthority::Sanction
4
+ default_config(:default_config => "I am a default option")
5
+
4
6
  def my_config
5
7
  config
6
8
  end
@@ -16,18 +18,34 @@ describe "plugin configuration" do
16
18
  it "should be possible to configure plugins with the SurveillanceAuthority.config method" do
17
19
  SurveillanceAuthority.config(Notify, :option1 => true)
18
20
 
19
- Notify.instance.config.should == {:option1 => true}
21
+ Notify.instance.config[:option1].should == true
20
22
  end
21
23
 
22
24
  it "configuration should be accessible within the plugin" do
23
25
  SurveillanceAuthority.config(Notify, :option2 => true)
24
26
 
25
- Notify.instance.my_config.should == {:option2 => true}
27
+ Notify.instance.my_config[:option2].should == true
26
28
  end
27
29
 
28
30
  it "should be possible to configure plugins with the SurveillanceAuthority.config method and retrieve this config with SurveillanceAuthority::config_for" do
29
31
  SurveillanceAuthority.config(Notify, :option3 => true)
30
32
 
31
- SurveillanceAuthority.config_for(Notify).should == {:option3 => true}
33
+ SurveillanceAuthority.config_for(Notify)[:option3].should == true
34
+ end
35
+
36
+ it "should be possible for plugins to have default options" do
37
+ Notify.instance.config[:default_config].should == "I am a default option"
38
+ end
39
+
40
+ it "should not delete default config if user sets some config options" do
41
+ SurveillanceAuthority.config(Notify, :what => "ever")
42
+ Notify.instance.config[:default_config].should == "I am a default option"
43
+ end
44
+
45
+ # ALWAYS LAST:
46
+ it "should be possible for plugins to overwrite default options" do
47
+ SurveillanceAuthority.config(Notify, :default_config => "I am not a default option")
48
+ Notify.instance.config[:default_config].should == "I am not a default option"
32
49
  end
50
+
33
51
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{surveillance_authority}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.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"]
12
- s.date = %q{2010-10-20}
12
+ s.date = %q{2010-10-25}
13
13
  s.description = %q{Write centralized model observers in a simple DSL}
14
14
  s.email = %q{github@bornkessel.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Bornkessel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-20 00:00:00 +02:00
17
+ date: 2010-10-25 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -252,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
252
  requirements:
253
253
  - - ">="
254
254
  - !ruby/object:Gem::Version
255
- hash: 1608769546526049591
255
+ hash: -2654120252079229652
256
256
  segments:
257
257
  - 0
258
258
  version: "0"