Module: PgEventstore::Web::Subscriptions::Helpers
- Defined in:
- lib/pg_eventstore/web/subscriptions/helpers.rb
Instance Method Summary collapse
- #alive?(interval, last_updated_at) ⇒ Boolean
-
#colored_state(state, interval, updated_at) ⇒ String
Html status.
- #delete_all_subscriptions_url(ids) ⇒ String
- #delete_event_url(global_position) ⇒ String
- #delete_stream_url(stream_attrs) ⇒ String
-
#subscription_cmd(cmd_name) ⇒ String
Command name.
- #subscription_cmd_url(set_id, id, cmd) ⇒ String
-
#subscriptions_set_cmd(cmd_name) ⇒ String
Command name.
- #subscriptions_set_cmd_url(id, cmd) ⇒ String
- #subscriptions_state ⇒ String?
- #subscriptions_state_url(state:, **params) ⇒ String
- #subscriptions_url(set_name: nil) ⇒ String
- #validate_subscription_cmd(cmd_name) ⇒ void
- #validate_subscriptions_set_cmd(cmd_name) ⇒ void
Instance Method Details
#alive?(interval, last_updated_at) ⇒ Boolean
112 113 114 115 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 112 def alive?(interval, last_updated_at) # -1 is added as a margin to prevent false-positive result last_updated_at > Time.now.utc - interval - 1 end |
#colored_state(state, interval, updated_at) ⇒ String
Returns html status.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 81 def colored_state(state, interval, updated_at) text_class = case state when RunnerState::STATES[:running] alive?(interval, updated_at) ? 'text-success' : 'text-warning' when RunnerState::STATES[:dead] 'text-danger' else 'text-info' end if alive?(interval, updated_at) " <span class=\"\#{text_class}\">\#{state}</span>\n HTML\n else\n title = <<~TEXT\n Something is wrong. Last update was more than \#{interval} seconds ago(\#{updated_at}).\n TEXT\n <<~HTML\n <span class=\"\#{text_class} text-nowrap\">\n \#{state}\n <i class=\"fa fa-question-circle\" data-toggle=\"tooltip\" title=\"\#{title}\"></i>\n </span>\n HTML\n end\nend\n" |
#delete_all_subscriptions_url(ids) ⇒ String
119 120 121 122 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 119 def delete_all_subscriptions_url(ids) encoded_params = Rack::Utils.build_nested_query(ids: ids) url("/delete_all_subscriptions?#{encoded_params}") end |
#delete_event_url(global_position) ⇒ String
126 127 128 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 126 def delete_event_url(global_position) url("/delete_event/#{global_position}") end |
#delete_stream_url(stream_attrs) ⇒ String
132 133 134 135 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 132 def delete_stream_url(stream_attrs) encoded_params = Rack::Utils.build_nested_query(stream_attrs) url("/delete_stream?#{encoded_params}") end |
#subscription_cmd(cmd_name) ⇒ String
Returns command name.
64 65 66 67 68 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 64 def subscription_cmd(cmd_name) validate_subscription_cmd(cmd_name) cmd_name end |
#subscription_cmd_url(set_id, id, cmd) ⇒ String
35 36 37 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 35 def subscription_cmd_url(set_id, id, cmd) url("/subscription_cmd/#{set_id}/#{id}/#{cmd}") end |
#subscriptions_set_cmd(cmd_name) ⇒ String
Returns command name.
48 49 50 51 52 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 48 def subscriptions_set_cmd(cmd_name) validate_subscriptions_set_cmd(cmd_name) cmd_name end |
#subscriptions_set_cmd_url(id, cmd) ⇒ String
42 43 44 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 42 def subscriptions_set_cmd_url(id, cmd) url("/subscriptions_set_cmd/#{id}/#{cmd}") end |
#subscriptions_state ⇒ String?
27 28 29 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 27 def subscriptions_state params[:state] if PgEventstore::RunnerState::STATES.values.include?(params[:state]) end |
#subscriptions_state_url(state:, **params) ⇒ String
18 19 20 21 22 23 24 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 18 def subscriptions_state_url(state:, **params) params = params.compact return url("/subscriptions/#{state}") if params.empty? encoded_params = Rack::Utils.build_nested_query(params) url("/subscriptions/#{state}?#{encoded_params}") end |
#subscriptions_url(set_name: nil) ⇒ String
9 10 11 12 13 14 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 9 def subscriptions_url(set_name: nil) return url('/subscriptions') unless set_name encoded_params = Rack::Utils.build_nested_query(set_name: set_name) url("/subscriptions?#{encoded_params}") end |
#validate_subscription_cmd(cmd_name) ⇒ void
This method returns an undefined value.
73 74 75 76 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 73 def validate_subscription_cmd(cmd_name) cmd_class = SubscriptionRunnerCommands.command_class(cmd_name) raise "Subscription command #{cmd_name.inspect} does not exist" unless cmd_class.known_command? end |
#validate_subscriptions_set_cmd(cmd_name) ⇒ void
This method returns an undefined value.
57 58 59 60 |
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 57 def validate_subscriptions_set_cmd(cmd_name) cmd_class = SubscriptionFeederCommands.command_class(cmd_name) raise "SubscriptionsSet command #{cmd_name.inspect} does not exist" unless cmd_class.known_command? end |