Module: Autowow::Features::Gem

Includes:
Commands::Gem, Commands::Heroku, Commands::Vcs, Executor, EasyLogging, ReflectionUtils::CreateModuleFunctions
Defined in:
lib/autowow/features/gem.rb,
lib/autowow/features/heroku.rb

Instance Method Summary collapse

Methods included from Commands::Heroku

#cmd, #info, #migrate, #pb_reset

Methods included from Executor

#pretty, #pretty_with_output, #quiet, #tty_params

Methods included from Commands::Vcs

#add, #add_remote, #branch, #branch_force_delete, #branch_list, #changes_not_on_remote, #checkout, #cmd, #commit, #create, #current_branch, #current_branch_remote, #fetch, #git_status, #hard_reset, #merge, #pull, #push, #rebase, #remotes, #set_upstream, #stash, #stash_pop, #terminal_options

Methods included from Commands::Gem

#be, #bump, #clean, #rake, #rake_db_migrate, #rake_db_schema, #rake_db_structure, #release, #rubocop_autocorrect, #rubocop_parallel

Instance Method Details

#app_nameObject



9
10
11
# File 'lib/autowow/features/heroku.rb', line 9

def app_name
  quiet.run(info).out.clean_lines.select { |line| line.start_with?("===") }.first.split(" ").last
end

#bump_readme_version_information(version) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/autowow/features/gem.rb', line 88

def bump_readme_version_information(version)
  readme = "README.md"
  return unless File.exists?(readme)
  text = File.read(readme)
  return unless contains_version_information?(text)

  version_information = get_version_information(text)
    
  new_version_information = if version_information.include?("development version")
    releases_link = version_information.match(/\[.+\]\(.+\)/)[0].split("(")[1].split("/tag")[0]
    <<-HEREDOC
<!--- Version informartion -->
*You are viewing the README of version [v#{version}](#{releases_link}/tag/v#{version}). You can find other releases [here](#{releases_link}).*
<!--- Version informartion end -->
    HEREDOC
  else
    version_information.gsub(/[0-9]\.[0-9]\.[0-9]/, version)
  end
    
  text.gsub!(version_information, new_version_information.chomp)
  File.write(readme, text)
end

#bundle_exec(cmd) ⇒ Object



72
73
74
# File 'lib/autowow/features/gem.rb', line 72

def bundle_exec(cmd)
  Autowow::Executor.pretty_with_output.run(["bundle", "exec"] + cmd)
end

#change_readme_version_information_to_development(version) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/autowow/features/gem.rb', line 111

def change_readme_version_information_to_development(version)
  readme = "README.md"
  return false unless File.file?(readme)
  text = File.read(readme)
  return false unless contains_version_information?(text)
  version_information = get_version_information(text)
  return false if version_information.include?("development version")

  releases_link = version_information.match(/\[.+\]\(.+\)/)[0].split("(")[1].split("/tag")[0]

  new_version_information = <<-HEREDOC
<!--- Version informartion -->
*You are viewing the README of the development version. You can find the README of the latest release (v#{version}) [here](#{releases_link}/tag/v#{version}).*
<!--- Version informartion end -->
  HEREDOC

  text.gsub!(version_information, new_version_information.chomp)
  File.write(readme, text)
  true
end

#contains_version_information?(text) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/autowow/features/gem.rb', line 132

def contains_version_information?(text)
  text.match(/<!--- Version informartion -->(.+)<!--- Version informartion end -->/m).length > 0
end

#db_migrateObject



76
77
78
# File 'lib/autowow/features/gem.rb', line 76

def db_migrate
  pretty_with_output.run(rake_db_migrate)
end

#db_schemaObject



80
81
82
# File 'lib/autowow/features/gem.rb', line 80

def db_schema
  pretty_with_output.run(rake_db_schema)
end

#db_structureObject



84
85
86
# File 'lib/autowow/features/gem.rb', line 84

def db_structure
  pretty_with_output.run(rake_db_structure)
end

#gem_cleanObject



56
57
58
# File 'lib/autowow/features/gem.rb', line 56

def gem_clean
  pretty_with_output.run(clean)
end

#gem_release(version_bump = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/autowow/features/gem.rb', line 14

def gem_release(version_bump = nil)
  unless rubygems_credentials_set?
    logger.error("Set RubyGems credentials first via `gem push`")
    return
  end
  pretty_with_output.run(git_status)
  start_branch = Vcs.working_branch
  logger.error("Not on master.") and return unless start_branch.eql?("master")
  pretty.run(pull)
  version = nil

  if version_bump
    version = pretty_with_output.run(bump(version_bump)).out.clean_lines.select { |line| line.match(/Bumping|bump/) }.first.split(" ").last
    bump_readme_version_information(version)
    # Full command is needed because of faulty escaping otherwise
    pretty.run("git add README.md *version.rb")
    pretty.run("git commit -m \"Bumps version to v#{version}\"")
  end

  pretty.run(push)

  Vcs.on_branch("release") do
    result = pretty.run!(pull)
    pretty_with_output.run(set_upstream("origin", "release")) unless result.success?
    pretty.run(rebase(start_branch))
    pretty_with_output.run(release)
  end

  if version && change_readme_version_information_to_development(version)
    pretty.run(add(["README.md"]))
    # Full command is needed because of faulty escaping otherwise
    pretty.run("git commit -m \"Changes README to development version\"")
    pretty.run(push)
  end

  pretty_with_output.run(git_status)
end

#get_version_information(text) ⇒ Object



136
137
138
# File 'lib/autowow/features/gem.rb', line 136

def get_version_information(text)
  text.match(/<!--- Version informartion -->(.+)<!--- Version informartion end -->/m)[0]
end

#rubocop_parallel_autocorrectObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/autowow/features/gem.rb', line 60

def rubocop_parallel_autocorrect
  pastel = Pastel.new
  result = pretty_with_output.run!(rubocop_parallel)
  if result.failed?
    filtered = result.out.each_line.select { |line| line.match(%r{(.*):([0-9]*):([0-9]*):}) }
                 .map { |line| line.split(":")[0] }
                 .uniq
                 .map { |line| pastel.strip(line) }
    pretty_with_output.run(rubocop_autocorrect(filtered)) if filtered.any?
  end
end

#rubygems_credentials_set?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/autowow/features/gem.rb', line 52

def rubygems_credentials_set?
  !quiet.run!("gem push --silent").err.clean_lines.blank?
end