Module: Evva

Extended by:
Evva
Included in:
Evva
Defined in:
lib/evva.rb,
lib/evva/config.rb,
lib/evva/logger.rb,
lib/evva/version.rb,
lib/evva/file_reader.rb,
lib/evva/google_sheet.rb,
lib/evva/analytics_enum.rb,
lib/evva/analytics_event.rb,
lib/evva/swift_generator.rb,
lib/evva/kotlin_generator.rb,
lib/evva/analytics_property.rb

Defined Under Namespace

Modules: Logger Classes: AnalyticsEnum, AnalyticsEvent, AnalyticsProperty, Config, FileReader, GoogleSheet, KotlinGenerator, SwiftGenerator

Constant Summary collapse

VERSION =
"0.5.0".freeze
VERSION_UPDATED_AT =
"2024-10-16".freeze

Instance Method Summary collapse

Instance Method Details

#analytics_data(config:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/evva.rb', line 63

def analytics_data(config:)
  source =
    case config[:type]
    when "google_sheet"
      Evva::GoogleSheet.new(config[:events_url], config[:people_properties_url], config[:enum_classes_url])
    end
  events_bundle = {}
  events_bundle[:events] = source.events
  events_bundle[:people] = source.people_properties
  events_bundle[:enums] = source.enum_classes
  events_bundle[:destinations] = source.destinations
  events_bundle
end

#command_line_options(options) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/evva.rb', line 77

def command_line_options(options)
  opts_hash = {}

  opts_parser = OptionParser.new do |opts|
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("-v", "--version", "Show version") do
      puts Evva::VERSION
      exit
    end
  end
  opts_parser.parse!(options)

  opts_hash
end

#evva_write(bundle, generator, configuration, extension) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/evva.rb', line 39

def evva_write(bundle, generator, configuration, extension)
  path = "#{configuration.out_path}/#{configuration.event_file_name}.#{extension}"
  write_to_file(path, generator.events(bundle[:events], configuration.event_file_name, configuration.event_enum_file_name, configuration.destinations_file_name))

  unless configuration.type.downcase == "ios"
    path = "#{configuration.out_path}/#{configuration.event_enum_file_name}.#{extension}"
    write_to_file(path, generator.event_enum(bundle[:events], configuration.event_enum_file_name))
  end

  path = "#{configuration.out_path}/#{configuration.people_file_name}.#{extension}"
  write_to_file(path, generator.people_properties(bundle[:people], configuration.people_file_name, configuration.people_enum_file_name, configuration.destinations_file_name))

  unless configuration.type.downcase == "ios"
    path = "#{configuration.out_path}/#{configuration.people_enum_file_name}.#{extension}"
    write_to_file(path, generator.people_properties_enum(bundle[:people], configuration.people_enum_file_name))
  end

  path = "#{configuration.out_path}/#{configuration.special_enum_file_name}.#{extension}"
  write_to_file(path, generator.special_property_enums(bundle[:enums]))

  path = "#{configuration.out_path}/#{configuration.destinations_file_name}.#{extension}"
  write_to_file(path, generator.destinations(bundle[:destinations], configuration.destinations_file_name))
end

#run(options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/evva.rb', line 18

def run(options)
  file_reader = Evva::FileReader.new
  options = command_line_options(options)
  unless config_file = file_reader.open_file("evva_config.yml", "r", true)
    Logger.error("Could not open evva_config.yml")
    return
  end

  config = Evva::Config.new(hash: YAML.safe_load(config_file))
  bundle = analytics_data(config: config.data_source)
  case config.type.downcase
  when "android"
    generator = Evva::KotlinGenerator.new(config.package_name)
    evva_write(bundle, generator, config, "kt")
  when "ios"
    generator = Evva::SwiftGenerator.new
    evva_write(bundle, generator, config, "swift")
  end
  Evva::Logger.print_summary
end

#write_to_file(path, data) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/evva.rb', line 96

def write_to_file(path, data)
  file_reader = Evva::FileReader.new
  if file = file_reader.open_file(path, "w", false)
    file_reader.write_to_file(file, data)
  else
    Logger.error("Could not write to file in #{path}")
  end
end