mayaml 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b20c8481f6bb916404aab132bf34cba05b8c4bb
4
- data.tar.gz: 03289891d912af7a59b092308f71d1b5a4731b97
3
+ metadata.gz: 3a1938719052779c534faa1c12f6e740fca2178f
4
+ data.tar.gz: ef1d8942558d64c0f7c528427ba4e20bf3fff26e
5
5
  SHA512:
6
- metadata.gz: d1c8673f2972f336871f1833adf1dc24ec88291a312b9d9ad0edf4378edfb21317bad073f94483beaf8d4fc395c696271688e023a7acb3dbfc0db8be2ff86ceb
7
- data.tar.gz: 9b19993fd6331be4bab4e3b4f3295745b4fb4ab8ced5c1e37ade1eff5b0477fb7948a1f9e1fa9a65d22babf8d296df0750566aa6e72a49b819bf6b2cf17a3ef5
6
+ metadata.gz: 6f307cd6cf40c3f33a2bf47b6d0e12c1da97e16dd4ebb9a336cc2c4c5807f3bd7f34eb5c77e38b9d0bbf0b47e2b4d5a9cb79779788400b7c441c56fe18852f4a
7
+ data.tar.gz: 0aff4a69ec54e872f932ca5d83c0afde656ae7c9e46748769fd3df770b6358ae937612f6670c24abb27b2ed4f296eefeb25094d30613a67c417761ea6e844b85
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ === 2.0.0 (2016.08.31)
2
+
3
+ * add new attributes to the mail_account format: `default` and `realname`
4
+ * now only `mailboxes` and `default` attributes are optional
5
+ * add travis integration
6
+
1
7
  === 1.0.3 (2016.06.24)
2
8
 
