Module: Atlantis::Portal::Helpers
- Defined in:
- lib/Atlantis/portal/helpers.rb
Instance Method Summary collapse
- #agent ⇒ Object
- #arguments ⇒ Object
- #output(title, fields, data) ⇒ Object
- #pluralize(n, singular, plural = nil) ⇒ Object
- #service ⇒ Object
- #try ⇒ Object
Instance Method Details
#agent ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/Atlantis/portal/helpers.rb', line 28 def agent unless @agent # # Web connecting agent # @agent = Atlantis::Portal::Agent.new @agent.instance_eval do def username @username ||= ask "Username:" end def password @password ||= pw "Password:" end end end @agent end |
#arguments ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/Atlantis/portal/helpers.rb', line 20 def arguments unless @arguments @arguments = Atlantis::Portal::CommandArguments.new end @arguments end |
#output(title, fields, data) ⇒ Object
77 78 79 80 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 108 109 110 111 112 113 |
# File 'lib/Atlantis/portal/helpers.rb', line 77 def output (title, fields, data) if arguments.format == "csv" output_string = CSV.generate do |csv| csv << fields data.each do |row| csv << array_for_object(fields, row) end end elsif arguments.format == "json" objects = [] data.each do |row| object = {} fields.each do |field| object[field.downcase] = row[field.downcase] end objects << object end output_string = JSON.generate(objects) else output_string = Terminal::Table.new :title => title do |t| t << fields t.add_separator data.each do |row| t << array_for_object(fields, row) end end end puts output_string end |
#pluralize(n, singular, plural = nil) ⇒ Object
61 62 63 |
# File 'lib/Atlantis/portal/helpers.rb', line 61 def pluralize(n, singular, plural = nil) n.to_i == 1 ? "1 #{singular}" : "#{n} #{plural || singular + 's'}" end |
#service ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/Atlantis/portal/helpers.rb', line 51 def service unless @service @service = arguments.service.casecmp('crashlytics') == 0 ? Atlantis::Portal::CrashlyticsService.new : Atlantis::Portal::TestFlightService.new @service.arguments = arguments end @service end |
#try ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/Atlantis/portal/helpers.rb', line 65 def try return unless block_given? begin yield rescue UnsuccessfulAuthenticationError say_error "Could not authenticate with the service. Check that your username & password are correct, and that your membership is valid and all pending Terms of Service & agreements are accepted. If this problem continues, try logging into the service from a browser to see what's going on." and abort rescue UnknownTeamError say_error "Could not find the specified team. Check if your team parameter is correct." end end |