uri_config 0.0.1 → 0.0.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTA1OWY5MzFkN2I5NDE0N2MxMmZiOTViMDk0NWE4NzJhMWViMzg0OA==
4
+ ZTUwM2NmYmNlY2QxZjJlMmZmYzI0NzNlYzJlYWU2M2Q3ODEzNWU2Ng==
5
5
  data.tar.gz: !binary |-
6
- NzU1ODlkYWRlODI3ZDAyYTY4MzViYmY3MmZlNzY1MmE3MGU3NWNiZQ==
6
+ MWViMjlmYmZiZjE5ZmVlODgwYTZkYTY3ZjA0MWUxMjBmYzRjZTQ2NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTIwNTgzOWYzNjE5MzZlNDAzZWJmZGZmZGVmOTNkNGMwNzUxMjQ5OTNlNmUy
10
- YTdjZmM5MzM2MDhlZThkY2U5MmJiMDlkMGMwMDUyZjFmZTlmMmNiYjkyNjVh
11
- YmQ5ODYxNWY3ODIzMmZlNTRlMmQ4NWE0YzUxYmEwMzk3MDAxYWU=
9
+ ZjhlNmUyNzk1Mzg1ODY2ZDM3NzUxMzc1ZDZkMzczNWFjMGIxOWJmMzIwNzM5
10
+ OWZiYWYxOWU0NTNiM2IwMWE1MzFkOWUwYmRhMjIzYThmODhkOTdmMmQ0MmZj
11
+ Y2Y2ZGExZjU4ZWIzMWQ5ZDc1YmE1ZTg2OWUzYzFjMWViNzE4MDI=
12
12
  data.tar.gz: !binary |-
13
- ODNjYzEzMDViYjM3ODI4ZjEwOWY2N2RlZmYwNGFjZTQ4Y2U4Njc1NzBkMzEy
14
- MWY5YTE1MmJkMGMzYzhjMGQyY2U4MWU2OTE2YTgyN2IzODU3NDg1MjU3NDMw
15
- YmVhMzViZDRkOWYwMTY5NzhlODAxNGQ0NDczOTZjMGQ3M2RjZTc=
13
+ NTEzZmFiMGY0ZTdiNzgyN2RlM2FmNTVkYzg1ZTRmN2FmNDE2ODhkMjYyNzQy
14
+ MWU5M2ZmNTAxMGQyY2RiMDRkOGNlOTE2MTdkNmZmZWI1ZTY3ZjVkZTg2NGFm
15
+ MTE3MzE4MzI2MzViYzFhN2E3ZmE1YjU4ZjZlMmFkZjIwNDIyM2Q=
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  Metrics/LineLength:
2
- Max: 120
2
+ Max: 160
3
3
 
4
4
  Style/Documentation:
5
5
  Enabled: false
data/README.md CHANGED
@@ -25,34 +25,34 @@ Or install it yourself as:
25
25
  Extract credentials from generic URIs:
26
26
 
27
27
  ```ruby
28
- config = URIConfig::Config.new("https://my_user:my_pass@s3.amazonaws.com/a_path")
28
+ config = URIConfig::Config.new("https://my_user:my_pass@s3.amazonaws.com/a_path")
29
29
 
30
- config.username # => "my_user"
31
- config.password # => "my_password"
32
- config.path # => "/bucket_name"
30
+ config.username # => "my_user"
31
+ config.password # => "my_password"
32
+ config.path # => "/bucket_name"
33
33
  ```
34
34
 
35
35
  Build wrapper classes for more specific configuration hashes:
36
36
 
37
37
  ```ruby
38
- class S3Config < Config
39
- alias_method :access_key_id, :username
40
- alias_method :secret_access_key, :password
38
+ class S3Config < Config
39
+ alias_method :access_key_id, :username
40
+ alias_method :secret_access_key, :password
41
41
 
42
- def bucket
43
- path[1..-1]
44
- end
45
-
46
- config :access_key_id, :secret_access_key, :bucket
42
+ def bucket
43
+ path[1..-1]
47
44
  end
48
45
 
49
- config = S3Config.new("https://AKIAJUSERNAME:abcd12345678@s3.amazonaws.com/bucket_name")
46
+ config :access_key_id, :secret_access_key, :bucket
47
+ end
48
+
49
+ config = S3Config.new("https://AKIAJUSERNAME:abcd12345678@s3.amazonaws.com/bucket_name")
50
50
 
51
- config.access_key_id # => "AKIAJUSERNAME"
52
- config.secret_access_key # => "abcd12345678"
53
- config.bucket # => "bucket_name"
51
+ config.access_key_id # => "AKIAJUSERNAME"
52
+ config.secret_access_key # => "abcd12345678"
53
+ config.bucket # => "bucket_name"
54
54
 
55
- config.config # => {access_key_id: "AKIAJUSERNAME, secret_access_key: "abcd12345678", bucket: "bucket_name" }
55
+ config.config # => {access_key_id: "AKIAJUSERNAME, secret_access_key: "abcd12345678", bucket: "bucket_name" }
56
56
  ```
