evva 0.1.1 → 0.1.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 +4 -4
- data/Gemfile +5 -4
- data/Gemfile.lock +26 -24
- data/changelog.md +3 -0
- data/lib/evva/android_generator.rb +2 -2
- data/lib/evva/swift_generator.rb +35 -38
- data/lib/evva/version.rb +2 -2
- data/spec/lib/evva/swift_generator_spec.rb +44 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ecc532385f462a9f37aec975d66fbd19b18aa05
|
4
|
+
data.tar.gz: acea35b0751f2f5574da3c75a615911a2093c6ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f628dec72519c201300590971a50c6ad81e7d0fe43d529b10b8d36f5463f03536c522a6307d2a082f2a39f55a147d626db9840521dca271cb895c336bc2ab668
|
7
|
+
data.tar.gz: 9a69b2a1810f3ea7a783e399fbda02eb03806526680096dfa1fb7f438e258480b4f7c551bb304078e4f0371b051bc48faa87bdac3dfbf3d2ac58f8aae5832d38
|
data/Gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
ruby '2.3.3'
|
3
3
|
|
4
|
-
gem 'colorize'
|
5
|
-
gem 'rubocop'
|
6
|
-
gem 'safe_yaml'
|
7
|
-
gem 'xml-simple'
|
4
|
+
gem 'colorize'
|
5
|
+
gem 'rubocop'
|
6
|
+
gem 'safe_yaml'
|
7
|
+
gem 'xml-simple'
|
8
|
+
gem 'byebug'
|
8
9
|
|
9
10
|
gem 'rspec'
|
10
11
|
gem 'rspec-its'
|
data/Gemfile.lock
CHANGED
@@ -1,50 +1,51 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.5.
|
5
|
-
public_suffix (
|
4
|
+
addressable (2.5.2)
|
5
|
+
public_suffix (>= 2.0.2, < 4.0)
|
6
6
|
ast (2.3.0)
|
7
|
+
byebug (9.1.0)
|
7
8
|
colorize (0.8.1)
|
8
9
|
crack (0.4.3)
|
9
10
|
safe_yaml (~> 1.0.0)
|
10
11
|
diff-lcs (1.3)
|
11
12
|
docile (1.1.5)
|
12
|
-
hashdiff (0.3.
|
13
|
+
hashdiff (0.3.7)
|
13
14
|
json (2.1.0)
|
14
15
|
parallel (1.12.0)
|
15
16
|
parser (2.4.0.0)
|
16
17
|
ast (~> 2.2)
|
17
18
|
powerpack (0.1.1)
|
18
|
-
public_suffix (
|
19
|
+
public_suffix (3.0.0)
|
19
20
|
rainbow (2.2.2)
|
20
21
|
rake
|
21
|
-
rake (12.
|
22
|
-
rspec (3.
|
23
|
-
rspec-core (~> 3.
|
24
|
-
rspec-expectations (~> 3.
|
25
|
-
rspec-mocks (~> 3.
|
26
|
-
rspec-core (3.
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-expectations (3.
|
22
|
+
rake (12.1.0)
|
23
|
+
rspec (3.7.0)
|
24
|
+
rspec-core (~> 3.7.0)
|
25
|
+
rspec-expectations (~> 3.7.0)
|
26
|
+
rspec-mocks (~> 3.7.0)
|
27
|
+
rspec-core (3.7.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-expectations (3.7.0)
|
29
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.
|
31
|
+
rspec-support (~> 3.7.0)
|
31
32
|
rspec-its (1.2.0)
|
32
33
|
rspec-core (>= 3.0.0)
|
33
34
|
rspec-expectations (>= 3.0.0)
|
34
|
-
rspec-mocks (3.
|
35
|
+
rspec-mocks (3.7.0)
|
35
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-support (3.
|
38
|
-
rubocop (0.
|
37
|
+
rspec-support (~> 3.7.0)
|
38
|
+
rspec-support (3.7.0)
|
39
|
+
rubocop (0.51.0)
|
39
40
|
parallel (~> 1.10)
|
40
41
|
parser (>= 2.3.3.1, < 3.0)
|
41
42
|
powerpack (~> 0.1)
|
42
|
-
rainbow (>=
|
43
|
+
rainbow (>= 2.2.2, < 3.0)
|
43
44
|
ruby-progressbar (~> 1.7)
|
44
45
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
45
|
-
ruby-progressbar (1.
|
46
|
+
ruby-progressbar (1.9.0)
|
46
47
|
safe_yaml (1.0.4)
|
47
|
-
simplecov (0.15.
|
48
|
+
simplecov (0.15.1)
|
48
49
|
docile (~> 1.1.0)
|
49
50
|
json (>= 1.8, < 3)
|
50
51
|
simplecov-html (~> 0.10.0)
|
@@ -62,15 +63,16 @@ PLATFORMS
|
|
62
63
|
ruby
|
63
64
|
|
64
65
|
DEPENDENCIES
|
65
|
-
|
66
|
+
byebug
|
67
|
+
colorize
|
66
68
|
rspec
|
67
69
|
rspec-its
|
68
|
-
rubocop
|
69
|
-
safe_yaml
|
70
|
+
rubocop
|
71
|
+
safe_yaml
|
70
72
|
simplecov
|
71
73
|
simplecov-rcov
|
72
74
|
webmock (~> 1.20)
|
73
|
-
xml-simple
|
75
|
+
xml-simple
|
74
76
|
|
75
77
|
RUBY VERSION
|
76
78
|
ruby 2.3.3p222
|
data/changelog.md
CHANGED
@@ -15,10 +15,10 @@ module Evva
|
|
15
15
|
"import com.hole19golf.hole19.analytics.Event\n\n".freeze
|
16
16
|
|
17
17
|
KOTIN_PEOPLE_FUNCTIONS =
|
18
|
-
"\
|
18
|
+
"\nopen fun updateProperties(property: MixpanelProperties, value: Any) {\n"\
|
19
19
|
"\t\tmixpanelMask.updateProperties(property.key, value)"\
|
20
20
|
"\t\n} \n"\
|
21
|
-
"\
|
21
|
+
"\nopen fun incrementCounter(property: MixpanelProperties) {\n"\
|
22
22
|
"\t\tmixpanelMask.incrementCounter(property.key)"\
|
23
23
|
"\t\n} \n".freeze
|
24
24
|
|
data/lib/evva/swift_generator.rb
CHANGED
@@ -18,7 +18,9 @@ module Evva
|
|
18
18
|
"MixpanelAPI.instance.incrementCounter(rawValue, times: times)\n"\
|
19
19
|
'}'.freeze
|
20
20
|
|
21
|
-
|
21
|
+
NATIVE_TYPES = %w[Long Int String Double Float Bool].freeze
|
22
|
+
|
23
|
+
def events(bundle, file_name)
|
22
24
|
event_file = SWIFT_EVENT_HEADER
|
23
25
|
bundle.each do |event|
|
24
26
|
event_file += swift_case(event)
|
@@ -34,62 +36,63 @@ module Evva
|
|
34
36
|
|
35
37
|
def swift_case(event_data)
|
36
38
|
function_name = 'track' + titleize(event_data.event_name)
|
37
|
-
if event_data.properties.
|
38
|
-
|
39
|
+
if event_data.properties.empty?
|
40
|
+
"\t\tcase #{function_name}\n"
|
39
41
|
else
|
40
|
-
trimmed_properties = event_data.properties.gsub('Boolean', 'Bool')
|
41
|
-
|
42
|
+
trimmed_properties = event_data.properties.map { |k, v| "#{k}: #{v.gsub('Boolean', 'Bool')}" }
|
43
|
+
"\t\tcase #{function_name}(#{trimmed_properties})\n"
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def swift_event_data(event_data)
|
46
48
|
function_name = 'track' + titleize(event_data.event_name)
|
47
|
-
if event_data.properties.
|
49
|
+
if event_data.properties.empty?
|
48
50
|
function_body = "case .#{function_name} \n" \
|
49
|
-
"\treturn EventData(name
|
51
|
+
"\treturn EventData(name:\"#{event_data.event_name}\")\n\n"
|
50
52
|
else
|
51
53
|
function_header = prepend_let(event_data.properties)
|
52
|
-
function_arguments = process_arguments(event_data.properties.gsub('Boolean', 'Bool'))
|
54
|
+
function_arguments = process_arguments(event_data.properties.map { |k, v| "#{k}: #{v.gsub('Boolean', 'Bool')}" })
|
53
55
|
function_body = "case .#{function_name}(#{function_header}):\n" \
|
54
|
-
"\treturn EventData(name
|
56
|
+
"\treturn EventData(name:\"#{event_data.event_name}\", properties: [#{function_arguments}])\n\n"
|
55
57
|
end
|
56
|
-
|
57
58
|
function_body
|
58
59
|
end
|
59
60
|
|
60
|
-
def event_enum(enum)
|
61
|
+
def event_enum(enum, file_name)
|
61
62
|
# empty
|
62
63
|
end
|
63
64
|
|
64
|
-
def people_properties(people_bundle)
|
65
|
+
def people_properties(people_bundle, file_name)
|
65
66
|
properties = SWIFT_PEOPLE_HEADER
|
66
|
-
people_bundle.
|
67
|
-
|
68
|
-
end
|
69
|
-
properties += SWIFT_INCREMENT_FUNCTION + "\n}"
|
67
|
+
properties += people_bundle.map { |prop| swift_people_const(prop) }.join('')
|
68
|
+
properties + "\n" + SWIFT_INCREMENT_FUNCTION + "\n}\n"
|
70
69
|
end
|
71
70
|
|
72
71
|
def special_property_enum(enum)
|
73
72
|
enum_body = "import Foundation\n\n"
|
74
|
-
enum_values = enum.values.split(',')
|
75
73
|
enum_body += "enum #{enum.enum_name}: String {\n"
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
enum_body += "} \n"
|
74
|
+
enum_body += enum.values.map { |vals| "\tcase #{vals.tr(' ', '_')} = \"#{vals}\"\n" }.join('')
|
75
|
+
enum_body + "} \n"
|
80
76
|
end
|
81
77
|
|
82
78
|
def process_arguments(props)
|
83
79
|
arguments = ''
|
84
|
-
props.
|
85
|
-
|
86
|
-
|
87
|
-
|
80
|
+
props.each do |property|
|
81
|
+
val = property.split(':').first
|
82
|
+
if is_special_property?(property)
|
83
|
+
if is_optional_property?(property)
|
84
|
+
val = val.chomp('?')
|
85
|
+
arguments += "\"#{val}\": #{val}.rawValue, "
|
88
86
|
else
|
89
|
-
arguments +=
|
87
|
+
arguments += "\"#{val}\": #{val}.rawValue, "
|
90
88
|
end
|
91
89
|
else
|
92
|
-
|
90
|
+
if is_optional_property?(property)
|
91
|
+
val = val.chomp('?')
|
92
|
+
arguments += "\"#{val}\": #{val}, "
|
93
|
+
else
|
94
|
+
arguments += "\"#{val}\": #{val}, "
|
95
|
+
end
|
93
96
|
end
|
94
97
|
end
|
95
98
|
arguments.chomp(', ')
|
@@ -97,28 +100,22 @@ module Evva
|
|
97
100
|
|
98
101
|
private
|
99
102
|
|
100
|
-
def is_special_property(prop)
|
101
|
-
types_array = %w[Long Int String Double Float Boolean]
|
103
|
+
def is_special_property?(prop)
|
102
104
|
type = prop.split(':')[1]
|
103
|
-
|
105
|
+
!NATIVE_TYPES.include?(type.chomp('?'))
|
104
106
|
end
|
105
107
|
|
106
|
-
def is_optional_property(prop)
|
108
|
+
def is_optional_property?(prop)
|
107
109
|
type = prop.split(':')[1]
|
108
110
|
type.include?('?') ? true : false
|
109
111
|
end
|
110
112
|
|
111
|
-
|
112
113
|
def prepend_let(props)
|
113
|
-
|
114
|
-
props.split(',').each do |property|
|
115
|
-
function_header += 'let ' + property.split(':')[0] + ', '
|
116
|
-
end
|
117
|
-
function_header.chomp(', ')
|
114
|
+
props.map { |k, v| "let #{k}" }.join(', ')
|
118
115
|
end
|
119
116
|
|
120
117
|
def swift_people_const(prop)
|
121
|
-
|
118
|
+
"\tcase #{titleize(prop)} = \"#{prop}\"\n"
|
122
119
|
end
|
123
120
|
|
124
121
|
def titleize(str)
|
data/lib/evva/version.rb
CHANGED
@@ -7,10 +7,10 @@ describe Evva::SwiftGenerator do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe '#events' do
|
10
|
-
subject { trim_spaces(generator.events(event_bundle)) }
|
10
|
+
subject { trim_spaces(generator.events(event_bundle, "")) }
|
11
11
|
let(:event_bundle) {
|
12
12
|
[Evva::MixpanelEvent.new('nav_feed_tap', []),
|
13
|
-
Evva::MixpanelEvent.new('cp_page_view', 'course_id:Long,course_name:String')]
|
13
|
+
Evva::MixpanelEvent.new('cp_page_view', ['course_id:Long'],['course_name:String?'])]
|
14
14
|
}
|
15
15
|
let(:expected) { <<-Swift
|
16
16
|
import CoreLocation
|
@@ -20,47 +20,41 @@ describe Evva::SwiftGenerator do
|
|
20
20
|
class MixpanelHelper: NSObject {
|
21
21
|
enum Event {
|
22
22
|
case trackNavFeedTap
|
23
|
-
case trackCpPageView(course_id:Long,course_name:String)
|
23
|
+
case trackCpPageView(course_id: Long, course_name: String?)
|
24
24
|
}
|
25
|
-
private var data: EventData {
|
26
|
-
switch self {
|
27
25
|
|
28
|
-
|
29
|
-
|
26
|
+
private var data: EventData {
|
27
|
+
switch self {
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
case .trackNavFeedTap
|
30
|
+
return EventData(name:"nav_feed_tap")
|
33
31
|
|
32
|
+
case .trackCpPageView(let course_id, let course_name):
|
33
|
+
return EventData(name:"cp_page_view", properties: ["course_id": course_id, "course_name": course_name])
|
34
|
+
}
|
34
35
|
}
|
35
|
-
}
|
36
36
|
Swift
|
37
37
|
}
|
38
38
|
it { should eq trim_spaces(expected) }
|
39
39
|
end
|
40
40
|
|
41
|
-
describe '#
|
42
|
-
context
|
43
|
-
|
44
|
-
it 'should create a case for an event to be tracked' do
|
45
|
-
expected = "\t\tcase trackNavFeedTap\n"
|
46
|
-
expect(generator.swift_case(event)).to eq expected
|
47
|
-
end
|
48
|
-
end
|
41
|
+
describe '#process_arguments' do
|
42
|
+
context "with optional arguments" do
|
43
|
+
let(:properties) { 'course_id:Long,course_name:String,from_screen: CourseProfileSource?' }
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
expected = "\t\tcase trackCpPageView(course_id:Long,course_name:String)\n"
|
54
|
-
expect(generator.swift_case(event)).to eq expected
|
45
|
+
it 'processes the arguments looking for special properties' do
|
46
|
+
expected = '"course_id": course_id, "course_name": course_name, "from_screen": from_screen.rawValue'
|
47
|
+
expect(generator.process_arguments(properties)).to eq expected
|
55
48
|
end
|
56
49
|
end
|
57
|
-
end
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
51
|
+
context "without optional arguments" do
|
52
|
+
let(:properties) { 'course_id:Long,course_name:String,from_screen: CourseProfileSource' }
|
53
|
+
|
54
|
+
it 'processes the arguments looking for special properties' do
|
55
|
+
expected = '"course_id": course_id, "course_name": course_name, "from_screen": from_screen.rawValue'
|
56
|
+
expect(generator.process_arguments(properties)).to eq expected
|
57
|
+
end
|
64
58
|
end
|
65
59
|
end
|
66
60
|
|
@@ -71,11 +65,30 @@ describe Evva::SwiftGenerator do
|
|
71
65
|
import Foundation
|
72
66
|
|
73
67
|
enum CourseProfileSource: String {
|
74
|
-
|
75
|
-
|
68
|
+
case course_discovery = "course_discovery"
|
69
|
+
case synced_courses = "synced_courses"
|
76
70
|
}
|
77
71
|
Swift
|
78
72
|
}
|
73
|
+
|
74
|
+
it { should eq trim_spaces(expected) }
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#people_properties" do
|
78
|
+
subject { trim_spaces(generator.people_properties(people_bundle)) }
|
79
|
+
let(:people_bundle) { ['rounds_with_wear', 'friends_from_facebook'] }
|
80
|
+
let(:expected) { <<-Swift
|
81
|
+
fileprivate enum Counter: String {
|
82
|
+
case RoundsWithWear = "rounds_with_wear"
|
83
|
+
case FriendsFromFacebook = "friends_from_facebook"
|
84
|
+
|
85
|
+
func increment(times: Int = 1) {
|
86
|
+
MixpanelAPI.instance.incrementCounter(rawValue, times: times)
|
87
|
+
}
|
88
|
+
}
|
89
|
+
Swift
|
90
|
+
}
|
91
|
+
|
79
92
|
it { should eq trim_spaces(expected) }
|
80
93
|
end
|
81
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evva
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RicardoTrindade
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: safe_yaml
|