Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Conformance To Style Standards With RuboCop & TravisCI #71

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ ParameterLists:
AbcSize:
Max: 34

# Increase max number of "/" in %r
RegexpLiteral:
MaxSlashes: 0

# Increase the max line number of class
ClassLength:
Max: 250
Expand All @@ -30,3 +26,6 @@ CyclomaticComplexity:

PerceivedComplexity:
Max: 11

Metrics/LineLength:
Max: 100
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ install:
gem install bundler:1.14.6; bundle install

test:
rubocop
rake test
41 changes: 20 additions & 21 deletions lib/smtpapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ def set_ip_pool(pool_name)
self
end

def json_string
escape_unicode(to_array.to_json)
end
alias_method :to_json, :json_string

def escape_unicode(str)
str.unpack('U*').map do |i|
if i > 65_535
"\\u#{format('%04x', ((i - 0x10000) / 0x400 + 0xD800))}" \
"\\u#{format('%04x', ((i - 0x10000) % 0x400 + 0xDC00))}"
elsif i > 127
"\\u#{format('%04x', i)}"
else
i.chr('UTF-8')
end
end.join
end

protected

def to_array
data = {}
data['to'] = @to unless @to.empty?
Expand All @@ -132,26 +152,5 @@ def to_array

data
end

protected :to_array

def json_string
escape_unicode(to_array.to_json)
end

alias :to_json :json_string

def escape_unicode(str)
str.unpack('U*').map do |i|
if i > 65_535
"\\u#{format('%04x', ((i - 0x10000) / 0x400 + 0xD800))}" \
"\\u#{format('%04x', ((i - 0x10000) % 0x400 + 0xDC00))}"
elsif i > 127
"\\u#{format('%04x', i)}"
else
i.chr('UTF-8')
end
end.join
end
end
end
4 changes: 2 additions & 2 deletions smtpapi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^(test|spec|features)/)
spec.require_paths = ['lib']

spec.add_development_dependency 'rake'
Expand Down