Skip to content

Commit

Permalink
Merge pull request #144 from yahonda/add_some_more_cops
Browse files Browse the repository at this point in the history
Follow Oracle enhanced adapter rubocop configurations
  • Loading branch information
yahonda committed Jan 13, 2018
2 parents 370c997 + 6d447f9 commit 9628895
Show file tree
Hide file tree
Showing 34 changed files with 1,720 additions and 1,618 deletions.
22 changes: 22 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
checks:
argument-count:
enabled: false
complex-logic:
enabled: false
file-lines:
enabled: false
method-complexity:
enabled: false
method-count:
enabled: false
method-lines:
enabled: false
nested-control-flow:
enabled: false
return-statements:
enabled: false
similar-code:
enabled: false
identical-code:
enabled: false

engines:
rubocop:
enabled: true
Expand Down
139 changes: 137 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,145 @@ AllCops:
TargetRubyVersion: 2.1
DisabledByDefault: true

# No trailing whitespace.
Layout/TrailingWhitespace:
# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

# Do not use braces for hash literals when they are the last argument of a
# method call.
Style/BracesAroundHashParameters:
Enabled: true
EnforcedStyle: context_dependent

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

# No extra empty lines.
Layout/EmptyLines:
Enabled: true

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstParameterIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: rails

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceAroundOperators:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Style/DefWithParentheses:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: false
EnforcedStyle: always

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

# Detect hard tabs, no hard tabs.
Layout/Tab:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingBlankLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: true

# Use quotes for string literals when they are enough.
Style/UnneededPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Lint/EndAlignment:
Enabled: false
EnforcedStyleAlignWith: variable

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: true
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true
20 changes: 10 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
source 'http://rubygems.org'
source "http://rubygems.org"

group :development do
gem 'juwelier', '~> 2.0'
gem 'rspec_junit_formatter'
gem "juwelier", "~> 2.0"
gem "rspec_junit_formatter"
end

group :test, :development do
gem 'rake', '>= 10.0'
gem 'rspec', '~> 3.1'
gem "rake", ">= 10.0"
gem "rspec", "~> 3.1"

unless ENV['NO_ACTIVERECORD']
gem 'activerecord', '>= 3.2.3', '< 5.2.0'
gem 'activerecord-oracle_enhanced-adapter', '>= 1.4.1', '< 1.9.0'
gem 'simplecov', '>= 0'
unless ENV["NO_ACTIVERECORD"]
gem "activerecord", ">= 3.2.3", "< 5.2.0"
gem "activerecord-oracle_enhanced-adapter", ">= 1.4.1", "< 1.9.0"
gem "simplecov", ">= 0"
end

platforms :ruby, :mswin, :mingw do
gem 'ruby-oci8', '~> 2.1'
gem "ruby-oci8", "~> 2.1"
end
end
28 changes: 14 additions & 14 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rubygems'
require 'bundler'
require "rubygems"
require "bundler"
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
Expand All @@ -8,10 +8,10 @@ rescue Bundler::BundlerError => e
exit e.status_code
end

require 'rake'
require "rake"

begin
require 'juwelier'
require "juwelier"
Juwelier::Tasks.new do |gem|
gem.name = "ruby-plsql"
gem.summary = "Ruby API for calling Oracle PL/SQL procedures."
Expand All @@ -24,30 +24,30 @@ begin
gem.homepage = "http://github.com/rsim/ruby-plsql"
gem.license = "MIT".freeze
gem.authors = ["Raimonds Simanovskis"]
gem.extra_rdoc_files = ['README.md']
gem.extra_rdoc_files = ["README.md"]
end
Juwelier::RubygemsDotOrgTasks.new
rescue LoadError
# juwelier not installed
end

require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

desc "Code coverage detail"
task :simplecov do
ENV['COVERAGE'] = "true"
Rake::Task['spec'].execute
ENV["COVERAGE"] = "true"
Rake::Task["spec"].execute
end

task :default => :spec
task default: :spec

require 'rdoc/task'
require "rdoc/task"
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
version = File.exist?("VERSION") ? File.read("VERSION") : ""

