Module: Octo
- Includes:
- Config
- Defined in:
- lib/octocore-mongo.rb,
lib/octocore-mongo/email.rb,
lib/octocore-mongo/stats.rb,
lib/octocore-mongo/utils.rb,
lib/octocore-mongo/config.rb,
lib/octocore-mongo/config.rb,
lib/octocore-mongo/record.rb,
lib/octocore-mongo/trends.rb,
lib/octocore-mongo/counter.rb,
lib/octocore-mongo/segment.rb,
lib/octocore-mongo/version.rb,
lib/octocore-mongo/baseline.rb,
lib/octocore-mongo/callbacks.rb,
lib/octocore-mongo/scheduler.rb,
lib/octocore-mongo/trendable.rb,
lib/octocore-mongo/featureflag.rb,
lib/octocore-mongo/models/user.rb,
lib/octocore-mongo/kafka_bridge.rb,
lib/octocore-mongo/kldivergence.rb,
lib/octocore-mongo/models/plans.rb,
lib/octocore-mongo/search/setup.rb,
lib/octocore-mongo/schedeuleable.rb,
lib/octocore-mongo/search/client.rb,
lib/octocore-mongo/message_parser.rb,
lib/octocore-mongo/counter/helpers.rb,
lib/octocore-mongo/models/contactus.rb,
lib/octocore-mongo/models/subscribe.rb,
lib/octocore-mongo/models/enterprise.rb,
lib/octocore-mongo/search/searchable.rb,
lib/octocore-mongo/helpers/api_helper.rb,
lib/octocore-mongo/helpers/api_logger.rb,
lib/octocore-mongo/helpers/kong_helper.rb,
lib/octocore-mongo/helpers/client_helper.rb,
lib/octocore-mongo/models/enterprise/ctr.rb,
lib/octocore-mongo/models/enterprise/gcm.rb,
lib/octocore-mongo/models/enterprise/tag.rb,
lib/octocore-mongo/helpers/sinatra_helper.rb,
lib/octocore-mongo/models/enterprise/page.rb,
lib/octocore-mongo/models/user/push_token.rb,
lib/octocore-mongo/models/enterprise/rules.rb,
lib/octocore-mongo/mailer/subscriber_mailer.rb,
lib/octocore-mongo/models/user/user_persona.rb,
lib/octocore-mongo/models/user/user_profile.rb,
lib/octocore-mongo/models/enterprise/api_hit.rb,
lib/octocore-mongo/models/enterprise/api_key.rb,
lib/octocore-mongo/models/enterprise/funnels.rb,
lib/octocore-mongo/models/enterprise/product.rb,
lib/octocore-mongo/models/enterprise/segment.rb,
lib/octocore-mongo/models/enterprise/tag_hit.rb,
lib/octocore-mongo/models/user/user_timeline.rb,
lib/octocore-mongo/models/enterprise/app_init.rb,
lib/octocore-mongo/models/enterprise/category.rb,
lib/octocore-mongo/models/enterprise/push_key.rb,
lib/octocore-mongo/models/enterprise/template.rb,
lib/octocore-mongo/helpers/api_consumer_helper.rb,
lib/octocore-mongo/models/enterprise/api_event.rb,
lib/octocore-mongo/models/enterprise/api_track.rb,
lib/octocore-mongo/models/enterprise/app_login.rb,
lib/octocore-mongo/models/enterprise/page_view.rb,
lib/octocore-mongo/models/enterprise/tag_trend.rb,
lib/octocore-mongo/models/enterprise/app_logout.rb,
lib/octocore-mongo/models/enterprise/conversions.rb,
lib/octocore-mongo/models/enterprise/funnel_data.rb,
lib/octocore-mongo/models/enterprise/product_hit.rb,
lib/octocore-mongo/models/enterprise/category_hit.rb,
lib/octocore-mongo/models/enterprise/newsfeed_hit.rb,
lib/octocore-mongo/models/enterprise/segment_data.rb,
lib/octocore-mongo/models/enterprise/tag_baseline.rb,
lib/octocore-mongo/models/user/user_phone_details.rb,
lib/octocore-mongo/models/enterprise/authorization.rb,
lib/octocore-mongo/models/enterprise/pageload_time.rb,
lib/octocore-mongo/models/enterprise/product_trend.rb,
lib/octocore-mongo/models/enterprise/category_trend.rb,
lib/octocore-mongo/models/enterprise/funnel_tracker.rb,
lib/octocore-mongo/models/user/user_browser_details.rb,
lib/octocore-mongo/models/enterprise/adapter_details.rb,
lib/octocore-mongo/models/enterprise/engagement_time.rb,
lib/octocore-mongo/models/user/user_location_history.rb,
lib/octocore-mongo/models/enterprise/dimension_choice.rb,
lib/octocore-mongo/models/enterprise/notification_hit.rb,
lib/octocore-mongo/models/enterprise/product_baseline.rb,
lib/octocore-mongo/models/enterprise/category_baseline.rb,
lib/octocore-mongo/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
-
._connect(configuration) ⇒ Object
A low level method to connect using a configuration.
-
.connect(configuration) ⇒ Object
Connect using the provided configuration.
-
.connect_with(location) ⇒ Object
Provides a unified interface to #connect_with_config_dir and #connect_with_config_file for convenience.
-
.connect_with_config_dir(config_dir) ⇒ Object
Connect by reading configuration files from the given directory.
-
.connect_with_config_file(config_file) ⇒ Object
Connect by reading configuration from the provided file.
-
.logger ⇒ Object
Creates a logger for Octo.
-
.true_load(config, file, config_dir) ⇒ Hash
Loads the true config.
Methods included from Config
Class Method Details
._connect(configuration) ⇒ Object
A low level method to connect using a configuration
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 141 142 143 144 145 |
# File 'lib/octocore-mongo.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 Mongo Connection mongo_uri = Octo.get_config(:mongo_uri) connection = MongoMapper.setup({'production' => {'uri' => mongo_uri}}, 'production') # MongoMapper::Connection.connection= connection # Establish connection to cache server default_cache = { host: '127.0.0.1', port: 6379 } cache_config = Octo.get_config(:redis, default_cache) MongoMapper::Document.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-mongo/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
38 39 40 |
# File 'lib/octocore-mongo.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-mongo.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-mongo.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
44 45 46 47 |
# File 'lib/octocore-mongo.rb', line 44 def self.connect_with_config_file(config_file) config = YAML.load_file(config_file).deep_symbolize_keys self.connect(config) end |
.logger ⇒ Object
Creates a logger for Octo
148 149 150 151 152 153 154 155 |
# File 'lib/octocore-mongo.rb', line 148 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/octocore-mongo.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 |