Class: Snowly::ProtocolSchemaFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/snowly/protocol_schema_finder.rb

Constant Summary collapse

PROTOCOL_FILE_NAME =
'snowplow_protocol.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_schema = nil) ⇒ ProtocolSchemaFinder

Returns a new instance of ProtocolSchemaFinder.



6
7
8
9
# File 'lib/snowly/protocol_schema_finder.rb', line 6

def initialize(custom_schema = nil)
  @custom_schema = custom_schema
  @schema = load_protocol_schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



4
5
6
# File 'lib/snowly/protocol_schema_finder.rb', line 4

def schema
  @schema
end

Instance Method Details

#alternative_protocol_schemaObject



24
25
26
# File 'lib/snowly/protocol_schema_finder.rb', line 24

def alternative_protocol_schema
  Dir[File.join(resolver,"/**/*")].select{ |f| File.basename(f) == PROTOCOL_FILE_NAME }[0]
end

#find_protocol_schemaObject



11
12
13
14
15
16
17
18
# File 'lib/snowly/protocol_schema_finder.rb', line 11

def find_protocol_schema
  return @custom_schema if @custom_schema
  if resolver && alternative_protocol_schema
    alternative_protocol_schema
  else
    File.expand_path("../../schemas/#{PROTOCOL_FILE_NAME}", __FILE__)
  end
end

#load_protocol_schemaHash

Loads the protocol schema created to describe snowplow events table attributes

Returns:

  • (Hash)

    parsed schema



30
31
32
# File 'lib/snowly/protocol_schema_finder.rb', line 30

def load_protocol_schema
  JSON.parse File.read(find_protocol_schema)
end

#resolverObject



20
21
22
# File 'lib/snowly/protocol_schema_finder.rb', line 20

def resolver
  Snowly.development_iglu_resolver_path
end