rdoc.rdoc_dir = 'doc'
rdoc.rdoc_dir = "doc"
rdoc.title = "ruby-plsql #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end
4 changes: 2 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision :shell, inline: "mkdir -p /opt/oracle"
config.vm.provision :shell, inline: "unzip -o -q -d /opt/oracle /vagrant/oracle-xe-11.2.0-1.0.x86_64.rpm.zip"
config.vm.provision :shell, inline: "cd /opt/oracle/Disk1 && rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm"
config.vm.provision :shell, inline: %q{sed -i -E "s/<value required>/oracle/" /opt/oracle/Disk1/response/xe.rsp}
config.vm.provision :shell, inline: 'sed -i -E "s/<value required>/oracle/" /opt/oracle/Disk1/response/xe.rsp'
config.vm.provision :shell, inline: "/etc/init.d/oracle-xe configure responseFile=/opt/oracle/Disk1/response/xe.rsp >> /opt/oracle/XEsilentinstall.log"
config.vm.provision :shell, inline: ". /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh"
config.vm.provision :shell, inline: "touch /etc/profile.d/oracle_profile.sh && cat /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh >> /etc/profile.d/oracle_profile.sh"
config.vm.provision :shell, inline: %q{sed -i -E "s/HOST = [^)]+/HOST = $HOSTNAME/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora}
config.vm.provision :shell, inline: 'sed -i -E "s/HOST = [^)]+/HOST = $HOSTNAME/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora'
config.vm.provision :shell, inline: %q{sed -i -E "s/<ORACLE_BASE>/\/u01\/app\/oracle/" /u01/app/oracle/product/11.2.0/xe/dbs/init.ora}

# Change password for Oracle user
Expand Down
28 changes: 13 additions & 15 deletions lib/plsql/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def self.create(raw_conn, ar_class = nil) #:nodoc:

def self.create_new(params) #:nodoc:
conn = case driver_type
when :oci
OCIConnection.create_raw(params)
when :jdbc
JDBCConnection.create_raw(params)
when :oci
OCIConnection.create_raw(params)
when :jdbc
JDBCConnection.create_raw(params)
else
raise ArgumentError, "Unknown raw driver"
raise ArgumentError, "Unknown raw driver"
end
conn.set_time_zone(params[:time_zone]||ENV['ORA_SDTZ'])
conn.set_time_zone(params[:time_zone] || ENV["ORA_SDTZ"])
conn
end

Expand Down Expand Up @@ -99,14 +99,14 @@ def prefetch_rows=(value)
end

def select_first(sql, *bindvars) #:nodoc:
cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1)
cursor = cursor_from_query(sql, bindvars, prefetch_rows: 1)
cursor.fetch
ensure
cursor.close rescue nil
end

def select_hash_first(sql, *bindvars) #:nodoc:
cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1)
cursor = cursor_from_query(sql, bindvars, prefetch_rows: 1)
cursor.fetch_hash
ensure
cursor.close rescue nil
Expand Down Expand Up @@ -183,7 +183,7 @@ def fetch_hash
# this implementation is overriden in OCI connection with faster native OCI method
def describe_synonym(schema_name, synonym_name) #:nodoc:
select_first(
"SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name",
"SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name",
schema_name.to_s.upcase, synonym_name.to_s.upcase)
end

Expand All @@ -198,7 +198,7 @@ def session_id
end

# Set time zone
def set_time_zone(time_zone=nil)
def set_time_zone(time_zone = nil)
exec("alter session set time_zone = '#{time_zone}'") if time_zone
end

Expand All @@ -207,12 +207,12 @@ def time_zone
select_first("SELECT SESSIONTIMEZONE FROM dual")[0]
end

RUBY_TEMP_TABLE_PREFIX = 'ruby_'
RUBY_TEMP_TABLE_PREFIX = "ruby_"

# Drop all ruby temporary tables that are used for calling packages with table parameter types defined in packages
def drop_all_ruby_temporary_tables
select_all("SELECT table_name FROM user_tables WHERE temporary='Y' AND table_name LIKE :table_name",
RUBY_TEMP_TABLE_PREFIX.upcase+'%').each do |row|
RUBY_TEMP_TABLE_PREFIX.upcase + "%").each do |row|
exec "TRUNCATE TABLE #{row[0]}"
exec "DROP TABLE #{row[0]}"
end
Expand All @@ -221,12 +221,10 @@ def drop_all_ruby_temporary_tables
# Drop ruby temporary tables created in current session that are used for calling packages with table parameter types defined in packages
def drop_session_ruby_temporary_tables
select_all("SELECT table_name FROM user_tables WHERE temporary='Y' AND table_name LIKE :table_name",
RUBY_TEMP_TABLE_PREFIX.upcase+"#{session_id}_%").each do |row|
RUBY_TEMP_TABLE_PREFIX.upcase + "#{session_id}_%").each do |row|
exec "TRUNCATE TABLE #{row[0]}"
exec "DROP TABLE #{row[0]}"
end
end

end

end
2 changes: 0 additions & 2 deletions lib/plsql/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module PLSQL #:nodoc:
module ArrayHelpers #:nodoc:

def self.to_hash(keys, values) #:nodoc:
(0...keys.size).inject({}) { |hash, i| hash[keys[i]] = values[i]; hash }
end

end
end
Loading

0 comments on commit 9628895

Please sign in to comment.