Module: Octo

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

def self._connect(configuration)

  load_config configuration

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

  # Establish Cequel Connection
  cassandra_config = Octo.get_config(:cassandra)
  connection = Cequel.connect(cassandra_config)
  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-cassandra/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-cassandra.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-cassandra.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-cassandra.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-cassandra.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



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

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-cassandra.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