Skip to content

Commit

Permalink
Rubocop improved: Metrics/LineLength: 194 -> 120
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Jun 24, 2015
1 parent 955e564 commit 80e637f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Expand Up @@ -53,10 +53,10 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 17

# Offense count: 158
# Offense count: 149
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 194
Max: 120

# Offense count: 32
# Configuration parameters: CountComments.
Expand Down
3 changes: 2 additions & 1 deletion src/ruby/yast/builtins.rb
Expand Up @@ -147,7 +147,8 @@ def self.maplist(object, &block)
# - Removes element from a list
# - Remove key/value pair from a map
# - Remove item from term
# @deprecated use native ruby method {::Hash#delete},{::Array#delete_at} or {Yast::Term#params} (call delete_at on term params)
# @deprecated use native ruby method {::Hash#delete}, {::Array#delete_at}
# or {Yast::Term#params} (call delete_at on term params)
def self.remove(object, element)
return nil if object.nil?

Expand Down
3 changes: 2 additions & 1 deletion src/ruby/yast/exportable.rb
Expand Up @@ -27,7 +27,8 @@ def published_variables
# Publishes function or variable to component system
# @param (Hash) options specified parameters
# @option options [String] :type specified Yast type that allows communication with type languages
# @option options [TrueClass,FalseClass] :private (false) id specified then exported only in old testsuite environment
# @option options [TrueClass,FalseClass] :private (false)
# if specified then exported only in old testsuite environment
# after convert of testsuite all private publish call can be removed
# @option options [Symbol] :variable exported variable
# @option options [Symbol] :function exported function
Expand Down
4 changes: 3 additions & 1 deletion src/ruby/yast/i18n.rb
Expand Up @@ -26,7 +26,9 @@ def textdomain(domain)
available = available_locales
if FastGettext.available_locales != available
# reload the translations, a new language is available
FastGettext.translation_repositories.keys.each { |dom| FastGettext.add_text_domain(dom, path: LOCALE_DIR) }
FastGettext.translation_repositories.keys.each do |dom|
FastGettext.add_text_domain(dom, path: LOCALE_DIR)
end
FastGettext.available_locales = available
end

Expand Down
30 changes: 20 additions & 10 deletions src/ruby/yast/yast.rb
Expand Up @@ -34,20 +34,25 @@ def path(*args)
Path.new *args
end

# Makes deep copy of object. Difference to #dup or #clone is that it copy all elements of Array, Hash, Yast::Term.
# Makes deep copy of object. Difference to #dup or #clone is
# that it copy all elements of Array, Hash, Yast::Term.
# Immutable classes is just returned.
# @param [Hash] options modifies behavior
# @option options [TrueClass,FalseClass] :full (false) make full copy even for types that is immutable in Yast builtins context
# @note String, Yast::Path and Yast::Byteblock is also immutable in sense of Yast because there is no builtin operation for string modify that do not copy it. Use :full option to copy it also.
# @option options [TrueClass,FalseClass] :full (false) make full copy
# even for types that is immutable in Yast builtins context
# @note String, Yast::Path and Yast::Byteblock is also immutable
# in sense of Yast because there is no builtin operation
# for string modify that do not copy it. Use :full option to copy it also.
# @example how to refactor generated code
# #old method where a is not need to copy and b is needed, but we plan to use full ruby features to modify strings
# # old method where a is not need to copy
# # and b is needed, but we plan to use full ruby features to modify strings
# def old(a, b)
# a = copy_arg(a)
# b = copy_arg(b)
# ...
# end
#
# #refactored method
# # refactored method
# def new(a, b)
# b = copy_arg b, :full => true
# ...
Expand Down Expand Up @@ -83,13 +88,18 @@ def deep_copy(object)

