deflectable 0.5.1 → 0.6.0

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: 360ccb8d8e116753a9a29d6b042137467d9e4fb8
4
- data.tar.gz: 369179b44205e1cbdbfeb93d6f35eadaa856d423
3
+ metadata.gz: 1e4716f5e2c86e3ce09ff3ad7900cb1e3b5aeb03
4
+ data.tar.gz: ed906c20acca45219ac490310119df32480061d7
5
5
  SHA512:
6
- metadata.gz: 7c96c23991ae7875dd6c33bb556dfdfdff524db693f0ec0d5384be4045756c6c9a0170b562f55a46ef9e8f25a559951464d4b56257f15b801a8b784d94dce5d4
7
- data.tar.gz: 074dea192fd5ef24eceb6d20017248c62534965be62b9616f8e3ecaa897e5e93ef8de7b7f38c0e760aef68bfab282eec3814a7a66d47f27114dc6b2e4f6a762d
6
+ metadata.gz: 0bd0aaf78c815ba922b3ce011853d9534511afe7cd4670da554fe8912e2b534caa8239e8a6ee30030734dd65da3fe5dc3daf825e429cc0031f4406fc4ccd9818
7
+ data.tar.gz: e586a7411d053dc91bbbcdd07e493cd18587b642181c870556116c4fbd59e8d5c0befaedf0393ed3df762998cb100b81d53e6de7aec306561f1f53eec32947aa
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  RailsアプリにIP制限 (ブラックリスト、ホワイトリスト)を適用
4
4
 
5
+ It is possible to add the ip limiting the rack app.
6
+
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
@@ -16,11 +19,13 @@ Or install it yourself as:
16
19
 
17
20
  $ gem install deflectable
18
21
 
19
- ## Usage
20
22
 
23
+ ## Usage
21
24
 
22
25
  ### Configure
23
26
 
27
+ #### Generator
28
+
24
29
  ```bash
25
30
  $ rails generate deflectable:install
26
31
  ```
@@ -29,22 +34,49 @@ Generated files
29
34
  * config/deflectable.yml
30
35
  * public/403.html
31
36
 
37
+
32
38
  #### deflectable.yml
33
39
 
34
40
  ```yaml
35
- # config/deflectable.yml
41
+ ### config/deflectable.yml
42
+
43
+ # default false
44
+ :log: true
36
45
 
37
- :log: true # default false
38
- :whitelist: # or :blacklist
46
+ # :whitelist or :blacklist
47
+ :whitelist:
39
48
  - 192.168.1.1
40
49
  - 10.20.30.0/24 # ip range
41
50
  - 3ffe:505:2::1 # IPv6 supported
51
+
52
+ # default: config/deflectable.yml (Rails.root)
53
+ :config_path: Rails.root.join('vendor/app/config/setting.yml')
42
54
  ```
43
55
 
56
+
44
57
  ### Modified config.ru
45
58
 
59
+ #### config.ru & deflectable.yml
60
+
46
61
  ```ruby
47
62
  # config.ru
48
63
 
49
64
  use Deflectable::Watcher
65
+
66
+ ```
67
+
68
+ #### Define the settings in the block (only config.ru)
69
+
70
+ deflectable.ymlを設置せずに、ブロックで定義することもできる。
71
+
72
+ Possible to omit the 'deflectable.yml'.
73
+
74
+ ```ruby
75
+ # config.ru
76
+
77
+ use Deflectable::Watcher do
78
+ { :log => true,
79
+ :whitelist => %w(192.168.1.1 10.20.30.0/24 3ffe:505:2::1)
80
+ }
81
+ end
50
82
  ```
@@ -1,7 +1,7 @@
1
1
  module Deflectable
2
2
  major = 0
3
- minore = 5
4
- patch = 1
3
+ minore = 6
4
+ patch = 0
5
5
 
6
6
  VERSION = [major, minore, patch].join('.')
7
7
  end
