evva 0.1.4 → 0.1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +6 -3
- data/lib/evva/swift_generator.rb +38 -32
- data/lib/evva/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb97d0f1d8232f0bd8be466a5bb44d0d6969d620
|
4
|
+
data.tar.gz: eafd1e8f81baa14886ba4fcb466ea18b59f9b199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f35827bcadcc08b17693f45d7b5106c75fddb277df50f837eb38e8ab10e06612d53ee550a37ad173e85ffa9e830a5b4debb2136c361dff0e4335c15054449b7
|
7
|
+
data.tar.gz: eec447eb9229129b08415d30382e23fcab70b354a6512e906d756fe7c87ef734011fe2ba4da7cc09706ac00bcd2310e6047698f36e5eaafcb3be2d9521b9ef0d
|
data/changelog.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# Change Log
|
2
|
-
##[0.1.4] - 2018-02-08
|
2
|
+
## [0.1.4.1] - 2018-02-08
|
3
|
+
- DRYs methods in swift event generation
|
4
|
+
|
5
|
+
## [0.1.4] - 2018-02-08
|
3
6
|
- Removes not needed enum file on Swift generator
|
4
7
|
- Removes Long type on Swift generator
|
5
8
|
- More tabbing fixes according to #9
|
6
9
|
|
7
|
-
##[0.1.3] - 2018-02-08
|
10
|
+
## [0.1.3] - 2018-02-08
|
8
11
|
- Fixes quotations and spacing on Swift code generation
|
9
12
|
|
10
|
-
##[0.1.2] - 2018-01-25
|
13
|
+
## [0.1.2] - 2018-01-25
|
11
14
|
- Improves swift code generation
|
12
15
|
|
13
16
|
## [0.1.1] - 2017-11-07
|
data/lib/evva/swift_generator.rb
CHANGED
@@ -4,7 +4,17 @@ module Evva
|
|
4
4
|
"import CoreLocation\n"\
|
5
5
|
"import Foundation\n"\
|
6
6
|
"import SharedCode\n\n"\
|
7
|
-
"@objc class MixpanelHelper: NSObject {\n"\
|
7
|
+
"@objc class MixpanelHelper: NSObject {\n\n"\
|
8
|
+
"\tprivate struct EventData {\n"\
|
9
|
+
"\t\tlet name: String\n"\
|
10
|
+
"\t\tlet properties: [String: Any]?\n"\
|
11
|
+
"\t\tlet timeEvent: Bool\n\n"\
|
12
|
+
"\t\tinit(name: String, properties: [String: Any]? = nil, timeEvent: Bool = false) {\n"\
|
13
|
+
"\t\t\tself.name = name\n"\
|
14
|
+
"\t\t\tself.properties = properties\n"\
|
15
|
+
"\t\t\tself.timeEvent = timeEvent\n"\
|
16
|
+
"\t\t}\n"\
|
17
|
+
"\t}\n\n"\
|
8
18
|
"\tenum Event {\n".freeze
|
9
19
|
|
10
20
|
SWIFT_EVENT_DATA_HEADER =
|
@@ -16,7 +26,7 @@ module Evva
|
|
16
26
|
SWIFT_INCREMENT_FUNCTION =
|
17
27
|
"\tfunc increment(times: Int = 1) {\n"\
|
18
28
|
"\t\tMixpanelAPI.instance.incrementCounter(rawValue, times: times)\n"\
|
19
|
-
|
29
|
+
"\t}".freeze
|
20
30
|
|
21
31
|
NATIVE_TYPES = %w[Int String Double Float Bool].freeze
|
22
32
|
|
@@ -25,12 +35,14 @@ module Evva
|
|
25
35
|
bundle.each do |event|
|
26
36
|
event_file += swift_case(event)
|
27
37
|
end
|
28
|
-
event_file += "\t}\n\n"
|
29
38
|
event_file += SWIFT_EVENT_DATA_HEADER
|
30
39
|
bundle.each do |event|
|
31
40
|
event_file += swift_event_data(event)
|
32
41
|
end
|
33
|
-
event_file += "\t
|
42
|
+
event_file += "\t\t\t}\n"
|
43
|
+
event_file += "\t\t}\n"
|
44
|
+
event_file += "\t}\n"
|
45
|
+
event_file += "}\n"
|
34
46
|
end
|
35
47
|
|
36
48
|
def swift_case(event_data)
|
@@ -38,7 +50,7 @@ module Evva
|
|
38
50
|
if event_data.properties.empty?
|
39
51
|
"\t\tcase #{function_name}\n"
|
40
52
|
else
|
41
|
-
trimmed_properties = event_data.properties.map { |k, v| k.to_s + ': ' + v
|
53
|
+
trimmed_properties = event_data.properties.map { |k, v| k.to_s + ': ' + native_type(v) }.join(", ")
|
42
54
|
"\t\tcase #{function_name}(#{trimmed_properties})\n"
|
43
55
|
end
|
44
56
|
end
|
@@ -50,9 +62,11 @@ module Evva
|
|
50
62
|
"\t\t\t\treturn EventData(name: \"#{event_data.event_name}\")\n\n"
|
51
63
|
else
|
52
64
|
function_header = prepend_let(event_data.properties)
|
53
|
-
function_arguments =
|
54
|
-
function_body = "\t\t\tcase .#{function_name}(#{function_header}):\n"
|
55
|
-
"\t\t\t\treturn EventData(name: \"#{event_data.event_name}\", properties: [
|
65
|
+
function_arguments = dictionary_pairs(event_data.properties)
|
66
|
+
function_body = "\t\t\tcase .#{function_name}(#{function_header}):\n"\
|
67
|
+
"\t\t\t\treturn EventData(name: \"#{event_data.event_name}\", properties: [\n"\
|
68
|
+
"\t\t\t\t\t#{function_arguments.join(",\n\t\t\t\t\t")} ]\n"\
|
69
|
+
"\t\t\t\t)\n\n"
|
56
70
|
end
|
57
71
|
function_body
|
58
72
|
end
|
@@ -74,39 +88,31 @@ module Evva
|
|
74
88
|
enum_body + "} \n"
|
75
89
|
end
|
76
90
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
val = val.chomp('?')
|
84
|
-
arguments += "\"#{val}\": #{val}.rawValue, "
|
85
|
-
else
|
86
|
-
arguments += "\"#{val}\": #{val}.rawValue, "
|
87
|
-
end
|
88
|
-
else
|
89
|
-
if is_optional_property?(property)
|
90
|
-
val = val.chomp('?')
|
91
|
-
arguments += "\"#{val}\": #{val}, "
|
92
|
-
else
|
93
|
-
arguments += "\"#{val}\": #{val}, "
|
91
|
+
def dictionary_pairs(props)
|
92
|
+
props.map do |name, type|
|
93
|
+
pair = "\"#{name}\": #{name}"
|
94
|
+
if is_raw_representable_property?(type)
|
95
|
+
if is_optional_property?(type)
|
96
|
+
pair += "?"
|
94
97
|
end
|
98
|
+
pair += ".rawValue"
|
95
99
|
end
|
100
|
+
pair += " as Any"
|
96
101
|
end
|
97
|
-
arguments.chomp(', ')
|
98
102
|
end
|
99
103
|
|
100
104
|
private
|
101
105
|
|
102
|
-
def
|
103
|
-
type
|
104
|
-
|
106
|
+
def is_raw_representable_property?(type)
|
107
|
+
!NATIVE_TYPES.include?(native_type(type).chomp('?'))
|
108
|
+
end
|
109
|
+
|
110
|
+
def is_optional_property?(type)
|
111
|
+
type.end_with?('?')
|
105
112
|
end
|
106
113
|
|
107
|
-
def
|
108
|
-
type
|
109
|
-
type.include?('?') ? true : false
|
114
|
+
def native_type(type)
|
115
|
+
type.gsub('Boolean','Bool').gsub('Long', 'Int')
|
110
116
|
end
|
111
117
|
|
112
118
|
def prepend_let(props)
|
data/lib/evva/version.rb
CHANGED