Module: PgEventstore::Web::Subscriptions::Helpers

Defined in:
lib/pg_eventstore/web/subscriptions/helpers.rb

Instance Method Summary collapse

Instance Method Details

#colored_state(state, interval, updated_at) ⇒ String

Returns html status.

Parameters:

  • state (String)
  • updated_at (Time)

Returns:

  • (String)

    html status



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 81

def colored_state(state, interval, updated_at)
  if state == RunnerState::STATES[:running]
    # -1 is added as a margin to prevent false-positive result
    if updated_at < Time.now.utc - interval - 1
      title = <<~TEXT
        Something is wrong. Last update was more than #{interval} seconds ago(#{updated_at}).
      TEXT
      <<~HTML
        <span class="text-warning text-nowrap">
          #{state}
          <i class="fa fa-question-circle" data-toggle="tooltip" title="#{title}"></i>
        </span>              
      HTML
    else
      "<span class=\"text-success\">#{state}</span>"
    end
  elsif state == RunnerState::STATES[:dead]
    "<span class=\"text-danger\">#{state}</span>"
  else
    "<span class=\"text-info\">#{state}</span>"
  end
end

#delete_all_subscriptions_url(ids) ⇒ String

Parameters:

  • ids (Array<Integer>)

Returns:

  • (String)


106
107
108
109
# File 'lib/pg_eventstore/web/subscriptions/helpers.rb', line 106

def delete_all_subscriptions_url(ids)
  encoded_params = Rack::Utils.build_nested_query(ids: ids)
  url("/delete_all_subscriptions?#{encoded_params}")
end

#subscription_cmd(cmd_name) ⇒ String

Returns command name.

Parameters:

  • cmd_name (String)

    command name

Returns:

  • (String)

    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

Parameters:

  • set_id (Integer)
  • id (Integer)
  • cmd (String)

Returns:

  • (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.

Parameters:

  • cmd_name (String)

    command name

Returns:

  • (String)

    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

Parameters:

  • id (Integer)
  • cmd (String)

Returns:

  • (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_stateString?

Returns:

  • (String, nil)


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

Parameters:

  • state (String)

Returns:

  • (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

Parameters:

  • set_name (String, nil) (defaults to: nil)

Returns:

  • (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.

Parameters:

  • cmd_name (String)

Raises:

  • (RuntimeError)

    in case if command class is not found



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.

Parameters:

  • cmd_name (String)

Raises:

  • (RuntimeError)

    in case if command class is not found



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