<commit_before>#
# Cookbook Name:: chef-jellyfish
# Recipe:: api
#
# Copyright 2015, <NAME>
#
# All rights reserved - Do Not Redistribute
#
node.set['rbenv']['root']          = rbenv_root_path
node.set['ruby_build']['prefix'] = "#{node['rbenv']['root']}/plugins/ruby_build"
node.set['ruby_build']['bin_path'] = "#{node['ruby_build']['prefix']}/bin"

log 'Create jellyfish user'
user node['jellyfish']['user'] do
  comment 'jellyfish user'
  shell '/bin/bash'
end.run_action(:create)

log 'Install Pre-Requisites'
yum_package 'git'
yum_package 'gcc-c++'
yum_package 'patch'
yum_package 'readline'
yum_package 'readline-devel'
yum_package 'zlib'
yum_package 'zlib-devel'
yum_package 'libyaml-devel'
yum_package 'libffi-devel'
yum_package 'openssl-devel'
yum_package 'make'
yum_package 'bzip2'
yum_package 'autoconf'
yum_package 'automake'
yum_package 'libtool'
yum_package 'bison'
yum_package 'sqlite-devel'
yum_package 'unzip' do
  action :install
end.run_action(:install)

log 'Checkout the latest code'
remote_file "#{node['rbenv']['user_home']}/api-master.zip" do
  source 'https://github.com/projectjellyfish/api/archive/master.zip'
  mode '0644'
end.run_action(:create)

bash 'unzip api-master.zip' do
  cwd node['rbenv']['user_home']
  user node['jellyfish']['user']
  code <<-EOH
  /usr/bin/unzip api-master.zip && /bin/mv api-master api
  EOH
  creates "#{node['rbenv']['user_home']}/api"
end.run_action(:run)

node.set['rvp'] = "#{node['rbenv']['user_home']}/api/.ruby-version"
ruby_version = File.read("#{node['rvp']}").strip
log("ruby version #{ruby_version}")
node.set['gd1'] = "#{node['rbenv']['root_path']}/version/#{ruby_version}"
node.set['gd2'] = "/lib/ruby/gems/#{ruby_version}/gems"
node.set['rbenv']['gem_directory'] = "#{node['gd1']}/#{node['gd2']}"
node.set['gem_exec'] = "#{node['rbenv']['ver_dir']}/#{ruby_version}/bin/gem"
node.set['rbenv']['installed'] = "#{node['rbenv']['ver_dir']}/#{ruby_version}"

directory "#{node['rbenv']['user_home']}/.rbenv" do
  owner node['jellyfish']['user']
  group node['jellyfish']['group']
  mode '0755'
  action :create
end

git "#{node['rbenv']['user_home']}/.rbenv" do<commit_msg>removed quotes around line 57 because food critic was complaining that there was no string interpolation<commit_after>#
# Cookbook Name:: chef-jellyfish
# Recipe:: api
#
# Copyright 2015, <NAME>
#
# All rights reserved - Do Not Redistribute
#
node.set['rbenv']['root']          = rbenv_root_path
node.set['ruby_build']['prefix'] = "#{node['rbenv']['root']}/plugins/ruby_build"
node.set['ruby_build']['bin_path'] = "#{node['ruby_build']['prefix']}/bin"

log 'Create jellyfish user'
user node['jellyfish']['user'] do
  comment 'jellyfish user'
  shell '/bin/bash'
end.run_action(:create)

log 'Install Pre-Requisites'
yum_package 'git'
yum_package 'gcc-c++'
yum_package 'patch'
yum_package 'readline'
yum_package 'readline-devel'
yum_package 'zlib'
yum_package 'zlib-devel'
yum_package 'libyaml-devel'
yum_package 'libffi-devel'
yum_package 'openssl-devel'
yum_package 'make'
yum_package 'bzip2'
yum_package 'autoconf'
yum_package 'automake'
yum_package 'libtool'
yum_package 'bison'
yum_package 'sqlite-devel'
yum_package 'unzip' do
  action :install
end.run_action(:install)

log 'Checkout the latest code'
remote_file "#{node['rbenv']['user_home']}/api-master.zip" do
  source 'https://github.com/projectjellyfish/api/archive/master.zip'
  mode '0644'
end.run_action(:create)

bash 'unzip api-master.zip' do
  cwd node['rbenv']['user_home']
  user node['jellyfish']['user']
  code <<-EOH
  /usr/bin/unzip api-master.zip && /bin/mv api-master api
  EOH
  creates "#{node['rbenv']['user_home']}/api"
end.run_action(:run)

node.set['rvp'] = "#{node['rbenv']['user_home']}/api/.ruby-version"
ruby_version = File.read(#{node['rvp']}).strip
log("ruby version #{ruby_version}")
node.set['gd1'] = "#{node['rbenv']['root_path']}/version/#{ruby_version}"
node.set['gd2'] = "/lib/ruby/gems/#{ruby_version}/gems"
node.set['rbenv']['gem_directory'] = "#{node['gd1']}/#{node['gd2']}"
node.set['gem_exec'] = "#{node['rbenv']['ver_dir']}/#{ruby_version}/bin/gem"
node.set['rbenv']['installed'] = "#{node['rbenv']['ver_dir']}/#{ruby_version}"

directory "#{node['rbenv']['user_home']}/.rbenv" do
  owner node['jellyfish']['user']
  group node['jellyfish']['group']
  mode '0755'
  action :create
end

git "#{node['rbenv']['user_home']}/.rbenv" do
{'fraction_non_alphanumeric': 0.20544497826584307, 'fraction_numerical': 0.008236101578586136, 'mean_word_length': 6.643356643356643, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '602043', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1675, 'n_words': 296}