Module: Octo

Includes:
Config
Defined in:
lib/octocore.rb,
lib/octocore/email.rb,
lib/octocore/stats.rb,
lib/octocore/utils.rb,
lib/octocore/config.rb,
lib/octocore/config.rb,
lib/octocore/record.rb,
lib/octocore/trends.rb,
lib/octocore/counter.rb,
lib/octocore/segment.rb,
lib/octocore/version.rb,
lib/octocore/baseline.rb,
lib/octocore/callbacks.rb,
lib/octocore/scheduler.rb,
lib/octocore/trendable.rb,
lib/octocore/featureflag.rb,
lib/octocore/models/user.rb,
lib/octocore/kafka_bridge.rb,
lib/octocore/kldivergence.rb,
lib/octocore/models/plans.rb,
lib/octocore/search/setup.rb,
lib/octocore/schedeuleable.rb,
lib/octocore/search/client.rb,
lib/octocore/message_parser.rb,
lib/octocore/counter/helpers.rb,
lib/octocore/models/contactus.rb,
lib/octocore/models/subscribe.rb,
lib/octocore/models/enterprise.rb,
lib/octocore/search/searchable.rb,
lib/octocore/helpers/api_helper.rb,
lib/octocore/helpers/api_logger.rb,
lib/octocore/helpers/kong_helper.rb,
lib/octocore/helpers/client_helper.rb,
lib/octocore/models/enterprise/ctr.rb,
lib/octocore/models/enterprise/gcm.rb,
lib/octocore/models/enterprise/tag.rb,
lib/octocore/helpers/sinatra_helper.rb,
lib/octocore/models/enterprise/page.rb,
lib/octocore/models/user/push_token.rb,
lib/octocore/models/enterprise/rules.rb,
lib/octocore/mailer/subscriber_mailer.rb,
lib/octocore/models/user/user_persona.rb,
lib/octocore/models/user/user_profile.rb,
lib/octocore/models/enterprise/api_hit.rb,
lib/octocore/models/enterprise/funnels.rb,
lib/octocore/models/enterprise/product.rb,
lib/octocore/models/enterprise/segment.rb,
lib/octocore/models/enterprise/tag_hit.rb,
lib/octocore/models/user/user_timeline.rb,
lib/octocore/models/enterprise/app_init.rb,
lib/octocore/models/enterprise/category.rb,
lib/octocore/models/enterprise/push_key.rb,
lib/octocore/models/enterprise/template.rb,
lib/octocore/helpers/api_consumer_helper.rb,
lib/octocore/models/enterprise/api_event.rb,
lib/octocore/models/enterprise/api_track.rb,
lib/octocore/models/enterprise/app_login.rb,
lib/octocore/models/enterprise/page_view.rb,
lib/octocore/models/enterprise/tag_trend.rb,
lib/octocore/models/enterprise/app_logout.rb,
lib/octocore/models/enterprise/conversions.rb,
lib/octocore/models/enterprise/funnel_data.rb,
lib/octocore/models/enterprise/product_hit.rb,
lib/octocore/models/enterprise/category_hit.rb,
lib/octocore/models/enterprise/newsfeed_hit.rb,
lib/octocore/models/enterprise/segment_data.rb,
lib/octocore/models/enterprise/tag_baseline.rb,
lib/octocore/models/user/user_phone_details.rb,
lib/octocore/models/enterprise/authorization.rb,
lib/octocore/models/enterprise/pageload_time.rb,
lib/octocore/models/enterprise/product_trend.rb,
lib/octocore/models/enterprise/category_trend.rb,
lib/octocore/models/enterprise/funnel_tracker.rb,
lib/octocore/models/user/user_browser_details.rb,
lib/octocore/models/enterprise/adapter_details.rb,
lib/octocore/models/enterprise/engagement_time.rb,
lib/octocore/models/user/user_location_history.rb,
lib/octocore/models/enterprise/dimension_choice.rb,
lib/octocore/models/enterprise/notification_hit.rb,
lib/octocore/models/enterprise/product_baseline.rb,
lib/octocore/models/enterprise/category_baseline.rb,
lib/octocore/models/enterprise/product_page_view.rb

Overview

Model for Subscribe to us (in the footer), on the microsite

Defined Under Namespace

Modules: Baseline, Config, Counter, Email, FeatureFlag, Helpers, KLDivergence, Mailer, Message, OctoHooks, Record, Scheduleable, Scheduler, Search, Searchable, Segmentation, Setup, Sinatra, Stats, Trendable, Trends, Utils Classes: AdapterDetails, ApiEvent, ApiHit, ApiLogger, ApiTrack, AppInit, AppLogin, AppLogout, Authorization, Callbacks, Category, CategoryBaseline, CategoryHit, CategoryTrend, ContactUs, Conversions, Ctr, DimensionChoice, EmailSender, EngagementTime, Enterprise, Funnel, FunnelData, FunnelTracker, GcmNotification, KafkaBridge, NewsfeedHit, NotificationHit, Page, PageView, PageloadTime, Plan, Product, ProductBaseline, ProductHit, ProductPageView, ProductTrend, PushKey, PushToken, Rules, Segment, SegmentData, Subscriber, Tag, TagBaseline, TagHit, TagTrend, Template, User, UserBrowserDetails, UserLocationHistory, UserPersona, UserPhoneDetails, UserProfileDetails, UserTimeline