3
9
  * fix bin script
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # MAYaml
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/mayaml.svg)](http://badge.fury.io/rb/mayaml)
4
+ [![Code Climate](https://codeclimate.com/github/skopciewski/mayaml/badges/gpa.svg)](https://codeclimate.com/github/skopciewski/mayaml)
4
5
 
5
6
  This is a base package for mail accounts configuration generators. The idea is to store mail accounts configuration in one Yaml file and then generates dedicated configs for specific programs (like getmail, mutt, etc...).
6
7
 
@@ -20,7 +21,7 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- If ruby bin dir is in your PATH, just call `mayaml-check <path_to_the_yaml_file>` to list recognized accounts.
24
+ If ruby bin dir is in your PATH, just call `mayaml-check <path_to_the_yaml_file>` to list recognized accounts.
24
25
  On the other hand, In plugins:
25
26
 
26
27
  ```ruby
@@ -33,15 +34,32 @@ Mayaml.accounts_from_file(yaml_path).each { |account| ... }
33
34
 
34
35
  ```yaml
35
36
  - name: account_name
37
+ default: false
38
+ realname: Jon Foo
36
39
  type: imap
37
40
  server: test.mailserver.com
38
41
  port: 998
39
42
  user: user@mailserver.com
40
43
  pass: sercet_password
41
44
  mailboxes:
42
- - INBOX
45
+ - INBOX
43
46
  ```
44
47
 
48
+ #### Required attributes
49
+
50
+ * `name`
51
+ * `type`
52
+ * `server`
53
+ * `port`
54
+ * `user`
55
+ * `pass`
56
+ * `realname`
57
+
58
+ #### Default attributes
59
+
60
+ * `mailboxes` => `[]`
61
+ * `default` => `false`
62
+
45
63
  ## Versioning
46
64
 
47
65
  See [semver.org][semver]
data/lib/mayaml.rb CHANGED
@@ -32,6 +32,8 @@ module Mayaml
32
32
  def self.build_account(raw_account)
33
33
  MailAccount::Builder.build do |builder|
34
34
  builder.name raw_account.fetch("name")
35
+ builder.default raw_account.fetch("default", "false")
36
+ builder.realname raw_account.fetch("realname")
35
37
  builder.type raw_account.fetch("type")
36
38
  builder.server raw_account.fetch("server")
37
39
  builder.port raw_account.fetch("port")
@@ -19,20 +19,15 @@
19
19
 
20
20
  module Mayaml
21
21
  class MailAccount
22
- attr_accessor :name, :type, :server, :port, :user, :pass, :mailboxes
22
+ attr_accessor :name, :default, :realname, :type, :server, :port, :user, :pass, :mailboxes
23
23
 
24
24
  def initialize
25
- set_default_type
26
- set_default_port
25
+ set_default_flag
27
26
  set_default_mailboxes
28
27
  end
29
28
 
30
- def set_default_type
31
- @type = :imap
32
- end
33
-
34
- def set_default_port
35
- @port = 993
29
+ def set_default_flag
30
+ @default = false
36
31
  end
37
32
 
38
33
  def set_default_mailboxes
@@ -40,8 +35,9 @@ module Mayaml
40
35
  end
41
36
 
42
37
  def to_str
38
+ default_mark = @default ? "*" : ""
43
39
  <<-DESC
44
- Account: #{@name} | user: #{@user}:#{@pass}
40
+ Account#{default_mark}: #{@name}<#{@realname}> | user: #{@user}:#{@pass}
45
41
  #{@type} - #{@server}:#{@port} [#{@mailboxes.join(",")}]
46
42
  DESC
47
43
  end
@@ -22,6 +22,7 @@ require "mayaml/mail_account/required_attributes_validator"
22
22
  require "mayaml/mail_account/type_validator"
23
23
  require "mayaml/mail_account/port_validator"
24
24
  require "mayaml/mail_account/mailboxes_validator"
25
+ require "mayaml/mail_account/default_flag_validator"
25
26
 
26
27
  module Mayaml
27
28
  class MailAccount
@@ -40,32 +41,31 @@ module Mayaml
40
41
  @account.name = name
41
42
  end
42
43
 
43
- def type(str)
44
- if str.nil? || str == ""
45
- @account.set_default_type
44
+ def default(flag)
45
+ if flag.nil? || flag == ""
46
+ @account.set_default_flag
46
47
  else
47
- validator = TypeValidator.new str
48
- unless validator.valid?
49
- raise WrongAccountType, validator.errors.join(" ")
50
- end
51
- @account.type = str.to_sym
48
+ valid_attribute DefaultFlagValidator, WrongDefaultFlag, flag
49
+ @account.default = (["true", true].include? flag)
52
50
  end
53
51
  end
54
52
 
53
+ def realname(realname)
54
+ @account.realname = realname
55
+ end
56
+
57
+ def type(str)
58
+ valid_attribute TypeValidator, WrongAccountType, str
59
+ @account.type = str.to_sym
60
+ end
61
+
55
62
  def server(str)
56
63
  @account.server = str
57
64
  end
58
65
 
59
66
  def port(nr)
60
- if nr.nil? || nr == ""
61
- @account.set_default_port
62
- else
63
- validator = PortValidator.new nr
64
- unless validator.valid?
65
- raise WrongAccountPort, validator.errors.join(" ")
66
- end
67
- @account.port = nr.to_i
68
- end
67
+ valid_attribute PortValidator, WrongAccountPort, nr
68
+ @account.port = nr.to_i
69
69
  end
70
70
 
71
71
  def user(str)
@@ -80,10 +80,7 @@ module Mayaml
80
80
  if arr.nil? || arr.empty?
81
81
  @account.set_default_mailboxes
82
82
  else
83
- validator = MailboxesValidator.new arr
84
- unless validator.valid?
85
- raise WrongAccountMailboxes, validator.errors.join(" ")
86
- end
83
+ valid_attribute MailboxesValidator, WrongAccountMailboxes, arr
87
84
  @account.mailboxes = arr
88
85
  end
89
86
  end
@@ -98,11 +95,14 @@ module Mayaml
98
95
 
99
96
  def valid_account
100
97
  validator = RequiredAttributesValidator.new @account
101
- unless validator.valid?
102
- raise MissingAttributes, validator.errors.join(" ")
103
- end
98
+ raise MissingAttributes, validator.errors.join(" ") unless validator.valid?
104
99
  @account.dup
105
100
  end
101
+
102
+ def valid_attribute(validator_class, error_class, attribute)
103
+ validator = validator_class.new attribute
104
+ raise error_class, validator.errors.join(" ") unless validator.valid?
105
+ end
106
106
  end
107
107
  end
108
108
  end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ # Copyright (C) 2016 Szymon Kopciewski
4
+ #
5
+ # This file is part of Mayaml.
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module Mayaml
21
+ class MailAccount
22
+ class DefaultFlagValidator
23
+ attr_reader :errors
24
+
25
+ def initialize(flag)
26
+ @errors = []
27
+ unless [true, false, "true", "false"].include? flag
28
+ @errors << "Flag need to be 'true' or 'false'"
29
+ end
30
+ end
31
+
32
+ def valid?
33
+ @errors.empty?
34
+ end
35
+ end
36
+ end
37
+ end
@@ -26,6 +26,9 @@ module Mayaml
26
26
  class MissingAttributes < Error
27
27
  end
28
28
 
29
+ class WrongDefaultFlag < Error
30
+ end
31
+
29
32
  class WrongAccountType < Error
30
33
  end
31
34
 
@@ -25,6 +25,8 @@ module Mayaml
25
25
  def initialize(mail_account)
26
26
  @errors = []
27
27
  @errors << "Missing name attribute." if mail_account.name.nil?
28
+ @errors << "Missing realname attribute." if mail_account.realname.nil?
29
+ @errors << "Missing type attribute." if mail_account.type.nil?
28
30
  @errors << "Missing server attribute." if mail_account.server.nil?
29
31
  @errors << "Missing user attribute." if mail_account.user.nil?
30
32
  @errors << "Missing pass attribute." if mail_account.pass.nil?
@@ -18,5 +18,5 @@
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module Mayaml
21
- VERSION = "1.0.3".freeze
21
+ VERSION = "2.0.0".freeze
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mayaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Kopciewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Mail Accounts from Yaml parser - the base classes
70
84
  email:
71
85
  - s.kopciewski@gmail.com
@@ -83,6 +97,7 @@ files:
83
97
  - lib/mayaml/error.rb
84
98
  - lib/mayaml/mail_account.rb
85
99
  - lib/mayaml/mail_account/builder.rb
100
+ - lib/mayaml/mail_account/default_flag_validator.rb
86
101
  - lib/mayaml/mail_account/error.rb
87
102
  - lib/mayaml/mail_account/mailboxes_validator.rb
88
103
  - lib/mayaml/mail_account/port_validator.rb
@@ -110,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
125
  version: '0'
111
126
  requirements: []
112
127
  rubyforge_project:
113
- rubygems_version: 2.2.5
128
+ rubygems_version: 2.4.8
114
129
  signing_key:
115
130
  specification_version: 4
116
131
  summary: Mail Accounts from Yaml parser - the base classes