Skip to content

Commit

Permalink
Merge a353864 into 51e8f92
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Earle committed May 16, 2018
2 parents 51e8f92 + a353864 commit 59e86d3
Show file tree
Hide file tree
Showing 31 changed files with 201 additions and 188 deletions.
21 changes: 21 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
inherit_gem:
rubocop-rails:
- config/rails.yml

AllCops:
TargetRubyVersion: 2.4

Style/FrozenStringLiteralComment:
Enabled: false

Style/StringLiterals:
Enabled: false

Layout/IndentationWidth:
IgnoredPatterns: ['^\s*private$']

Style/BracesAroundHashParameters:
Enabled: false

Metrics/LineLength:
Max: 100
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## Unreleased

### Added

- [TT-4020] Implemented Rubocop

## 0.0.1

### Added
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "bundler/gem_tasks"

desc 'Default: run specs.'
task :default => :spec
task default: :spec

require 'rspec/core/rake_task'

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails3.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
gemspec :path => '../'
gemspec path: '../'

group :development, :test do
gem 'rake'
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails4.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
gemspec :path => '../'
gemspec path: '../'

group :development, :test do
gem 'rake'
Expand Down
3 changes: 1 addition & 2 deletions lib/ruby_core_extensions/array.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Array

def to_param
self.collect { |element| element.respond_to?(:to_param) ? element.to_param : element }
end
Expand Down Expand Up @@ -31,7 +30,7 @@ def hash_by_id(method = nil, &block)
end

def intersects?(other)
self.any?{|i| other.include?(i)}
self.any? { |i| other.include?(i) }
end

# Same effect as Array.wrap(object).first
Expand Down
3 changes: 0 additions & 3 deletions lib/ruby_core_extensions/class.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class Class

def downcase_symbol
self.to_s.downcase.to_sym
end

end

3 changes: 1 addition & 2 deletions lib/ruby_core_extensions/compact/array.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Array
def compact_blank!
delete_if{|v| v.blank?}
delete_if { |v| v.blank? }
end

def recursive_compact_blank!
Expand All @@ -17,4 +17,3 @@ def recursive_compact_blank!
end
end
end

7 changes: 3 additions & 4 deletions lib/ruby_core_extensions/compact/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ def compact

# Remove nil values - !desctructively!
def compact!
delete_if{|k,v| v.nil?}
delete_if { |k, v| v.nil? }
end

def compact_blank
self.dup.compact_blank!
end

def compact_blank!
delete_if{|k,v| v.blank?}
delete_if { |k, v| v.blank? }
end

def recursive_compact_blank!
delete_if do |k,v|
delete_if do |k, v|
if v.is_a?(Hash)
v.recursive_compact_blank!
v.recursive_blank?
Expand All @@ -31,4 +31,3 @@ def recursive_compact_blank!
end
end
end

3 changes: 0 additions & 3 deletions lib/ruby_core_extensions/enumerable.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Enumerable

def map_methods(*methods)
map do |object|
methods.inject({}) do |h, method|
Expand Down Expand Up @@ -34,6 +33,4 @@ def with_object(obj, &block)
obj
end
end

end

1 change: 0 additions & 1 deletion lib/ruby_core_extensions/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ def self.safe_name(name)
gsub(/\-+/, '-') # limit - character to once
end
end

10 changes: 4 additions & 6 deletions lib/ruby_core_extensions/hash.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Hash

unless self.method_defined?(:extract!)
#Imported from Rails 3
# Imported from Rails 3
def extract!(*keys)
result = {}
keys.each { |key| result[key] = delete(key) }
Expand All @@ -12,23 +11,22 @@ def extract!(*keys)

def map_key_value(key_method, value_method = nil)
value_method ||= key_method
each.with_object({}) do |(k,v), new_hash|
each.with_object({}) do |(k, v), new_hash|
new_hash[k.send(key_method)] = v.send(value_method)
end
end


def map_key(method)
each.with_object({}) do |(k,v), new_hash|
each.with_object({}) do |(k, v), new_hash|
new_hash[k.send(method)] = v
end
end


def map_value(method)
each.with_object({}) do |(k,v), new_hash|
each.with_object({}) do |(k, v), new_hash|
new_hash[k] = v.send(method)
end
end

end
2 changes: 0 additions & 2 deletions lib/ruby_core_extensions/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module Kernel

def require_dirs(dirs)
Array.wrap(dirs).each do |load_path|
Dir.glob("#{load_path}/**/*.rb").each do |file|
require file
end
end
end

end
2 changes: 0 additions & 2 deletions lib/ruby_core_extensions/numeric.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Numeric

def to_bool
!zero?
end

end
12 changes: 5 additions & 7 deletions lib/ruby_core_extensions/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ class Object
def sounds_like?(other)
self.phonetic_code == other.phonetic_code
end

# Convert this object into a string, then convert that to phonetic code
def phonetic_code
self.to_s.phonetic_code
end

def to_long_s
to_s
end

def virtual_belongs_to(*associations)
options = associations.extract_options!

Expand Down Expand Up @@ -62,11 +62,9 @@ def #{normal_name}?(*args)
end
EVAL
end


def to_bool
self.to_s.to_bool
end

end

86 changes: 42 additions & 44 deletions lib/ruby_core_extensions/recursive/array.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
class Array

def convert
self
end
class Array
def convert
self
end

def convert_keys_recursively(&converter)
map { |v| v.convert_keys_recursively(&converter) }
end

def convert_values_recursively(&converter)
map { |v| v.convert_values_recursively(&converter) }
end

def symbolize_keys_recursively
map(&:symbolize_keys_recursively)
end

def stringify_values_recursively
map(&:stringify_values_recursively)
end

def make_indifferent_access_recursively
map(&:make_indifferent_access_recursively)
end

def recursive_blank?
each do |v|
if v.respond_to?(:recursive_blank?)
return false unless v.recursive_blank?
else
return false unless v.blank?
end
end
true
end

def recursively(&block)
each do |element|
block.call(element)
element.recursively(&block) if element.respond_to?(:recursively)
end
end

end
def convert_keys_recursively(&converter)
map { |v| v.convert_keys_recursively(&converter) }
end

def convert_values_recursively(&converter)
map { |v| v.convert_values_recursively(&converter) }
end

def symbolize_keys_recursively
map(&:symbolize_keys_recursively)
end

def stringify_values_recursively
map(&:stringify_values_recursively)
end

def make_indifferent_access_recursively
map(&:make_indifferent_access_recursively)
end

def recursive_blank?
each do |v|
if v.respond_to?(:recursive_blank?)
return false unless v.recursive_blank?
else
return false unless v.blank?
end
end
true
end

def recursively(&block)
each do |element|
block.call(element)
element.recursively(&block) if element.respond_to?(:recursively)
end
end
end
3 changes: 0 additions & 3 deletions lib/ruby_core_extensions/recursive/date.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class Date

def stringify_values_recursively
self.to_s
end

end

3 changes: 0 additions & 3 deletions lib/ruby_core_extensions/recursive/date_time.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class DateTime

def stringify_values_recursively
self.to_s
end

end

2 changes: 0 additions & 2 deletions lib/ruby_core_extensions/recursive/fixnum.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Fixnum

def stringify_values_recursively
to_s
end

end

0 comments on commit 59e86d3

Please sign in to comment.