diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
| commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
| tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/network/http/api | |
| parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
| download | puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip | |
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with
The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.
3 Examples:
The code:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
becomes:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
The code:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
becomes:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
The code:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
becomes:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
Diffstat (limited to 'lib/puppet/network/http/api')
| -rw-r--r-- | lib/puppet/network/http/api/v1.rb | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 577328589..dd4612a14 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -1,70 +1,70 @@ require 'puppet/network/http/api' module Puppet::Network::HTTP::API::V1 - # How we map http methods and the indirection name in the URI - # to an indirection method. - METHOD_MAP = { - "GET" => { - :plural => :search, - :singular => :find - }, - "PUT" => { - :singular => :save - }, - "DELETE" => { - :singular => :destroy - } + # How we map http methods and the indirection name in the URI + # to an indirection method. + METHOD_MAP = { + "GET" => { + :plural => :search, + :singular => :find + }, + "PUT" => { + :singular => :save + }, + "DELETE" => { + :singular => :destroy } + } - def uri2indirection(http_method, uri, params) - environment, indirection, key = uri.split("/", 4)[1..-1] # the first field is always nil because of the leading slash + def uri2indirection(http_method, uri, params) + environment, indirection, key = uri.split("/", 4)[1..-1] # the first field is always nil because of the leading slash - raise ArgumentError, "The environment must be purely alphanumeric, not '#{environment}'" unless environment =~ /^\w+$/ - raise ArgumentError, "The indirection name must be purely alphanumeric, not '#{indirection}'" unless indirection =~ /^\w+$/ + raise ArgumentError, "The environment must be purely alphanumeric, not '#{environment}'" unless environment =~ /^\w+$/ + raise ArgumentError, "The indirection name must be purely alphanumeric, not '#{indirection}'" unless indirection =~ /^\w+$/ - method = indirection_method(http_method, indirection) + method = indirection_method(http_method, indirection) - params[:environment] = environment + params[:environment] = environment - raise ArgumentError, "No request key specified in #{uri}" if key == "" or key.nil? + raise ArgumentError, "No request key specified in #{uri}" if key == "" or key.nil? - key = URI.unescape(key) + key = URI.unescape(key) - Puppet::Indirector::Request.new(indirection, method, key, params) - end - - def indirection2uri(request) - indirection = request.method == :search ? pluralize(request.indirection_name.to_s) : request.indirection_name.to_s - "/#{request.environment.to_s}/#{indirection}/#{request.escaped_key}#{request.query_string}" - end + Puppet::Indirector::Request.new(indirection, method, key, params) + end - def indirection_method(http_method, indirection) - raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method] + def indirection2uri(request) + indirection = request.method == :search ? pluralize(request.indirection_name.to_s) : request.indirection_name.to_s + "/#{request.environment.to_s}/#{indirection}/#{request.escaped_key}#{request.query_string}" + end - unless method = METHOD_MAP[http_method][plurality(indirection)] - raise ArgumentError, "No support for plural #{http_method} operations" - end + def indirection_method(http_method, indirection) + raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method] - method + unless method = METHOD_MAP[http_method][plurality(indirection)] + raise ArgumentError, "No support for plural #{http_method} operations" end - def pluralize(indirection) - return(indirection == "status" ? "statuses" : indirection + "s") - end + method + end - def plurality(indirection) - # NOTE This specific hook for facts is ridiculous, but it's a *many*-line - # fix to not need this, and our goal is to move away from the complication - # that leads to the fix being too long. - return :singular if indirection == "facts" + def pluralize(indirection) + return(indirection == "status" ? "statuses" : indirection + "s") + end - # "status" really is singular - return :singular if indirection == "status" + def plurality(indirection) + # NOTE This specific hook for facts is ridiculous, but it's a *many*-line + # fix to not need this, and our goal is to move away from the complication + # that leads to the fix being too long. + return :singular if indirection == "facts" - result = (indirection =~ /s$/) ? :plural : :singular + # "status" really is singular + return :singular if indirection == "status" - indirection.sub!(/s$/, '') if result + result = (indirection =~ /s$/) ? :plural : :singular - result - end + indirection.sub!(/s$/, '') if result + + result + end end |
