Module: Autowow::Features::Gem

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

Instance Method Summary collapse

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, #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

#bump_readme_version_information(version) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/autowow/features/gem.rb', line 83

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



67
68
69
# File 'lib/autowow/features/gem.rb', line 67

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

#change_readme_version_information_to_development(version) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/autowow/features/gem.rb', line 106

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

Returns:

  • (Boolean)


127
128
129
# File 'lib/autowow/features/gem.rb', line 127

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

#db_migrateObject



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

def db_migrate
  pretty_with_output.run(rake_db_migrate)
end

#db_schemaObject



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

def db_schema
  pretty_with_output.run(rake_db_schema)
end

#db_structureObject



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

def db_structure
  pretty_with_output.run(rake_db_structure)
end

#gem_cleanObject



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

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
# File 'lib/autowow/features/gem.rb', line 14

def gem_release(version_bump = nil)
  if quiet.run!("gem push").out.clean_lines.select { |line| line.match(/Enter your RubyGems.org credentials/) }.any?
    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
    pretty.run(pull)
    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



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

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

#rubocop_parallel_autocorrectObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/autowow/features/gem.rb', line 55

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