Module: CodeSunset
- Defined in:
- lib/code_sunset.rb,
lib/code_sunset/engine.rb,
lib/code_sunset/context.rb,
lib/code_sunset/version.rb,
lib/code_sunset/subscriber.rb,
lib/code_sunset/job_context.rb,
app/models/code_sunset/event.rb,
lib/code_sunset/event_buffer.rb,
lib/code_sunset/configuration.rb,
lib/code_sunset/event_payload.rb,
lib/code_sunset/feature_query.rb,
lib/code_sunset/identity_hash.rb,
lib/code_sunset/status_engine.rb,
app/models/code_sunset/feature.rb,
lib/code_sunset/event_ingestor.rb,
lib/code_sunset/instrumentation.rb,
lib/code_sunset/alert_dispatcher.rb,
lib/code_sunset/feature_snapshot.rb,
lib/code_sunset/score_calculator.rb,
lib/code_sunset/analytics_filters.rb,
lib/code_sunset/controller_context.rb,
app/models/code_sunset/daily_rollup.rb,
app/jobs/code_sunset/application_job.rb,
lib/code_sunset/feature_usage_series.rb,
app/models/code_sunset/alert_delivery.rb,
app/jobs/code_sunset/persist_event_job.rb,
lib/code_sunset/removal_prompt_builder.rb,
app/jobs/code_sunset/cleanup_events_job.rb,
lib/code_sunset/removal_candidate_query.rb,
app/jobs/code_sunset/evaluate_alerts_job.rb,
app/models/code_sunset/application_record.rb,
app/helpers/code_sunset/application_helper.rb,
app/mailers/code_sunset/application_mailer.rb,
app/jobs/code_sunset/flush_buffered_events_job.rb,
app/controllers/code_sunset/features_controller.rb,
app/controllers/code_sunset/dashboard_controller.rb,
app/jobs/code_sunset/aggregate_daily_rollups_job.rb,
app/controllers/code_sunset/application_controller.rb,
lib/generators/code_sunset/install/install_generator.rb,
lib/generators/code_sunset/eject_ui/eject_ui_generator.rb,
lib/generators/code_sunset/migration/migration_generator.rb,
app/controllers/code_sunset/removal_candidates_controller.rb,
lib/generators/code_sunset/initializer/initializer_generator.rb
Defined Under Namespace
Modules: ApplicationHelper, ControllerContext, Generators, JobContext
Classes: AggregateDailyRollupsJob, AlertDelivery, AlertDispatcher, AnalyticsFilters, ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, CleanupEventsJob, Configuration, Context, DailyRollup, DashboardController, Engine, EvaluateAlertsJob, Event, EventBuffer, EventIngestor, EventPayload, Feature, FeatureQuery, FeatureSnapshot, FeatureUsageSeries, FeaturesController, FlushBufferedEventsJob, IdentityHash, Instrumentation, PersistEventJob, RemovalCandidateQuery, RemovalCandidatesController, RemovalPromptArtifact, RemovalPromptBuilder, ScoreCalculator, StatusEngine, Subscriber
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
37
38
39
|
# File 'lib/code_sunset.rb', line 37
def configuration
@configuration ||= Configuration.new
end
|
41
42
43
|
# File 'lib/code_sunset.rb', line 41
def configure
yield(configuration)
end
|
.enabled? ⇒ Boolean
49
50
51
|
# File 'lib/code_sunset.rb', line 49
def enabled?
configuration.enabled
end
|
.event_buffer ⇒ Object
53
54
55
|
# File 'lib/code_sunset.rb', line 53
def event_buffer
@event_buffer ||= CodeSunset::EventBuffer.new
end
|
.hit(feature_key, **attrs) ⇒ Object
57
58
59
|
# File 'lib/code_sunset.rb', line 57
def hit(feature_key, **attrs)
Instrumentation.hit(feature_key, **attrs)
end
|
.log_error(message, error) ⇒ Object
98
99
100
|
# File 'lib/code_sunset.rb', line 98
def log_error(message, error)
logger.error("[code_sunset] #{message}: #{error.class}: #{error.message}")
end
|
.logger ⇒ Object
92
93
94
95
96
|
# File 'lib/code_sunset.rb', line 92
def logger
return Rails.logger if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
@logger ||= Logger.new($stdout)
end
|
.register(feature_key, **attrs) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/code_sunset.rb', line 74
def register(feature_key, **attrs)
return unless enabled?
return unless defined?(CodeSunset::Feature)
safe_execute("register #{feature_key}") do
feature = CodeSunset::Feature.find_or_initialize_by(key: feature_key.to_s)
feature.assign_attributes(attrs.compact)
feature.save!
feature
end
end
|
.removal_candidates(filters = {}) ⇒ Object
86
87
88
89
90
|
# File 'lib/code_sunset.rb', line 86
def removal_candidates(filters = {})
return [] unless defined?(CodeSunset::RemovalCandidateQuery)
CodeSunset::RemovalCandidateQuery.new(filters).call
end
|
.reset_configuration! ⇒ Object
45
46
47
|
# File 'lib/code_sunset.rb', line 45
def reset_configuration!
@configuration = Configuration.new
end
|
.safe_execute(description = "operation") ⇒ Object
102
103
104
105
106
107
|
# File 'lib/code_sunset.rb', line 102
def safe_execute(description = "operation")
yield
rescue StandardError => error
log_error(description, error)
nil
end
|
.track(feature_key, **attrs) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/code_sunset.rb', line 61
def track(feature_key, **attrs)
hit(feature_key, **attrs)
return unless block_given?
yield
end
|
.with_context(**context) ⇒ Object
68
69
70
71
72
|
# File 'lib/code_sunset.rb', line 68
def with_context(**context)
return unless block_given?
Context.with(context) { yield }
end
|