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, #build, #bump, #bundle_install, #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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/autowow/features/gem.rb', line 100

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]
    "<!--- Version informartion -->\n*You are viewing the README of version [v\#{version}](\#{releases_link}/tag/v\#{version}). You can find other releases [here](\#{releases_link}).*\n<!--- Version informartion end -->\n    HEREDOC\n  else\n    version_information.gsub(/[0-9]\\.[0-9]\\.[0-9]/, version)\n  end\n    \n  text.gsub!(version_information, new_version_information.chomp)\n  File.write(readme, text)\nend\n"

#bundle_exec(cmd) ⇒ Object



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

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

#change_readme_version_information_to_development(version) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/autowow/features/gem.rb', line 123

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 = "<!--- Version informartion -->\n*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}).*\n<!--- Version informartion end -->\n  HEREDOC\n\n  text.gsub!(version_information, new_version_information.chomp)\n  File.write(readme, text)\n  true\nend\n"

#contains_version_information?(text) ⇒ Boolean



144
145
146
# File 'lib/autowow/features/gem.rb', line 144

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

#db_migrateObject



88
89
90
# File 'lib/autowow/features/gem.rb', line 88

def db_migrate
  pretty_with_output.run(rake_db_migrate)
end

#db_schemaObject



92
93
94
# File 'lib/autowow/features/gem.rb', line 92

def db_schema
  pretty_with_output.run(rake_db_schema)
end

#db_structureObject



96
97
98
# File 'lib/autowow/features/gem.rb', line 96

def db_structure
  pretty_with_output.run(rake_db_structure)
end

#gem_cleanObject



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

def gem_clean
  pretty_with_output.run(clean)
end

#gem_install_sourceObject



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

def gem_install_source
  pretty_with_output.run("gem build *.gemspec")
  pretty_with_output.run("gem install *.gem")
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
51
# 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)
  pretty_with_output.run(bundle_install)
  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("to ").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



148
149
150
# File 'lib/autowow/features/gem.rb', line 148

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

#rubocop_parallel_autocorrectObject



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

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

#ruby_checkObject



77
78
79
80
81
# File 'lib/autowow/features/gem.rb', line 77

def ruby_check
  rubocop_parallel_autocorrect
  bundle_exec(["rspec"])
  pretty_with_output.run(git_status)
end

#rubygems_credentials_set?Boolean



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

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