crusade 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7c9ad5a87057eb2d7f67cf5f7b8678781957c45
4
+ data.tar.gz: 52767d108623c74a0e39f0a2e241041dfabb4278
5
+ SHA512:
6
+ metadata.gz: ba9d3401ce6992572c5fe4ae464614926cce9c51097eeea67c0660bbd591f78b091a8ced2890b2e3355c63ece5a9ee5907f3448793a3bd2931b90e0d8d21c037
7
+ data.tar.gz: e65bb8f57d097a97c1870df8a28de1e0d3bf518113603321884e971f5d0b9072346fd1fe4770599c0dcb42595d6fa116b80dbe60e7be8361c19385d88e9ac64f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crusade (0.7.1)
4
+ crusade (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,63 @@
1
+ require "crusade/logger"
2
+ require 'yaml'
3
+
4
+ module Crusade
5
+
6
+ def self.config
7
+ c = Configuration.new
8
+ yield c if block_given?
9
+ c
10
+ end
11
+
12
+ class Configuration
13
+ attr_reader :plugins, :env
14
+
15
+ def initialize
16
+ @plugins = {}
17
+ @env = 'development'
18
+ end
19
+
20
+ def logger= logger
21
+ Crusade::Logger.logger = logger
22
+ end
23
+
24
+ def plugins= plugins
25
+ @plugins = plugins
26
+ plugins.each do |plugin_name, _|
27
+ register_plugin plugin_name
28
+ end
29
+ end
30
+
31
+ def env= env
32
+ @env = env
33
+ self.plugins = plugins
34
+ end
35
+
36
+ private
37
+
38
+ def register_plugin plugin
39
+ self.class.send(:attr_accessor, plugin)
40
+ config = load_plugin_configuration plugin
41
+ self.send("#{plugin}=", configuration_class_for(plugin).new(config))
42
+ end
43
+
44
+ def load_plugin_configuration plugin
45
+ yaml = load_yaml plugins[plugin]
46
+ symbolize_keys yaml[env.to_s]
47
+ end
48
+
49
+ def configuration_class_for plugin
50
+ Crusade.const_get(plugin.upcase).const_get('Configuration')
51
+ end
52
+
53
+ def symbolize_keys h
54
+ h.inject({}) do |memo, (k,v) |
55
+ memo.update k.to_sym => v
56
+ end
57
+ end
58
+
59
+ def load_yaml config_file
60
+ YAML.load_file config_file
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module Crusade
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -0,0 +1,23 @@
1
+ default: &default
2
+ site_name: Apns config fixture
3
+ push_id: web.com.example.push.id
4
+ iconset_dir: lib/icon.iconset
5
+ certificate: config/certificate.p12
6
+ certificate_password: test
7
+
8
+ development:
9
+ <<: *default
10
+ url_format: http://www.example.com/push/%@
11
+ webservice_url: https://www.example.com/push
12
+ allowed_domains:
13
+ - http://www.example.com
14
+ - https://www.example.com
15
+
16
+ test:
17
+ <<: *default
18
+ url_format: http://localhost/push/%@
19
+ webservice_url: https://localhost/push
20
+ allowed_domains:
21
+ - http://localhost
22
+ - https://localhost
23
+ certificate_password:
@@ -0,0 +1,78 @@
1
+ require File.expand_path '../../test_helper.rb', __FILE__
2
+
3
+ require 'crusade/configuration'
4
+ require 'ostruct'
5
+
6
+ module Crusade::APNS
7
+ class Configuration < OpenStruct
8
+ end
9
+ end
10
+
11
+ describe Crusade do
12
+
13
+ describe 'config' do
14
+ let(:logger) { 'logger' }
15
+ let(:logger_level) { 'level' }
16
+ let(:config_file) { 'test/fixtures/config.yml' }
17
+
18
+ let(:config) do
19
+ Crusade.config do |config|
20
+ config.logger = logger
21
+ config.env = 'development'
22
+ config.plugins = { apns: config_file }
23
+ end
24
+ end
25
+
26
+ before { config }
27
+
28
+ it 'sets the crusade logger' do
29
+ Crusade::Logger.logger.must_be_same_as logger
30
+ end
31
+
32
+ describe 'plugins' do
33
+ it 'sets the plugins attribute' do
34
+ config.plugins.must_equal({ apns: config_file })
35
+ end
36
+
37
+ it 'sets a config namespaces based on the plugin name' do
38
+ config.apns.wont_be_nil
39
+ end
40
+
41
+ it 'sets a configuration class based on the plugin name' do
42
+ config.apns.is_a?(Crusade::APNS::Configuration).must_be_true
43
+ end
44
+
45
+ it 'loads the configuration' do
46
+ config.apns.webservice_url.must_equal 'https://www.example.com/push'
47
+ end
48
+ end
49
+
50
+ describe 'no block' do
51
+ let(:config) { Crusade.config }
52
+
53
+ it 'builds a minimum configuration' do
54
+ config.is_a?(Crusade::Configuration).must_be_true
55
+ end
56
+
57
+ it 'sets no plugin' do
58
+ config.plugins.must_equal({})
59
+ end
60
+
61
+ it 'sets the env to development' do
62
+ config.env.must_equal 'development'
63
+ end
64
+ end
65
+
66
+ describe 'env' do
67
+ before { config.env = 'test' }
68
+
69
+ it 'sets the value' do
70
+ config.env.must_equal 'test'
71
+ end
72
+
73
+ it 'reloads the plugins' do
74
+ config.apns.webservice_url.must_equal 'https://localhost/push'
75
+ end
76
+ end
77
+ end
78
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crusade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
5
- prerelease:
4
+ version: 0.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Rouchy
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,23 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: minitest-great_expectations
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,33 +69,29 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: coveralls
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: push notification gem
@@ -123,46 +110,44 @@ files:
123
110
  - Rakefile
124
111
  - crusade.gemspec
125
112
  - lib/crusade.rb
113
+ - lib/crusade/configuration.rb
126
114
  - lib/crusade/logger.rb
127
115
  - lib/crusade/null_logger.rb
128
116
  - lib/crusade/version.rb
117
+ - test/fixtures/config.yml
129
118
  - test/support/fake_logger.rb
130
119
  - test/test_helper.rb
120
+ - test/unit/configuration_test.rb
131
121
  - test/unit/logger_test.rb
132
122
  - test/unit/null_logger_test.rb
133
123
  homepage: ''
134
124
  licenses:
135
125
  - MIT
126
+ metadata: {}
136
127
  post_install_message:
137
128
  rdoc_options: []
138
129
  require_paths:
139
130
  - lib
140
131
  required_ruby_version: !ruby/object:Gem::Requirement
141
- none: false
142
132
  requirements:
143
- - - ! '>='
133
+ - - '>='
144
134
  - !ruby/object:Gem::Version
145
135
  version: '0'
146
- segments:
147
- - 0
148
- hash: -945907368432889373
149
136
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
137
  requirements:
152
- - - ! '>='
138
+ - - '>='
153
139
  - !ruby/object:Gem::Version
154
140
  version: '0'
155
- segments:
156
- - 0
157
- hash: -945907368432889373
158
141
  requirements: []
159
142
  rubyforge_project:
160
- rubygems_version: 1.8.23
143
+ rubygems_version: 2.0.3
161
144
  signing_key:
162
- specification_version: 3
145
+ specification_version: 4
163
146
  summary: push some notification through APNS
164
147
  test_files:
148
+ - test/fixtures/config.yml
165
149
  - test/support/fake_logger.rb
166
150
  - test/test_helper.rb
151
+ - test/unit/configuration_test.rb
167
152
  - test/unit/logger_test.rb
168
153
  - test/unit/null_logger_test.rb