Module: AppSendr::Helpers

Included in:
Command, Command::Base
Defined in:
lib/appsendr/helpers.rb

Instance Method Summary collapse

Instance Method Details

#credentials_fileObject



24
25
26
# File 'lib/appsendr/helpers.rb', line 24

def credentials_file
  "#{home_directory}/#{AppSendr::APPDROPPR_DIR}/credentials"
end

#credentials_setup?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/appsendr/helpers.rb', line 28

def credentials_setup?
    File.exist?(credentials_file)
end

#display(msg, newline = true) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/appsendr/helpers.rb', line 15

def display(msg, newline=true)
  if newline
    puts(msg)
  else
    print(msg)
    STDOUT.flush
  end
end

#error(msg) ⇒ Object



107
108
109
110
# File 'lib/appsendr/helpers.rb', line 107

def error(msg)
  STDERR.puts(msg)
  exit 1
end

#has_project_droppr?Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/appsendr/helpers.rb', line 47

def has_project_droppr?
    return false unless File.directory?(project_appsendr)
    return File.exist?(project_appsendr_app)
end

#home_directoryObject



3
4
5
# File 'lib/appsendr/helpers.rb', line 3

def home_directory
  running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
end

#in_project_dir?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/appsendr/helpers.rb', line 60

def in_project_dir?
    return Dir.entries(Dir.pwd).grep(/.+\.xcodeproj/).first
end

#project_appsendrObject



32
33
34
# File 'lib/appsendr/helpers.rb', line 32

def project_appsendr
    Dir.pwd+"/#{AppSendr::PROJECT_DIR}"
end

#project_appsendr_appObject



36
37
38
# File 'lib/appsendr/helpers.rb', line 36

def project_appsendr_app
   project_appsendr+"/app"
end

#read_appObject



43
44
45
# File 'lib/appsendr/helpers.rb', line 43

def read_app
    File.exists?(project_appsendr_app) and File.read(project_appsendr_app).split("\n")
end

#read_app_idObject



40
41
42
# File 'lib/appsendr/helpers.rb', line 40

def read_app_id
    File.exists?(project_appsendr_app) and File.read(project_appsendr_app).split("\n").first
end

#require_in_project_and_no_droppr(num_args, action, wrong_args, greater_than = false) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/appsendr/helpers.rb', line 85

def require_in_project_and_no_droppr(num_args,action,wrong_args,greater_than=false)
    if in_project_dir? and !has_project_droppr?
        if args.count >= num_args
            if greater_than
                return true
            elsif !greater_than and (args.count == num_args)
                return true
            else
                return false
            end
        elsif wrong_args
            error "You must include #{wrong_args}"
        end
    else
        require_project_dir(action)
        error "This app is already linked to appsendr." unless !has_project_droppr?
        
    end

    return false
end

#require_project(num_args, action, wrong_args, greater_than = false) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/appsendr/helpers.rb', line 64

def require_project(num_args,action,wrong_args,greater_than=false)
    if in_project_dir? and has_project_droppr?
        if args.count >= num_args
            if greater_than
                return true
            elsif !greater_than and (args.count == num_args)
                return true
            else
                return false
            end
        elsif wrong_args
            error "You must include #{wrong_args}"
        end
    else
        require_project_dir(action)
        require_project_droppr
    end

    return false
end

#require_project_dir(action) ⇒ Object



56
57
58
# File 'lib/appsendr/helpers.rb', line 56

def require_project_dir(action)
    error "You must be in a Xcode project directory to #{action}" unless in_project_dir?
end

#require_project_dropprObject



52
53
54
# File 'lib/appsendr/helpers.rb', line 52

def require_project_droppr
    error "Project directory doesn't exist. Have you created an app droppr for this app?" unless has_project_droppr?
end

#running_on_a_mac?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/appsendr/helpers.rb', line 11

def running_on_a_mac?
  RUBY_PLATFORM =~ /-darwin\d/
end

#running_on_windows?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/appsendr/helpers.rb', line 7

def running_on_windows?
  RUBY_PLATFORM =~ /mswin32|mingw32/
end