Module: Activr
- Includes:
- Configuration
- Defined in:
- lib/activr.rb,
lib/activr/async.rb,
lib/activr/utils.rb,
lib/activr/entity.rb,
lib/activr/railtie.rb,
lib/activr/storage.rb,
lib/activr/version.rb,
lib/activr/activity.rb,
lib/activr/registry.rb,
lib/activr/timeline.rb,
lib/activr/rails_ctx.rb,
lib/activr/dispatcher.rb,
lib/activr/configuration.rb,
lib/generators/activr/activity_generator.rb,
lib/generators/activr/timeline_generator.rb
Overview
Manage activity feeds
Defined Under Namespace
Modules: Async, Configuration, Generators Classes: Activity, Dispatcher, Entity, RailsCtx, Railtie, Registry, Storage, Timeline, Utils
Constant Summary collapse
- VERSION =
Activr version
'1.0.1'
Class Attribute Summary collapse
-
.logger ⇒ Logger
A logger instance.
Class Method Summary collapse
-
.activities(limit, options = { }) ⇒ Array<Activity>
Find latest activities.
-
.activities_count(options = { }) ⇒ Integer
Count number of activities.
-
.activities_path ⇒ String
Path to activities classes directory.
-
.configure {|Configuration| ... } ⇒ Object
Configuration sugar.
-
.dispatch!(activity, options = { }) ⇒ Activity
Dispatch an activity.
-
.dispatcher ⇒ Dispatcher
Dispatcher singleton.
-
.normalize_query_options(options) ⇒ Hash
private
Normalize query options.
-
.registry ⇒ Registry
Registry singleton.
-
.sentence(text, bindings = { }) ⇒ String
Render a sentence.
-
.setup ⇒ Object
Setup registry.
-
.storage ⇒ Storage
Storage singleton.
-
.timeline(timeline_class, recipient) ⇒ Timeline
Get a timeline instance.
-
.timelines_path ⇒ String
Path to timelines classes directory.
Class Attribute Details
.logger ⇒ Logger
Returns A logger instance.
66 67 68 69 70 71 72 73 74 |
# File 'lib/activr.rb', line 66 def logger @logger ||= begin result = Logger.new(STDOUT) result.formatter = proc do |severity, datetime, progname, msg| "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}] #{severity} [activr] #{msg}\n" end result end end |
Class Method Details
.activities(limit, options = { }) ⇒ Array<Activity>
If you use others selectors then ‘limit’ argument and ‘skip’ option then you have to setup corresponding indexes in database.
Find latest activities
167 168 169 170 171 |
# File 'lib/activr.rb', line 167 def activities(limit, = { }) = self.() Activr.storage.find_activities(limit, ) end |
.activities_count(options = { }) ⇒ Integer
If you use one of options selectors then you have to setup corresponding indexes in database.
Count number of activities
174 175 176 177 178 |
# File 'lib/activr.rb', line 174 def activities_count( = { }) = self.() Activr.storage.count_activities() end |
.activities_path ⇒ String
Path to activities classes directory
79 80 81 |
# File 'lib/activr.rb', line 79 def activities_path File.join(Activr.config.app_path, "activities") end |
.configure {|Configuration| ... } ⇒ Object
Configuration sugar
56 57 58 |
# File 'lib/activr.rb', line 56 def configure yield self.config end |
.dispatch!(activity, options = { }) ⇒ Activity
Dispatch an activity
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/activr.rb', line 117 def dispatch!(activity, = { }) # default options = { :skip_dup_period => Activr.config.skip_dup_period, }.merge() # check for duplicates skip_it = [:skip_dup_period] && ([:skip_dup_period] > 0) && (Activr.storage.count_duplicate_activities(activity, Time.now - [:skip_dup_period]) > 0) if !skip_it if !activity.stored? # store activity in main collection activity.store! end # check if storing failed if activity.stored? Activr::Async.hook(:route_activity, activity) end end activity end |
.dispatcher ⇒ Dispatcher
Dispatcher singleton
107 108 109 |
# File 'lib/activr.rb', line 107 def dispatcher @dispatcher ||= Activr::Dispatcher.new end |
.normalize_query_options(options) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Normalize query options
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/activr.rb', line 148 def () result = { } .each do |key, value| key = key.to_sym if Activr.registry.entities_names.include?(key) # extract entities from options result[:entities] ||= { } result[:entities][key] = value else result[key] = value end end result end |
.registry ⇒ Registry
Registry singleton
93 94 95 |
# File 'lib/activr.rb', line 93 def registry @registy ||= Activr::Registry.new end |
.sentence(text, bindings = { }) ⇒ String
Render a sentence
194 195 196 197 198 199 200 201 202 |
# File 'lib/activr.rb', line 194 def sentence(text, bindings = { }) # render result = Activr::Utils.render_mustache(text, bindings) # strip whitespaces result.strip! result end |
.setup ⇒ Object
Setup registry
61 62 63 |
# File 'lib/activr.rb', line 61 def setup self.registry.setup end |
.storage ⇒ Storage
Storage singleton
100 101 102 |
# File 'lib/activr.rb', line 100 def storage @storage ||= Activr::Storage.new end |
.timeline(timeline_class, recipient) ⇒ Timeline
Get a timeline instance
185 186 187 |
# File 'lib/activr.rb', line 185 def timeline(timeline_class, recipient) timeline_class.new(recipient) end |
.timelines_path ⇒ String
Path to timelines classes directory
86 87 88 |
# File 'lib/activr.rb', line 86 def timelines_path File.join(Activr.config.app_path, "timelines") end |