textris 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/textris/delivery/mail.rb +42 -31
  4. metadata +43 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f11d4e0b9fd093a3fdf9375b466db8eaa04ca313
4
- data.tar.gz: e50fca53563ac205dd33aab179367612ee032037
3
+ metadata.gz: 0715eb5a0c4ce47948654b5353c7d67b4f6ea3da
4
+ data.tar.gz: 00e2a1a8c37cd5e3f6b478a41173d5293dfa3098
5
5
  SHA512:
6
- metadata.gz: c003c611fd9db86a5ace9ee0d91559600f0216b6dbbac6a6d778e3006361aae64c318d3d3693717c47f170d7df0991ab485be48c1b516a0815f7278a2513daf5
7
- data.tar.gz: cccddacc6d2698146d6451efafc49f1aee9b88f4c511b597acbc2126adbfe7a3fd5b6c132b2bd364066db1b1a3e7275465c1ef8674fa61bd553be2e6adaf48db
6
+ metadata.gz: a91454d5a3975a73149d944549a965b1f492f23de8671259f162d823ddd953fc82839c650e220058a8d2d8fd36fa3a3440b6d2e5c509db1b325d57170b34f2b8
7
+ data.tar.gz: 58ccf8ef1e8ccb8d7b0f49f16e801285346dd65db865b9e890e710d80ac5d53179ab3ad124f98528c56136949f09d5168c2d2a6324d855752c890e93b5771014
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # textris
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/visualitypl/textris/badges/gpa.svg)](https://codeclimate.com/github/visualitypl/textris)
4
+
3
5
  Simple gem for implementing texter classes which allow sending SMS messages in similar way to how e-mails are implemented and sent with ActionMailer-based mailers.
4
6
 
5
7
  Unlike similar gems, **textris** has some unique features:
@@ -48,41 +48,52 @@ module Textris
48
48
  var = directive.split(':').first
49
49
  modifiers = directive.split(':')[1] || ''
50
50
 
51
- content = if var == 'app'
52
- Rails.application.class.parent_name
53
- elsif var == 'env'
54
- Rails.env
55
- elsif var == 'texter' && (texter = message.texter).present?
56
- texter.to_s.split('::').last.sub(/Texter$/, '')
57
- elsif var == 'action' && (action = message.action).present?
58
- action.to_s
59
- elsif var == 'from_name' && (from = message.from_name).present?
60
- from.to_s
61
- elsif (value = vars[var.to_sym]).present?
62
- value
63
- elsif ['content', 'from_phone'].include?(var)
64
- message.send(var)
65
- end.to_s.strip
66
-
67
- unless content.present?
68
- content = 'unknown'
69
- end
70
-
71
- if modifiers.include?('d')
72
- content = content.underscore.dasherize
73
- end
74
-
75
- if modifiers.include?('h')
76
- content = content.humanize.gsub(/[-_]/, ' ')
77
- end
78
-
79
- if modifiers.include?('p')
80
- content = Phony.format(content) rescue content
81
- end
51
+ content = get_template_interpolation(var, message, vars)
52
+ content = apply_template_modifiers(content, modifiers)
82
53
 
83
54
  content
84
55
  end
85
56
  end
57
+
58
+ def get_template_interpolation(var, message, vars)
59
+ content = if var == 'app'
60
+ Rails.application.class.parent_name
61
+ elsif var == 'env'
62
+ Rails.env
63
+ elsif var == 'texter' && (texter = message.texter).present?
64
+ texter.to_s.split('::').last.sub(/Texter$/, '')
65
+ elsif var == 'action' && (action = message.action).present?
66
+ action.to_s
67
+ elsif var == 'from_name' && (from = message.from_name).present?
68
+ from.to_s
69
+ elsif (value = vars[var.to_sym]).present?
70
+ value
71
+ elsif ['content', 'from_phone'].include?(var)
72
+ message.send(var)
73
+ end.to_s.strip
74
+
75
+ if content.present?
76
+ content
77
+ else
78
+ 'unknown'
79
+ end
80
+ end
81
+
82
+ def apply_template_modifiers(content, modifiers)
83
+ if modifiers.include?('d')
84
+ content = content.underscore.dasherize
85
+ end
86
+
87
+ if modifiers.include?('h')
88
+ content = content.humanize.gsub(/[-_]/, ' ')
89
+ end
90
+
91
+ if modifiers.include?('p')
92
+ content = Phony.format(content) rescue content
93
+ end
94
+
95
+ content
96
+ end
86
97
  end
87
98
  end
88
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Słuszniak
@@ -10,6 +10,48 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: actionmailer
15
57
  requirement: !ruby/object:Gem::Requirement