@@ -3,7 +3,7 @@ module Deflectable
3
3
  class Watcher
4
4
  attr_accessor :options
5
5
 
6
- def initialize(app, build_options = {})
6
+ def initialize(app, build_options={}, &block)
7
7
  @app = app
8
8
  @filtering = nil
9
9
  @options = {
@@ -13,7 +13,9 @@ module Deflectable
13
13
  :log_date_format => '%m/%d/%Y',
14
14
  :whitelist => [],
15
15
  :blacklist => [],
16
+ :config_path => nil,
16
17
  }.merge(build_options)
18
+ @options = @options.merge(block.call) if block_given?
17
19
  configure_check!
18
20
  end
19
21
 
@@ -27,7 +29,7 @@ module Deflectable
27
29
  private
28
30
 
29
31
  def configure_check!
30
- set_rails_configure!
32
+ load_config_file!
31
33
  if (not options[:whitelist].empty?) and (not options[:blacklist].empty?)
32
34
  raise <<-EOS
33
35
  There was both a :blanklist and :whitelist.
@@ -41,10 +43,15 @@ There was both a :blanklist and :whitelist.
41
43
  end
42
44
  end
43
45
 
44
- def set_rails_configure!
45
- return unless defined?(Rails)
46
- conf = YAML.load_file(Rails.root.join('config/deflectable.yml'))
47
- self.options = options.merge(conf).merge(:logger => Rails.logger)
46
+ def load_config_file!
47
+ if defined?(Rails)
48
+ file = options[:config_path] || Rails.root.join('config/deflectable.yml')
49
+ loaded_config = YAML.load_file(file) rescue {}
50
+ loaded_config = loaded_config.merge(:logger => Rails.logger)
51
+ else
52
+ loaded_config = YAML.load_file(options[:config_path]) rescue {}
53
+ end
54
+ self.options = options.merge(loaded_config)
48
55
  rescue => e
49
56
  log e.message
50
57
  end
@@ -3,3 +3,4 @@
3
3
  # - 192.168.1.1
4
4
  # - 10.20.30.0/24 # ip range
5
5
  # - 3ffe:505:2::1 # IPv6 supported
6
+ # :config_path: Rails.root.join('vendor/app/config/setting.yml') # default: config/deflectable.yml (Rails.root)
@@ -0,0 +1 @@
1
+ # Logfile created on 2013-09-28 16:30:31 +0900 by logger.rb/36483
@@ -106,3 +106,15 @@ Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-09-25 10:33:1
106
106
 
107
107
 
108
108
  Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-09-25 10:33:11 +0900
109
+
110
+
111
+ Started GET "/" for 127.0.0.1 at 2013-09-28 18:33:00 +0900
112
+ Processing by WelcomeController#index as HTML
113
+ Rendered welcome/index.html.erb within layouts/application (1.1ms)
114
+ Completed 200 OK in 52ms (Views: 51.3ms | ActiveRecord: 0.0ms)
115
+
116
+
117
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-09-28 18:33:00 +0900
118
+
119
+
120
+ Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-09-28 18:33:00 +0900
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deflectable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naohiro Sakuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-26 00:00:00.000000000 Z
11
+ date: 2013-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -133,6 +133,7 @@ files:
133
133
  - test/dummy/db/development.sqlite3
134
134
  - test/dummy/db/schema.rb
135
135
  - test/dummy/db/test.sqlite3
136
+ - test/dummy/deflecter.log
136
137
  - test/dummy/log/development.log
137
138
  - test/dummy/log/test.log
138
139
  - test/dummy/public/403.html
@@ -212,6 +213,7 @@ test_files:
212
213
  - test/dummy/db/development.sqlite3
213
214
  - test/dummy/db/schema.rb
214
215
  - test/dummy/db/test.sqlite3
216
+ - test/dummy/deflecter.log
215
217
  - test/dummy/log/development.log
216
218
  - test/dummy/log/test.log
217
219
  - test/dummy/public/403.html