# includes module from include directory.
# given include must satisfied few restrictions.
# 1) file must contain module enclosed in Yast namespace with name constructed from path and its name
# it is constructed that all parts is upcased and also all [-_.] is replaced and next character must be upper case.
# 1) file must contain module enclosed in Yast namespace
# with name constructed from path and its name
# it is constructed that all parts is upcased
# and also all [-_.] is replaced and next character must be upper case.
# At the end is appended Include string
# example in file network/udev_lan.source.rb must be module Yast::NetworkUdevLanSourceInclude
# example in file network/udev_lan.source.rb
# must be module Yast::NetworkUdevLanSourceInclude
# 2) initialization of module must be in method with prefix initialize and rest is
# translated path, where all [-./] is replaced by underscore. Method take one parameter that is propagated target param.
# example in file network/udev_lan.source.rb initialization method will be initialize_network_udev_lan_source
# translated path, where all [-./] is replaced by underscore.
# Method take one parameter that is propagated target param.
# example in file network/udev_lan.source.rb
# initialization method will be initialize_network_udev_lan_source
# @param path [String] relative path to Y2DIR/include path with file suffix
# @param target [Class] where include module
# @deprecated use "lib" directory where you can place common ruby code without any special handling.
Expand Down
10 changes: 7 additions & 3 deletions tests/ruby/builtins_spec.rb
Expand Up @@ -87,7 +87,8 @@
expect(Yast::Builtins.splitstring("ABC", "abc")).to eq(["ABC"])

expect(Yast::Builtins.splitstring("a a", " ")).to eq(["a", "", "", "a"])
expect(Yast::Builtins.splitstring("text/with:different/separators", "/:")).to eq(["text", "with", "different", "separators"])
expect(Yast::Builtins.splitstring("text/with:different/separators", "/:"))
.to eq(["text", "with", "different", "separators"])
end

it "tests mergestring" do
Expand Down Expand Up @@ -141,7 +142,9 @@
expect(Yast::Builtins.regexpsub("aaabbb", "(.*ba)", "s_\\1_e")).to eq(nil)

# from sysconfig remove whitespaces
expect(Yast::Builtins.regexpsub(" lest test\tsrst\t", "^[ \t]*(([^ \t]*[ \t]*[^ \t]+)*)[ \t]*$", "\\1")).to eq("lest test\tsrst")
expect(Yast::Builtins.regexpsub(" lest test\tsrst\t",
"^[ \t]*(([^ \t]*[ \t]*[^ \t]+)*)[ \t]*$",
"\\1")).to eq("lest test\tsrst")
expect(Yast::Builtins.regexpsub("", "^[ \t]*(([^ \t]*[ \t]*[^ \t]+)*)[ \t]*$", "\\1")).to eq("")
expect(Yast::Builtins.regexpsub(" \t ", "^[ \t]*(([^ \t]*[ \t]*[^ \t]+)*)[ \t]*$", "\\1")).to eq("")

Expand Down Expand Up @@ -281,7 +284,8 @@
expect(Yast::Builtins.sort(["Z", "A"])).to eq(["A", "Z"])
expect(Yast::Builtins.sort([3, 2, 1])).to eq([1, 2, 3])

expect(Yast::Builtins.sort(["10", 1, 2, 10, 20, "15", 200, 5])).to eq([1, 2, 5, 10, 20, 200, "10", "15"])
expect(Yast::Builtins.sort(["10", 1, 2, 10, 20, "15", 200, 5]))
.to eq([1, 2, 5, 10, 20, 200, "10", "15"])

expect(Yast::Builtins.sort([10, 1, 20]) { |x, y| x > y }).to eq([20, 10, 1])
end
Expand Down
3 changes: 2 additions & 1 deletion tests/ruby/exportable_spec.rb
Expand Up @@ -42,6 +42,7 @@ def test(_a, _b)
end

it "tests type full specification" do
expect(MyTest.class.published_variables[:complex].type).to eq("map<string,map<list<any>,map<any,any>>>")
expect(MyTest.class.published_variables[:complex].type)
.to eq("map<string,map<list<any>,map<any,any>>>")
end
end
3 changes: 2 additions & 1 deletion tests/ruby/test_helper.rb
Expand Up @@ -5,7 +5,8 @@
FileUtils.ln_s binary_path, "#{binary_path}/yast" # to load builtinx.so
end
if !File.exist? "#{binary_path}/plugin"
FileUtils.ln_s binary_path, "#{binary_path}/plugin" # to load py2lang_ruby.so for calling testing ruby clients
# to load py2lang_ruby.so for calling testing ruby clients
FileUtils.ln_s binary_path, "#{binary_path}/plugin"
end
$LOAD_PATH.unshift binary_path # yastx.so
$LOAD_PATH.unshift "#{ROOT_DIR}/src/ruby" # yast.rb
Expand Down

0 comments on commit 80e637f

Please sign in to comment.