Class: Fastlane::Actions::SlackTrainAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/slack_train/actions/slack_train_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



31
32
33
# File 'lib/fastlane/plugin/slack_train/actions/slack_train_action.rb', line 31

def self.authors
  ["@KrauseFx"]
end

.available_optionsObject



39
40
41
# File 'lib/fastlane/plugin/slack_train/actions/slack_train_action.rb', line 39

def self.available_options
  []
end

.descriptionObject



27
28
29
# File 'lib/fastlane/plugin/slack_train/actions/slack_train_action.rb', line 27

def self.description
  "Show a train of the fastlane progress"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/fastlane/plugin/slack_train/actions/slack_train_action.rb', line 43

def self.is_supported?(platform)
  true
end

.return_valueObject



35
36
37
# File 'lib/fastlane/plugin/slack_train/actions/slack_train_action.rb', line 35

def self.return_value
  "A string that is being sent to slack"
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/slack_train/actions/slack_train_action.rb', line 4

def self.run(params)
  train_emoji = lane_context[SharedValues::SLACK_TRAIN_EMOJI]
  rail_emoji = lane_context[SharedValues::SLACK_TRAIN_RAIL]
  total_distance = lane_context[SharedValues::SLACK_TRAIN_DISTANCE]
  current_position = lane_context[SharedValues::SLACK_TRAIN_CURRENT_TRAIN_POSITION]
  speed = lane_context[SharedValues::SLACK_TRAIN_DIRECTION]
  return if total_distance.nil? # train hasn't started yet

  UI.user_error!("train drove too far") if current_position < 0
  UI.user_error!("train drove too far") if total_distance == current_position

  before = rail_emoji * current_position
  after = rail_emoji * (total_distance - current_position - 1)
  lane_name = lane_context[SharedValues::LANE_NAME]

  message = ["`#{lane_name}` ", before, train_emoji, after].join("")
  other_action.slack(message: message,
            default_payloads: [])
  UI.message(message)

  lane_context[SharedValues::SLACK_TRAIN_CURRENT_TRAIN_POSITION] += speed
end