57
57
 
58
58
  ## Contributing
@@ -0,0 +1,25 @@
1
+ require 'uri_config'
2
+
3
+ module URIConfig
4
+ class ActionMailerConfig < URIConfig::Config
5
+ map :address, from: :host
6
+ map :user_name, from: :username
7
+
8
+ parameter :authentication
9
+ parameter :domain
10
+
11
+ def enable_starttls_auto
12
+ uri.scheme == "smtps"
13
+ end
14
+
15
+ config(
16
+ :address,
17
+ :port,
18
+ :enable_starttls_auto,
19
+ :user_name,
20
+ :password,
21
+ :authentication,
22
+ :domain,
23
+ )
24
+ end
25
+ end
@@ -7,6 +7,16 @@ module URIConfig
7
7
  @url = url
8
8
  end
9
9
 
10
+ def self.map(key, options = {})
11
+ alias_method key, options.fetch(:from)
12
+ end
13
+
14
+ def self.parameter(method, query_parameter = method)
15
+ define_method(method) do
16
+ query[query_parameter.to_s].first
17
+ end
18
+ end
19
+
10
20
  def username
11
21
  CGI.unescape uri.user
12
22
  end
@@ -15,6 +25,14 @@ module URIConfig
15
25
  CGI.unescape uri.password
16
26
  end
17
27
 
28
+ def host
29
+ uri.host
30
+ end
31
+
32
+ def port
33
+ uri.port
34
+ end
35
+
18
36
  def path
19
37
  uri.path
20
38
  end
@@ -1,3 +1,3 @@
1
1
  module URIConfig
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require 'uri_config/action_mailer_config'
2
+
3
+ module URIConfig
4
+ describe ActionMailerConfig do
5
+ subject { described_class.new(url) }
6
+
7
+ {
8
+ "smtps://MANDRILL_USERNAME:MANDRILL_PASSWORD@smtp.mandrillapp.com:25/?authentication=login&domain=yourdomain.com" => {
9
+ address: "smtp.mandrillapp.com",
10
+ port: 25,
11
+ enable_starttls_auto: true,
12
+ user_name: "MANDRILL_USERNAME",
13
+ password: "MANDRILL_PASSWORD",
14
+ authentication: 'login',
15
+ domain: 'yourdomain.com',
16
+ },
17
+ "smtp://MANDRILL_USERNAME:MANDRILL_PASSWORD@smtp.mandrillapp.com:2525/?authentication=plain&domain=yourdomain.com" => {
18
+ address: "smtp.mandrillapp.com",
19
+ port: 2525,
20
+ enable_starttls_auto: false,
21
+ user_name: "MANDRILL_USERNAME",
22
+ password: "MANDRILL_PASSWORD",
23
+ authentication: 'plain',
24
+ domain: 'yourdomain.com',
25
+ },
26
+ }.each do |url, components|
27
+ context "with a URL of #{url}" do
28
+ let(:url) { url }
29
+
30
+ components.each do |key, value|
31
+ it "has a #{key} of #{value}" do
32
+ expect(subject.send(key)).to eq value
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
data/spec/config_spec.rb CHANGED
@@ -20,6 +20,10 @@ module URIConfig
20
20
  password: "7d123FASD123sljnfdsaSADFasdfhsdf12ddFDH4",
21
21
  path: "/bucket_name",
22
22
  },
23
+ "https://example.com:8080" => {
24
+ host: "example.com",
25
+ port: 8080,
26
+ },
23
27
  }.each do |url, components|
24
28
  context "with a URL of #{url}" do
25
29
  let(:url) { url }
@@ -1,7 +1,9 @@
1
+ require 'uri_config'
2
+
1
3
  module URIConfig
2
4
  class S3Config < Config
3
- alias_method :access_key_id, :username
4
- alias_method :secret_access_key, :password
5
+ map :access_key_id, from: :username
6
+ map :secret_access_key, from: :password
5
7
 
6
8
  def bucket
7
9
  path[1..-1]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathon M. Abbott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,8 +82,10 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - lib/uri_config.rb
85
+ - lib/uri_config/action_mailer_config.rb
85
86
  - lib/uri_config/config.rb
86
87
  - lib/uri_config/version.rb
88
+ - spec/action_mailer_config_spec.rb
87
89
  - spec/config_spec.rb
88
90
  - spec/s3_config_spec.rb
89
91
  - uri_config.gemspec
@@ -112,5 +114,7 @@ signing_key:
112
114
  specification_version: 4
113
115
  summary: extract configuration from URIs
114
116
  test_files:
117
+ - spec/action_mailer_config_spec.rb
115
118
  - spec/config_spec.rb
116
119
  - spec/s3_config_spec.rb
120
+ has_rdoc: