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

Development #8

Merged
merged 2 commits into from
Nov 21, 2023
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
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [Released]

### Added
- New feature for the next release.
## [0.1.1] - 2023-23-11

### Added
- Initial release of the project.
- Introduced `Array.wrap` extension to the `Array` class for more reliable conversion of objects to arrays within the Lennarb router environment. This method ensures consistent array wrapping of single objects and `nil` values.

### Changed
- Example change to an existing feature.
- Refactored the `put_header` method to use the `Array.wrap` method for more predictable header value handling.
- Renamed methods to have a consistent `assign_` prefix to standardize the API interface:
- `put_header` to `assign_header`
- `write_body` to `assign_body`
- `set_params` to `assign_params`
- `update_status` to `assign_status`

### Deprecated
- Example feature that will be removed in future releases.

### Removed
- Example feature that was removed.

### Fixed
- Example bug fix.

### Security
- Example security fix.

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lennarb (0.1.0)
lennarb (0.1.1)
colorize (~> 1.1)
puma (~> 6.4)
rack (~> 3.0, >= 3.0.8)
Expand Down
19 changes: 10 additions & 9 deletions lib/lenna/router/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,18 @@ def put_body(value)
#
# @return [void]
def put_header(key, value)
key => ::String
value => ::String | ::Array
raise ::ArgumentError, 'key must be a string' unless key.is_a?(::String)

unless value.is_a?(::String) || value.is_a?(::Array)
raise ::ArgumentError, 'value must be a string or an array'
end

header_value = @headers[key]

case value
in ::String then @headers[key] = [*header_value, value].uniq.join(', ')
in ::Array then @headers[key] = [*header_value, *value].uniq.join(', ')
end
rescue ::NoMatchingPatternError
raise ::ArgumentError, 'header must be a string or an array'
new_values = ::Array.wrap(value)
existing_values = ::Array.wrap(header_value)

@headers[key] = (existing_values + new_values).uniq.join(', ')
end

# @param key [String] the header name
Expand All @@ -352,7 +353,7 @@ def finish!

[@status, @headers, @body]
end

# This method will set the response default html content type.
#
# @return [void]
Expand Down
4 changes: 4 additions & 0 deletions lib/lennarb.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

# Extension for Array class
require 'lennarb/array_extensions'

# Base class for Lennarb
require 'lenna/base'
require 'lennarb/version'
17 changes: 17 additions & 0 deletions lib/lennarb/array_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Lennarb
module ArrayExtensions
def wrap(object)
if object.nil?
[]
elsif object.respond_to?(:to_ary)
object.to_ary || [object]
else
[object]
end
end
end
end

Array.extend(Lennarb::ArrayExtensions)
2 changes: 1 addition & 1 deletion lib/lennarb/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Lennarb
VERSION = '0.1.0'
VERSION = '0.1.1'

public_constant :VERSION
end