Constant Summary collapse

VERSION =

The current version of the library

'0.0.6'

Class Method Summary collapse

Methods included from Config

included

Class Method Details

._connect(configuration) ⇒ Object

A low level method to connect using a configuration

Parameters:

  • configuration (Hash)

    The configuration hash



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/octocore.rb', line 110

def self._connect(configuration)

  load_config configuration

  self.logger.info('Octo booting up.')

  # Establish Cequel Connection
  connection = Cequel.connect(Octo.get_config(:cassandra))
  Cequel::Record.connection = connection

  # Establish connection to cache server
  default_cache = {
      host: '127.0.0.1', port: 6379
  }
  cache_config = Octo.get_config(:redis, default_cache)
  Cequel::Record.update_cache_config(*cache_config.values_at(:host, :port))

  # Establish connection to statsd server if required
  if configuration.has_key?(:statsd)
    statsd_config = configuration[:statsd]
    set_config :stats, Statsd.new(*statsd_config.values)
  end

  self.logger.info('I\'m connected now.')
  require 'octocore/callbacks'

  self.logger.info('Setting callbacks.')

  Octo::Callbacks.run_hook(:after_connect)
end

.connect(configuration) ⇒ Object

Connect using the provided configuration. If you want to extend Octo’s connect

method you can override this method with your own. Just make sure to make
a call to self._connect(configuration) so that Octo also connects

Parameters:

  • configuration (Hash)

    The configuration hash



38
39
40
# File 'lib/octocore.rb', line 38

def self.connect(configuration)
  self._connect(configuration)
end

.connect_with(location) ⇒ Object

Provides a unified interface to #connect_with_config_dir

and #connect_with_config_file for convenience


97
98
99
100
101
102
103
104
105
# File 'lib/octocore.rb', line 97

def self.connect_with(location)
  if File.directory?(location)
    self.connect_with_config_dir location
  elsif File.file?(location)
    self.connect_with_config_file location
  else
    puts "Invalid location #{ location }"
  end
end

.connect_with_config_dir(config_dir) ⇒ Object

Connect by reading configuration files from the given directory.

In this case, all *.y*ml files would be read in
Dir.glob order and merged into one unified config


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/octocore.rb', line 52

def self.connect_with_config_dir(config_dir)
  config = {}
  accepted_formats = Set.new(['.yaml', '.yml'])
  Dir[config_dir + '/*'].each do |file_obj|
    if File.file?(file_obj) and accepted_formats.include?File.extname(file_obj)
      config = self.true_load(config, file_obj, config_dir)
    elsif File.directory?(file_obj)
      Dir[file_obj + '/**/*.y*ml'].each do |file|
        config = self.true_load(config, file, config_dir)
      end
    end
  end
  # As a cleanup step, merge the values of key named "config"
  # with the global config hash
  configConfig = config.delete(:config)
  config = config.deep_merge(configConfig)
  # Now, good to merge the two
  self.connect config
end

.connect_with_config_file(config_file) ⇒ Object

Connect by reading configuration from the provided file

Parameters:

  • config_file (String)

    Location of the YAML config file



44
45
46
47
# File 'lib/octocore.rb', line 44

def self.connect_with_config_file(config_file)
  config = YAML.load_file(config_file).deep_symbolize_keys
  self.connect(config)
end

.loggerObject

Creates a logger for Octo



142
143
144
145
146
147
148
149
# File 'lib/octocore.rb', line 142

def self.logger
  unless @logger
    @logger = Logger.new(Octo.get_config(:logfile, $stdout)).tap do |log|
      log.progname = name
    end
  end
  @logger
end

.true_load(config, file, config_dir) ⇒ Hash

Loads the true config. The true config is the hierarchial config

Parameters:

  • config (Hash)

    The base config. Loaded config will be deep merged with this

  • file (String)

    The file from which config should be loaded

  • config_fir (String)

    The config dir in which the file is located

Returns:

  • (Hash)

    The merged config hash



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

def self.true_load(config, file, config_dir)
  _config = YAML.load_file file
  if _config
    $stdout.puts "Loading from Config file: #{ file }"
    # A little bit of hack here.
    # This hack makes sure that if we load config files from nestes
    # directories, the corresponding config is loaded in
    # hierarchy.
    # So, if the file is like /config/search/index.yml, the
    # key would be like [config[search[index]]]
    a = file.gsub(/(\/?#{config_dir}(\/)*(config\/)*|.yml)/, '').split('/')
    _true_config = a.reverse.inject(_config) { |r,e| { e => r } }
    config = config.deep_merge(_true_config.deep_symbolize_keys)
  end
  config
end