Skip to content

Commit

Permalink
Replace keyword arguments with hash parameters (#58)
Browse files Browse the repository at this point in the history
* Replace keyword arguments with hash

* Add `**` to constructor of Carrier
  • Loading branch information
nesaulov committed Dec 29, 2017
1 parent 19f9407 commit bdf79bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
16 changes: 8 additions & 8 deletions lib/surrealist/carrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class Carrier
# @raise ArgumentError if types of arguments are wrong.
#
# @return [Carrier] self if type checks were passed.
def self.call(camelize:, include_root:, include_namespaces:, root:, namespaces_nesting_level:)
new(camelize, include_root, include_namespaces, root, namespaces_nesting_level).sanitize!
def self.call(**args)
new(args).sanitize!
end

def initialize(camelize, include_root, include_namespaces, root, namespaces_nesting_level)
@camelize = camelize
@include_root = include_root
@include_namespaces = include_namespaces
@root = root
@namespaces_nesting_level = namespaces_nesting_level
def initialize(**args)
@camelize = args.delete(:camelize) || false
@include_root = args.delete(:include_root) || false
@include_namespaces = args.delete(:include_namespaces) || false
@root = args.delete(:root) || nil
@namespaces_nesting_level = args.delete(:namespaces_nesting_level) || DEFAULT_NESTING_LEVEL
end

# Performs type checks
Expand Down
22 changes: 4 additions & 18 deletions lib/surrealist/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,13 @@ module InstanceMethods
# User.new.surrealize
# # => "{\"name\":\"Nikita\",\"age\":23}"
# # For more examples see README
def surrealize(camelize: false, include_root: false, include_namespaces: false, root: nil, namespaces_nesting_level: DEFAULT_NESTING_LEVEL) # rubocop:disable Metrics/LineLength
JSON.dump(
build_schema(
camelize: camelize,
include_root: include_root,
include_namespaces: include_namespaces,
root: root,
namespaces_nesting_level: namespaces_nesting_level,
),
)
def surrealize(**args)
JSON.dump(build_schema(args))
end

# Invokes +Surrealist+'s class method +build_schema+
def build_schema(camelize: false, include_root: false, include_namespaces: false, root: nil, namespaces_nesting_level: DEFAULT_NESTING_LEVEL) # rubocop:disable Metrics/LineLength
carrier = Surrealist::Carrier.call(
camelize: camelize,
include_namespaces: include_namespaces,
include_root: include_root,
root: root,
namespaces_nesting_level: namespaces_nesting_level,
)
def build_schema(**args)
carrier = Surrealist::Carrier.call(args)

Surrealist.build_schema(instance: self, carrier: carrier)
end
Expand Down

0 comments on commit bdf79bb

Please sign in to comment.