evva 0.1.4 → 0.1.4.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56e6842ab3d66a9abb5650bb441f0291e8c51e72
4
- data.tar.gz: b823b271c2577b6fd072617d55546558a097ae10
3
+ metadata.gz: eb97d0f1d8232f0bd8be466a5bb44d0d6969d620
4
+ data.tar.gz: eafd1e8f81baa14886ba4fcb466ea18b59f9b199
5
5
  SHA512:
6
- metadata.gz: 32d566d2c257d59dd7dd5a8f19c07342322d3402ea34fb2e230126ec92e6410829ee5a9d2a302b829cfee0df0dfa52b9ac236807a82f6996df59a3b06443a8e7
7
- data.tar.gz: f82155689b8307c2c7709921e5ee9f602612c13b5065d7b5a1ca32f253d0a7efe179be5cead7adf78e1de35eebf77ec1faa062ac3b5476a9de961fba60104156
6
+ metadata.gz: 6f35827bcadcc08b17693f45d7b5106c75fddb277df50f837eb38e8ab10e06612d53ee550a37ad173e85ffa9e830a5b4debb2136c361dff0e4335c15054449b7
7
+ data.tar.gz: eec447eb9229129b08415d30382e23fcab70b354a6512e906d756fe7c87ef734011fe2ba4da7cc09706ac00bcd2310e6047698f36e5eaafcb3be2d9521b9ef0d
@@ -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
@@ -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
- '\t}'.freeze
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}\n}\n"
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.gsub('Boolean','Bool').gsub('Long', 'Int') }.join(", ")
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 = process_arguments(event_data.properties.map { |k, v| "#{k}: #{v}" })
54
- function_body = "\t\t\tcase .#{function_name}(#{function_header}):\n" \
55
- "\t\t\t\treturn EventData(name: \"#{event_data.event_name}\", properties: [#{function_arguments}])\n\n"
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 process_arguments(props)
78
- arguments = ''
79
- props.each do |property|
80
- val = property.split(':').first
81
- if is_special_property?(property)
82
- if is_optional_property?(property)
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 is_special_property?(prop)
103
- type = prop.split(':')[1]
104
- !NATIVE_TYPES.include?(type.chomp('?'))
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 is_optional_property?(prop)
108
- type = prop.split(':')[1]
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)
@@ -1,4 +1,4 @@
1
1
  module Evva
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.4.1'.freeze
3
3
  VERSION_UPDATED_AT = '2018-02-08'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evva
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - RicardoTrindade