Class: Stenographer::Change
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Stenographer::Change
- Defined in:
- app/models/stenographer/change.rb
Constant Summary collapse
- VALID_CHANGE_TYPES =
Stenographer.change_types
Class Method Summary collapse
Instance Method Summary collapse
- #environments_to_tags ⇒ Object
- #matches_filters(output = nil) ⇒ Object
- #sanitize_environment ⇒ Object
- #to_markdown(truncate: nil) ⇒ Object
Class Method Details
.create_or_update_by_source_id(change_params) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/stenographer/change.rb', line 59 def self.create_or_update_by_source_id(change_params) source_id = change_params[:source_id] if source_id.present? && (change = Change.find_by(source_id: source_id)).present? change.environments += ", #{change_params[:environments]}" change.save else Change.create(change_params) end end |
Instance Method Details
#environments_to_tags ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/stenographer/change.rb', line 45 def = [] environment_array = environments.split(',').map(&:strip) environment_array.each do |environment| << { name: environment.capitalize, color: environment == 'production' ? 'is-primary' : 'is-light' } end end |
#matches_filters(output = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/stenographer/change.rb', line 29 def matches_filters(output = nil) return false if output.blank? filters = output.filters_hash return true if filters.empty? filters.none? do |key, value| if value.present? && key == :environments environments_array = environments.split(',').map(&:strip) environments_array.last != value.strip else value.present? && send(key) != value end end end |
#sanitize_environment ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/models/stenographer/change.rb', line 14 def sanitize_environment if environments.present? environments_array = environments.split(',').map do |environment| environment.downcase.strip end environments_array.uniq! environments_array.join(', ') end end |
#to_markdown(truncate: nil) ⇒ Object
24 25 26 27 |
# File 'app/models/stenographer/change.rb', line 24 def to_markdown(truncate: nil) msg = truncate ? .truncate(truncate) : Stenographer.markdown_renderer.render(msg).html_safe end |