Lotus => Hanami

This commit is contained in:
Luca Guidi 2016-01-19 18:40:46 +01:00
parent 85d16fe52b
commit 404f01fa4e
45 changed files with 1211 additions and 1226 deletions

View File

@ -3,24 +3,9 @@ sudo: false
cache: bundler cache: bundler
script: 'bundle exec rake test:coverage --trace' script: 'bundle exec rake test:coverage --trace'
rvm: rvm:
- 2.0.0 - 2.2
- 2.1.0 - 2.3
- 2.1.1
- 2.1.2
- 2.1.3
- 2.1.4
- 2.1.5
- 2.1.6
- 2.1.7
- 2.1.8
- 2.2.0
- 2.2.1
- 2.2.2
- 2.2.3
- 2.2.4
- 2.3.0
- jruby-9000 - jruby-9000
- rbx-2
- ruby-head - ruby-head
- jruby-head - jruby-head

View File

@ -1,76 +1,76 @@
# Lotus::Utils # Hanami::Utils
Ruby core extentions and class utilities for Lotus Ruby core extentions and class utilities for Hanami
## v0.6.1 - 2016-01-19 ## v0.6.1 - 2016-01-19
### Fixed ### Fixed
- [Anton Davydov] Ensure `Lotus::Utils::String#classify` to work properly with dashes (eg. `"app-store" => "App::Store"`) - [Anton Davydov] Ensure `Hanami::Utils::String#classify` to work properly with dashes (eg. `"app-store" => "App::Store"`)
## v0.6.0 - 2016-01-12 ## v0.6.0 - 2016-01-12
### Added ### Added
- [Luca Guidi] Official support for Ruby 2.3 - [Luca Guidi] Official support for Ruby 2.3
- [Luca Guidi] Custom inflections - [Luca Guidi] Custom inflections
- [Luca Guidi] Introduced `Lotus::Utils::Duplicable` as a safe dup logic for Ruby types - [Luca Guidi] Introduced `Hanami::Utils::Duplicable` as a safe dup logic for Ruby types
- [Luca Guidi] Added `Lotus::Utils::String#rsub` replace rightmost occurrence - [Luca Guidi] Added `Hanami::Utils::String#rsub` replace rightmost occurrence
### Fixed ### Fixed
- [Luca Guidi] Fix `Lotus::Utils::PathPrefix#join` and `#relative_join` by rejecting arguments that are equal to the separator - [Luca Guidi] Fix `Hanami::Utils::PathPrefix#join` and `#relative_join` by rejecting arguments that are equal to the separator
- [Karim Kiatlottiavi] Fix `Encoding::UndefinedConversionError` in `Lotus::Utils::Escape.encode` - [Karim Kiatlottiavi] Fix `Encoding::UndefinedConversionError` in `Hanami::Utils::Escape.encode`
### Changed ### Changed
- [Luca Guidi] Deprecate Ruby 2.0 and 2.1 - [Luca Guidi] Deprecate Ruby 2.0 and 2.1
- [Luca Guidi] Removed `Lotus::Utils::Callbacks#add` in favor of `#append` - [Luca Guidi] Removed `Hanami::Utils::Callbacks#add` in favor of `#append`
- [Luca Guidi] Removed pattern support for `Utils::Class.load!` (eg. `Articles(Controller|::Controller)`) - [Luca Guidi] Removed pattern support for `Utils::Class.load!` (eg. `Articles(Controller|::Controller)`)
## v0.5.2 - 2015-09-30 ## v0.5.2 - 2015-09-30
### Added ### Added
- [Luca Guidi] Added `Lotus::Utils::String#capitalize` - [Luca Guidi] Added `Hanami::Utils::String#capitalize`
- [Trung Lê] Official support for JRuby 9k+ - [Trung Lê] Official support for JRuby 9k+
## v0.5.1 - 2015-07-10 ## v0.5.1 - 2015-07-10
### Fixed ### Fixed
- [Thiago Felippe] Ensure `Lotus::Utils::PathPrefix#join` won't remote duplicate entries (eg `/admin/dashboard/admin`) - [Thiago Felippe] Ensure `Hanami::Utils::PathPrefix#join` won't remote duplicate entries (eg `/admin/dashboard/admin`)
## v0.5.0 - 2015-06-23 ## v0.5.0 - 2015-06-23
### Added ### Added
- [Luca Guidi] Extracted `Lotus::Logger` from `lotusrb` - [Luca Guidi] Extracted `Hanami::Logger` from `hanamirb`
### Changed ### Changed
- [Luca Guidi] `Lotus::Interactor::Result` contains only objects explicitly exposed via `Lotus::Interactor.expose`. - [Luca Guidi] `Hanami::Interactor::Result` contains only objects explicitly exposed via `Hanami::Interactor.expose`.
## v0.4.3 - 2015-05-22 ## v0.4.3 - 2015-05-22
### Added ### Added
- [François Beausoleil] Improved `Lotus::Utils::Kernel` messages for `TypeError`. - [François Beausoleil] Improved `Hanami::Utils::Kernel` messages for `TypeError`.
## v0.4.2 - 2015-05-15 ## v0.4.2 - 2015-05-15
### Fixed ### Fixed
- [Luca Guidi] Ensure `Lotus::Utils::Attributes#to_h` to return `::Hash` - [Luca Guidi] Ensure `Hanami::Utils::Attributes#to_h` to return `::Hash`
## v0.4.1 - 2015-05-15 ## v0.4.1 - 2015-05-15
### Added ### Added
- [Luca Guidi & Alfonso Uceda Pompa] Introduced `Lotus::Utils::Inflector`, `Lotus::Utils::String#pluralize` and `#singularize` - [Luca Guidi & Alfonso Uceda Pompa] Introduced `Hanami::Utils::Inflector`, `Hanami::Utils::String#pluralize` and `#singularize`
### Fixed ### Fixed
- [Luca Guidi] Ensure `Lotus::Utils::Attributes#to_h` to safely return nested `::Hash` instances for complex data structures. - [Luca Guidi] Ensure `Hanami::Utils::Attributes#to_h` to safely return nested `::Hash` instances for complex data structures.
- [Luca Guidi] Let `Lotus::Interactor#error` to return a falsey value for control flow. (eg. `check_permissions or error "You can't access"`) - [Luca Guidi] Let `Hanami::Interactor#error` to return a falsey value for control flow. (eg. `check_permissions or error "You can't access"`)
## v0.4.0 - 2015-03-23 ## v0.4.0 - 2015-03-23
### Added ### Added
- [Luca Guidi] Introduced `Lotus::Utils::Escape`. It implements OWASP/ESAPI suggestions for HTML, HTML attribute and URL escape utilities. - [Luca Guidi] Introduced `Hanami::Utils::Escape`. It implements OWASP/ESAPI suggestions for HTML, HTML attribute and URL escape utilities.
- [Luca Guidi] Introduced `Lotus::Utils::String#dasherize` - [Luca Guidi] Introduced `Hanami::Utils::String#dasherize`
- [Luca Guidi] Introduced `Lotus::Utils::String#titleize` - [Luca Guidi] Introduced `Hanami::Utils::String#titleize`
## v0.3.5 - 2015-03-12 ## v0.3.5 - 2015-03-12
### Added ### Added
- [Luca Guidi] Introduced `Lotus::Interactor` - [Luca Guidi] Introduced `Hanami::Interactor`
- [Luca Guidi] Introduced `Lotus::Utils::BasicObject` - [Luca Guidi] Introduced `Hanami::Utils::BasicObject`
## v0.3.4 - 2015-01-30 ## v0.3.4 - 2015-01-30
### Added ### Added
- [Alfonso Uceda Pompa] Aliased `Lotus::Utils::Attributes#get` with `#[]` - [Alfonso Uceda Pompa] Aliased `Hanami::Utils::Attributes#get` with `#[]`
- [Simone Carletti] Introduced `Lotus::Utils::Callbacks::Chain#prepend` and `#append` - [Simone Carletti] Introduced `Hanami::Utils::Callbacks::Chain#prepend` and `#append`
### Deprecated ### Deprecated
- [Luca Guidi] Deprecated `Lotus::Utils::Callbacks::Chain#add` in favor of `#append` - [Luca Guidi] Deprecated `Hanami::Utils::Callbacks::Chain#add` in favor of `#append`
## v0.3.3 - 2015-01-08 ## v0.3.3 - 2015-01-08
### Fixed ### Fixed
@ -106,37 +106,37 @@ Ruby core extentions and class utilities for Lotus
## v0.3.0 - 2014-10-23 ## v0.3.0 - 2014-10-23
### Added ### Added
- [Celso Fernandes] Add BigDecimal coercion to Lotus::Utils::Kernel - [Celso Fernandes] Add BigDecimal coercion to Hanami::Utils::Kernel
- [Luca Guidi] Define `Boolean` constant, if missing - [Luca Guidi] Define `Boolean` constant, if missing
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::PathPrefix` - [Luca Guidi] Use composition over inheritance for `Hanami::Utils::PathPrefix`
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::Hash` - [Luca Guidi] Use composition over inheritance for `Hanami::Utils::Hash`
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::String` - [Luca Guidi] Use composition over inheritance for `Hanami::Utils::String`
### Fixed ### Fixed
- [Luca Guidi] Improved error message for `Utils::Class.load!` - [Luca Guidi] Improved error message for `Utils::Class.load!`
- [Tom Kadwill] Improved error `NameError` message by passing in the whole constant name to `Utils::Class.load!` - [Tom Kadwill] Improved error `NameError` message by passing in the whole constant name to `Utils::Class.load!`
- [Luca Guidi] `Utils::Hash#to_h` return instances of `::Hash` in case of nested symbolized data structure - [Luca Guidi] `Utils::Hash#to_h` return instances of `::Hash` in case of nested symbolized data structure
- [Luca Guidi] Raise `TypeError` if `nil` is passed to `PathPrefix#relative_join` - [Luca Guidi] Raise `TypeError` if `nil` is passed to `PathPrefix#relative_join`
- [Peter Suschlik] Define `Lotus::Utils::Hash#respond_to_missing?` - [Peter Suschlik] Define `Hanami::Utils::Hash#respond_to_missing?`
- [Peter Suschlik] Define `Lotus::Utils::String#responds_to_missing?` - [Peter Suschlik] Define `Hanami::Utils::String#responds_to_missing?`
- [Luca Guidi] Ensure `Utils::Hash#inspect` output to be the same of `::Hash#inspect` - [Luca Guidi] Ensure `Utils::Hash#inspect` output to be the same of `::Hash#inspect`
## v0.2.0 - 2014-06-23 ## v0.2.0 - 2014-06-23
### Added ### Added
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Symbol` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Symbol`
- [Luca Guidi] Made `Kernel.Pathname` to raise an error when `nil` is passed as argument - [Luca Guidi] Made `Kernel.Pathname` to raise an error when `nil` is passed as argument
- [Luca Guidi] Implemented `Lotus::Utils::LoadPaths#freeze` in order to prevent modification after the object has been frozen - [Luca Guidi] Implemented `Hanami::Utils::LoadPaths#freeze` in order to prevent modification after the object has been frozen
- [Luca Guidi] Implemented Lotus::Utils::LoadPaths#push, also aliased as #<< - [Luca Guidi] Implemented Hanami::Utils::LoadPaths#push, also aliased as #<<
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::LoadPaths` - [Luca Guidi] Use composition over inheritance for `Hanami::Utils::LoadPaths`
- [Luca Guidi] Introduced `Lotus::Utils::LoadPaths` - [Luca Guidi] Introduced `Hanami::Utils::LoadPaths`
- [Luca Guidi] Introduced `Lotus::Utils::String#namespace`, in order to return the top level Ruby namespace for the given string - [Luca Guidi] Introduced `Hanami::Utils::String#namespace`, in order to return the top level Ruby namespace for the given string
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Pathname` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Pathname`
### Fixed ### Fixed
- [Luca Guidi] Implemented `Lotus::Utils::LoadPaths#initialize_copy` in order to safely `#dup` and `#clone` - [Luca Guidi] Implemented `Hanami::Utils::LoadPaths#initialize_copy` in order to safely `#dup` and `#clone`
### Changed ### Changed
- [Luca Guidi] Implemented `Lotus::Utils::Callbacks::Chain#freeze` in order to prevent modification after the object has been frozen - [Luca Guidi] Implemented `Hanami::Utils::Callbacks::Chain#freeze` in order to prevent modification after the object has been frozen
- [Luca Guidi] All the `Utils::Kernel` methods will raise `TypeError` in case of failed coercion. - [Luca Guidi] All the `Utils::Kernel` methods will raise `TypeError` in case of failed coercion.
- [Luca Guidi] Made `Kernel.Time` to raise an error when `nil` is passed as argument - [Luca Guidi] Made `Kernel.Time` to raise an error when `nil` is passed as argument
- [Luca Guidi] Made `Kernel.DateTime` to raise an error when `nil` is passed as argument - [Luca Guidi] Made `Kernel.DateTime` to raise an error when `nil` is passed as argument
@ -148,28 +148,28 @@ Ruby core extentions and class utilities for Lotus
- [Luca Guidi] Made `Kernel.Hash` to return an empty `Hash` when `nil` is passed as argument - [Luca Guidi] Made `Kernel.Hash` to return an empty `Hash` when `nil` is passed as argument
- [Luca Guidi] Made `Kernel.Set` to return an empty `Set` when `nil` is passed as argument - [Luca Guidi] Made `Kernel.Set` to return an empty `Set` when `nil` is passed as argument
- [Luca Guidi] Made `Kernel.Array` to return an empty `Array` when `nil` is passed as argument - [Luca Guidi] Made `Kernel.Array` to return an empty `Array` when `nil` is passed as argument
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::Callbacks::Chain` - [Luca Guidi] Use composition over inheritance for `Hanami::Utils::Callbacks::Chain`
## v0.1.1 - 2014-04-23 ## v0.1.1 - 2014-04-23
### Added ### Added
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Time` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Time`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.DateTime` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.DateTime`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Date` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Date`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Float` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Float`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Boolean` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Boolean`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Hash` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Hash`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Set` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Set`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.String` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.String`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Integer` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Integer`
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Array` - [Luca Guidi] Implemented `Hanami::Utils::Kernel.Array`
### Fixed ### Fixed
- [Christopher Keele] Add missing stdlib `Set` require to `Utils::ClassAttribute` - [Christopher Keele] Add missing stdlib `Set` require to `Utils::ClassAttribute`
## v0.1.0 - 2014-01-23 ## v0.1.0 - 2014-01-23
### Added ### Added
- [Luca Guidi] Introduced `Lotus::Utils::String#demodulize` - [Luca Guidi] Introduced `Hanami::Utils::String#demodulize`
- [Luca Guidi] Introduced `Lotus::Utils::IO.silence_warnings` - [Luca Guidi] Introduced `Hanami::Utils::IO.silence_warnings`
- [Luca Guidi] Introduced class loading mechanism from a string: `Utils::Class.load!` - [Luca Guidi] Introduced class loading mechanism from a string: `Utils::Class.load!`
- [Luca Guidi] Introduced callbacks support for classes - [Luca Guidi] Introduced callbacks support for classes
- [Luca Guidi] Introduced inheritable class level attributes - [Luca Guidi] Introduced inheritable class level attributes

View File

@ -17,7 +17,7 @@ Here are some ways *you* can contribute:
* by closing [issues][] * by closing [issues][]
* by reviewing patches * by reviewing patches
[issues]: https://github.com/lotus/utils/issues [issues]: https://github.com/hanami/utils/issues
## Submitting an Issue ## Submitting an Issue
We use the [GitHub issue tracker][issues] to track bugs and features. Before We use the [GitHub issue tracker][issues] to track bugs and features. Before

110
README.md
View File

@ -1,36 +1,35 @@
# Hanami::Utils
# Lotus::Utils Ruby core extentions and class utilities for [Hanami](http://hanamirb.org)
Ruby core extentions and class utilities for [Lotus](http://lotusrb.org)
## Status ## Status
[![Gem Version](http://img.shields.io/gem/v/lotus-utils.svg)](https://badge.fury.io/rb/lotus-utils) [![Gem Version](http://img.shields.io/gem/v/hanami-utils.svg)](https://badge.fury.io/rb/hanami-utils)
[![Build Status](http://img.shields.io/travis/lotus/utils/master.svg)](https://travis-ci.org/lotus/utils?branch=master) [![Build Status](http://img.shields.io/travis/hanami/utils/master.svg)](https://travis-ci.org/hanami/utils?branch=master)
[![Coverage](http://img.shields.io/coveralls/lotus/utils/master.svg)](https://coveralls.io/r/lotus/utils) [![Coverage](http://img.shields.io/coveralls/hanami/utils/master.svg)](https://coveralls.io/r/hanami/utils)
[![Code Climate](http://img.shields.io/codeclimate/github/lotus/utils.svg)](https://codeclimate.com/github/lotus/utils) [![Code Climate](http://img.shields.io/codeclimate/github/hanami/utils.svg)](https://codeclimate.com/github/hanami/utils)
[![Dependencies](http://img.shields.io/gemnasium/lotus/utils.svg)](https://gemnasium.com/lotus/utils) [![Dependencies](http://img.shields.io/gemnasium/hanami/utils.svg)](https://gemnasium.com/hanami/utils)
[![Inline Docs](http://inch-ci.org/github/lotus/utils.svg)](http://inch-ci.org/github/lotus/utils) [![Inline Docs](http://inch-ci.org/github/hanami/utils.svg)](http://inch-ci.org/github/hanami/utils)
## Contact ## Contact
* Home page: http://lotusrb.org * Home page: http://hanamirb.org
* Mailing List: http://lotusrb.org/mailing-list * Mailing List: http://hanamirb.org/mailing-list
* API Doc: http://rdoc.info/gems/lotus-utils * API Doc: http://rdoc.info/gems/hanami-utils
* Bugs/Issues: https://github.com/lotus/utils/issues * Bugs/Issues: https://github.com/hanami/utils/issues
* Support: http://stackoverflow.com/questions/tagged/lotus-ruby * Support: http://stackoverflow.com/questions/tagged/hanami
* Chat: https://gitter.im/lotus/chat * Chat: http://chat.hanamirb.org
## Rubies ## Rubies
__Lotus::Utils__ supports Ruby (MRI) 2+, JRuby 9k+ & Rubinius 2.3+ __Hanami::Utils__ supports Ruby (MRI) 2+, JRuby 9k+ & Rubinius 2.3+
## Installation ## Installation
Add this line to your application's Gemfile: Add this line to your application's Gemfile:
```ruby ```ruby
gem 'lotus-utils' gem 'hanami-utils'
``` ```
And then execute: And then execute:
@ -39,91 +38,91 @@ And then execute:
Or install it yourself as: Or install it yourself as:
$ gem install lotus-utils $ gem install hanami-utils
## Usage ## Usage
__Lotus::Utils__ is designed to enhance Ruby's code and stdlib. __Hanami::Utils__ is designed to enhance Ruby's code and stdlib.
**By default this gem doesn't load any code, you must require what you need.** **By default this gem doesn't load any code, you must require what you need.**
## Features ## Features
### Lotus::Interactor ### Hanami::Interactor
Standardized Service Object with small interface and rich returning result. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Interactor)] Standardized Service Object with small interface and rich returning result. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Interactor)]
### Lotus::Logger ### Hanami::Logger
Enhanced version of Ruby's `Logger`. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Logger)] Enhanced version of Ruby's `Logger`. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Logger)]
### Lotus::Utils::Attributes ### Hanami::Utils::Attributes
Set of attributes with indifferent access. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Attributes)] Set of attributes with indifferent access. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Attributes)]
### Lotus::Utils::BasicObject ### Hanami::Utils::BasicObject
Enhanced version of Ruby's `BasicObject`. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/BasicObject)] Enhanced version of Ruby's `BasicObject`. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/BasicObject)]
### Lotus::Utils::Callbacks ### Hanami::Utils::Callbacks
Callbacks to decorate methods with `before` and `after` logic. It supports polymorphic callbacks (methods and procs). [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Callbacks)] Callbacks to decorate methods with `before` and `after` logic. It supports polymorphic callbacks (methods and procs). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Callbacks)]
### Lotus::Utils::Class ### Hanami::Utils::Class
Load classes from strings. It also supports namespaces. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Class)] Load classes from strings. It also supports namespaces. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Class)]
### Lotus::Utils::ClassAttribute ### Hanami::Utils::ClassAttribute
Inheritable class attributes. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/ClassAttribute)] Inheritable class attributes. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/ClassAttribute)]
### Lotus::Utils::Deprecation ### Hanami::Utils::Deprecation
Deprecate Lotus features. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Deprecation)] Deprecate Hanami features. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Deprecation)]
### Lotus::Utils::Duplicable ### Hanami::Utils::Duplicable
Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Deprecation)] Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Deprecation)]
### Lotus::Utils::Escape ### Hanami::Utils::Escape
Safe and fast escape for URLs, HTML content and attributes. Based on OWASP/ESAPI code. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Escape)] Safe and fast escape for URLs, HTML content and attributes. Based on OWASP/ESAPI code. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Escape)]
### Lotus::Utils::Hash ### Hanami::Utils::Hash
Enhanced version of Ruby's `Hash`. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Hash)] Enhanced version of Ruby's `Hash`. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Hash)]
### Lotus::Utils::IO ### Hanami::Utils::IO
Silence Ruby warnings. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/IO)] Silence Ruby warnings. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/IO)]
### Lotus::Utils::Inflector ### Hanami::Utils::Inflector
Complete and customizable english inflections (pluralization and singularization). [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Inflector)] Complete and customizable english inflections (pluralization and singularization). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Inflector)]
### Lotus::Utils::Kernel ### Hanami::Utils::Kernel
Type coercions for most common Ruby types. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/Kernel)] Type coercions for most common Ruby types. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Kernel)]
### Lotus::Utils::LoadPaths ### Hanami::Utils::LoadPaths
Manage directories where to find Ruby source code or web static assets. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/LoadPaths)] Manage directories where to find Ruby source code or web static assets. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/LoadPaths)]
### Lotus::Utils::PathPrefix ### Hanami::Utils::PathPrefix
Safe logic to manage relative URLs. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/PathPrefix)] Safe logic to manage relative URLs. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/PathPrefix)]
### Lotus::Utils::String ### Hanami::Utils::String
Enhanced version of Ruby's `String`. [[API doc](http://www.rubydoc.info/gems/lotus-utils/Lotus/Utils/String)] Enhanced version of Ruby's `String`. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/String)]
## Versioning ## Versioning
__Lotus::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org) __Hanami::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
## Contributing ## Contributing
1. Fork it ( https://github.com/lotus/utils/fork ) 1. Fork it ( https://github.com/hanami/utils/fork )
2. Create your feature branch (`git checkout -b my-new-feature`) 2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`) 3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`) 4. Push to the branch (`git push origin my-new-feature`)
@ -132,3 +131,4 @@ __Lotus::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
## Copyright ## Copyright
Copyright © 2014-2016 Luca Guidi Released under MIT License Copyright © 2014-2016 Luca Guidi Released under MIT License
This project was formerly known as Lotus (`lotus-utils`).

View File

@ -1,19 +1,19 @@
# coding: utf-8 # coding: utf-8
lib = File.expand_path('../lib', __FILE__) lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'lotus/utils/version' require 'hanami/utils/version'
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = 'lotus-utils' spec.name = 'hanami-utils'
spec.version = Lotus::Utils::VERSION spec.version = Hanami::Utils::VERSION
spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda'] spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda']
spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com'] spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com']
spec.description = %q{Lotus utilities} spec.description = %q{Hanami utilities}
spec.summary = %q{Ruby core extentions and Lotus utilities} spec.summary = %q{Ruby core extentions and Hanami utilities}
spec.homepage = 'http://lotusrb.org' spec.homepage = 'http://hanamirb.org'
spec.license = 'MIT' spec.license = 'MIT'
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md lotus-utils.gemspec`.split($/) spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-utils.gemspec`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib'] spec.require_paths = ['lib']

1
lib/hanami-utils.rb Normal file
View File

@ -0,0 +1 @@
require 'hanami/utils'

View File

@ -1,9 +1,9 @@
require 'lotus/utils/basic_object' require 'hanami/utils/basic_object'
require 'lotus/utils/class_attribute' require 'hanami/utils/class_attribute'
require 'lotus/utils/hash' require 'hanami/utils/hash'
module Lotus module Hanami
# Lotus Interactor # Hanami Interactor
# #
# @since 0.3.5 # @since 0.3.5
module Interactor module Interactor
@ -16,14 +16,14 @@ module Lotus
# @since 0.3.5 # @since 0.3.5
# @api private # @api private
# #
# @see Lotus::Interactor::Result#respond_to_missing? # @see Hanami::Interactor::Result#respond_to_missing?
METHODS = {initialize: true, success?: true, fail!: true, prepare!: true, errors: true, error: true}.freeze METHODS = {initialize: true, success?: true, fail!: true, prepare!: true, errors: true, error: true}.freeze
# Initialize a new result # Initialize a new result
# #
# @param payload [Hash] a payload to carry on # @param payload [Hash] a payload to carry on
# #
# @return [Lotus::Interactor::Result] # @return [Hanami::Interactor::Result]
# #
# @since 0.3.5 # @since 0.3.5
# @api private # @api private
@ -55,10 +55,10 @@ module Lotus
# #
# @since 0.3.5 # @since 0.3.5
# #
# @see Lotus::Interactor::Result#error # @see Hanami::Interactor::Result#error
# @see Lotus::Interactor#call # @see Hanami::Interactor#call
# @see Lotus::Interactor#error # @see Hanami::Interactor#error
# @see Lotus::Interactor#error! # @see Hanami::Interactor#error!
def errors def errors
@errors.dup @errors.dup
end end
@ -77,10 +77,10 @@ module Lotus
# #
# @since 0.3.5 # @since 0.3.5
# #
# @see Lotus::Interactor::Result#errors # @see Hanami::Interactor::Result#errors
# @see Lotus::Interactor#call # @see Hanami::Interactor#call
# @see Lotus::Interactor#error # @see Hanami::Interactor#error
# @see Lotus::Interactor#error! # @see Hanami::Interactor#error!
def error def error
errors.first errors.first
end end
@ -147,15 +147,15 @@ module Lotus
# #
# @param args [Array<Object>] arbitrary number of arguments # @param args [Array<Object>] arbitrary number of arguments
# #
# @return [Lotus::Interactor] the interactor # @return [Hanami::Interactor] the interactor
# #
# @since 0.3.5 # @since 0.3.5
# #
# @example Override #initialize # @example Override #initialize
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class UpdateProfile # class UpdateProfile
# include Lotus::Interactor # include Hanami::Interactor
# #
# def initialize(user, params) # def initialize(user, params)
# @user = user # @user = user
@ -169,7 +169,7 @@ module Lotus
def initialize(*args) def initialize(*args)
super super
ensure ensure
@__result = ::Lotus::Interactor::Result.new @__result = ::Hanami::Interactor::Result.new
end end
# Triggers the operation and return a result. # Triggers the operation and return a result.
@ -178,15 +178,15 @@ module Lotus
# #
# ATTENTION: This must be implemented by the including class. # ATTENTION: This must be implemented by the including class.
# #
# @return [Lotus::Interactor::Result] the result of the operation # @return [Hanami::Interactor::Result] the result of the operation
# #
# @raise [NoMethodError] if this isn't implemented by the including class. # @raise [NoMethodError] if this isn't implemented by the including class.
# #
# @example Expose instance variables in result payload # @example Expose instance variables in result payload
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class Signup # class Signup
# include Lotus::Interactor # include Hanami::Interactor
# expose :user, :params # expose :user, :params
# #
# def initialize(params) # def initialize(params)
@ -208,10 +208,10 @@ module Lotus
# result.foo # => raises NoMethodError # result.foo # => raises NoMethodError
# #
# @example Failed precondition # @example Failed precondition
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class Signup # class Signup
# include Lotus::Interactor # include Hanami::Interactor
# expose :user # expose :user
# #
# def initialize(params) # def initialize(params)
@ -236,10 +236,10 @@ module Lotus
# result.user # => #<User:0x007fa311105778 @id=nil @name="Luca"> # result.user # => #<User:0x007fa311105778 @id=nil @name="Luca">
# #
# @example Bad usage # @example Bad usage
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class Signup # class Signup
# include Lotus::Interactor # include Hanami::Interactor
# #
# # Method #call is not defined # # Method #call is not defined
# end # end
@ -268,10 +268,10 @@ module Lotus
# @since 0.3.5 # @since 0.3.5
# #
# @example # @example
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class CreateEmailTest # class CreateEmailTest
# include Lotus::Interactor # include Hanami::Interactor
# #
# def initialize(params) # def initialize(params)
# @params = params # @params = params
@ -313,13 +313,13 @@ module Lotus
# #
# @since 0.3.5 # @since 0.3.5
# #
# @see Lotus::Interactor#error! # @see Hanami::Interactor#error!
# #
# @example # @example
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class CreateRecord # class CreateRecord
# include Lotus::Interactor # include Hanami::Interactor
# expose :logger # expose :logger
# #
# def initialize # def initialize
@ -366,13 +366,13 @@ module Lotus
# #
# @since 0.3.5 # @since 0.3.5
# #
# @see Lotus::Interactor#error # @see Hanami::Interactor#error
# #
# @example # @example
# require 'lotus/interactor' # require 'hanami/interactor'
# #
# class CreateRecord # class CreateRecord
# include Lotus::Interactor # include Hanami::Interactor
# expose :logger # expose :logger
# #
# def initialize # def initialize
@ -466,12 +466,12 @@ module Lotus
# #
# @since 0.5.0 # @since 0.5.0
# #
# @see Lotus::Interactor::Result # @see Hanami::Interactor::Result
# #
# @example Expose instance variable # @example Expose instance variable
# #
# class Signup # class Signup
# include Lotus::Interactor # include Hanami::Interactor
# expose :user # expose :user
# #
# def initialize(params) # def initialize(params)

View File

@ -1,20 +1,20 @@
require 'logger' require 'logger'
require 'lotus/utils/string' require 'hanami/utils/string'
module Lotus module Hanami
# Lotus logger # Hanami logger
# #
# Implement with the same interface of Ruby std lib `Logger`. # Implement with the same interface of Ruby std lib `Logger`.
# It uses `STDOUT` as output device. # It uses `STDOUT` as output device.
# #
# #
# #
# When a Lotus application is initialized, it creates a logger for that specific application. # When a Hanami application is initialized, it creates a logger for that specific application.
# For instance for a `Bookshelf::Application` a `Bookshelf::Logger` will be available. # For instance for a `Bookshelf::Application` a `Bookshelf::Logger` will be available.
# #
# This is useful for auto-tagging the output. Eg (`[Booshelf]`). # This is useful for auto-tagging the output. Eg (`[Booshelf]`).
# #
# When used stand alone (eg. `Lotus::Logger.info`), it tags lines with `[Shared]`. # When used stand alone (eg. `Hanami::Logger.info`), it tags lines with `[Shared]`.
# #
# #
# #
@ -35,10 +35,10 @@ module Lotus
# @see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger/Severity.html # @see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger/Severity.html
# #
# @example Basic usage # @example Basic usage
# require 'lotus' # require 'hanami'
# #
# module Bookshelf # module Bookshelf
# class Application < Lotus::Application # class Application < Hanami::Application
# end # end
# end # end
# #
@ -54,21 +54,21 @@ module Lotus
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Bookshelf] : Hello # # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Bookshelf] : Hello
# #
# @example Standalone usage # @example Standalone usage
# require 'lotus' # require 'hanami'
# #
# Lotus::Logger.info('Hello') # Hanami::Logger.info('Hello')
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Lotus] : Hello # # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Hanami] : Hello
# #
# Lotus::Logger.new.info('Hello') # Hanami::Logger.new.info('Hello')
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Lotus] : Hello # # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Hanami] : Hello
# #
# @example Custom tagging # @example Custom tagging
# require 'lotus' # require 'hanami'
# #
# Lotus::Logger.new('FOO').info('Hello') # Hanami::Logger.new('FOO').info('Hello')
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [FOO] : Hello # # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [FOO] : Hello
class Logger < ::Logger class Logger < ::Logger
# Lotus::Logger default formatter # Hanami::Logger default formatter
# #
# @since 0.5.0 # @since 0.5.0
# @api private # @api private
@ -94,7 +94,7 @@ module Lotus
# #
# @since 0.5.0 # @since 0.5.0
# @api private # @api private
DEFAULT_APPLICATION_NAME = 'Lotus'.freeze DEFAULT_APPLICATION_NAME = 'Hanami'.freeze
# @since 0.5.0 # @since 0.5.0
# @api private # @api private
@ -110,7 +110,7 @@ module Lotus
super(STDOUT) super(STDOUT)
@application_name = application_name @application_name = application_name
@formatter = Lotus::Logger::Formatter.new.tap { |f| f.application_name = self.application_name } @formatter = Hanami::Logger::Formatter.new.tap { |f| f.application_name = self.application_name }
end end
# Returns the current application name, this is used for tagging purposes # Returns the current application name, this is used for tagging purposes

View File

@ -1,17 +1,17 @@
require 'lotus/utils/version' require 'hanami/utils/version'
module Lotus module Hanami
# Ruby core extentions and Lotus utilities # Ruby core extentions and Hanami utilities
# #
# @since 0.1.0 # @since 0.1.0
module Utils module Utils
# @since 0.3.1 # @since 0.3.1
# @api private # @api private
LOTUS_JRUBY = 'java'.freeze HANAMI_JRUBY = 'java'.freeze
# @since 0.3.1 # @since 0.3.1
# @api private # @api private
LOTUS_RUBINIUS = 'rbx'.freeze HANAMI_RUBINIUS = 'rbx'.freeze
# Checks if the current VM is JRuby # Checks if the current VM is JRuby
# #
@ -20,7 +20,7 @@ module Lotus
# @since 0.3.1 # @since 0.3.1
# @api private # @api private
def self.jruby? def self.jruby?
RUBY_PLATFORM == LOTUS_JRUBY RUBY_PLATFORM == HANAMI_JRUBY
end end
# Checks if the current VM is Rubinius # Checks if the current VM is Rubinius
@ -30,7 +30,7 @@ module Lotus
# @since 0.3.1 # @since 0.3.1
# @api private # @api private
def self.rubinius? def self.rubinius?
RUBY_ENGINE == LOTUS_RUBINIUS RUBY_ENGINE == HANAMI_RUBINIUS
end end
end end
end end

View File

@ -1,6 +1,6 @@
require 'lotus/utils/hash' require 'hanami/utils/hash'
module Lotus module Hanami
module Utils module Utils
# A set of attributes. # A set of attributes.
# #
@ -20,14 +20,14 @@ module Lotus
# #
# @param hash [#to_h] a Hash or any object that implements #to_h # @param hash [#to_h] a Hash or any object that implements #to_h
# #
# @return [Lotus::Utils::Attributes] self # @return [Hanami::Utils::Attributes] self
# #
# @since 0.3.2 # @since 0.3.2
# #
# @example # @example
# require 'lotus/utils/attributes' # require 'hanami/utils/attributes'
# #
# attributes = Lotus::Utils::Attributes.new(a: 1, b: { 2 => [3, 4] }) # attributes = Hanami::Utils::Attributes.new(a: 1, b: { 2 => [3, 4] })
# attributes.to_h # => { "a" => 1, "b" => { "2" => [3, 4] } } # attributes.to_h # => { "a" => 1, "b" => { "2" => [3, 4] } }
def initialize(hash = {}) def initialize(hash = {})
@attributes = Utils::Hash.new(hash, &nil).stringify! @attributes = Utils::Hash.new(hash, &nil).stringify!
@ -42,9 +42,9 @@ module Lotus
# @since 0.3.2 # @since 0.3.2
# #
# @example # @example
# require 'lotus/utils/attributes' # require 'hanami/utils/attributes'
# #
# attributes = Lotus::Utils::Attributes.new(a: 1, 'b' => 2, 23 => 'foo') # attributes = Hanami::Utils::Attributes.new(a: 1, 'b' => 2, 23 => 'foo')
# #
# attributes.get(:a) # => 1 # attributes.get(:a) # => 1
# attributes.get('a') # => 1 # attributes.get('a') # => 1
@ -82,9 +82,9 @@ module Lotus
# @since 0.3.2 # @since 0.3.2
# #
# @example # @example
# require 'lotus/utils/attributes' # require 'hanami/utils/attributes'
# #
# attributes = Lotus::Utils::Attributes.new # attributes = Hanami::Utils::Attributes.new
# #
# attributes.set(:a, 1) # attributes.set(:a, 1)
# attributes.get(:a) # => 1 # attributes.get(:a) # => 1
@ -121,7 +121,7 @@ module Lotus
# @api private # @api private
def _read_value(value) def _read_value(value)
case val = value case val = value
when ::Hash, ::Lotus::Utils::Hash, ->(v) { v.respond_to?(:lotus_nested_attributes?) } when ::Hash, ::Hanami::Utils::Hash, ->(v) { v.respond_to?(:hanami_nested_attributes?) }
val.to_h val.to_h
else else
val val

View File

@ -1,4 +1,4 @@
module Lotus module Hanami
module Utils module Utils
# BasicObject # BasicObject
# #

View File

@ -1,4 +1,4 @@
module Lotus module Hanami
module Utils module Utils
# Before and After callbacks # Before and After callbacks
# #
@ -12,7 +12,7 @@ module Lotus
class Chain class Chain
# Return a new chain # Return a new chain
# #
# @return [Lotus::Utils::Callbacks::Chain] # @return [Hanami::Utils::Callbacks::Chain]
# #
# @since 0.2.0 # @since 0.2.0
def initialize def initialize
@ -30,16 +30,16 @@ module Lotus
# #
# @see #prepend # @see #prepend
# @see #run # @see #run
# @see Lotus::Utils::Callbacks::Callback # @see Hanami::Utils::Callbacks::Callback
# @see Lotus::Utils::Callbacks::MethodCallback # @see Hanami::Utils::Callbacks::MethodCallback
# @see Lotus::Utils::Callbacks::Chain#freeze # @see Hanami::Utils::Callbacks::Chain#freeze
# #
# @since 0.3.4 # @since 0.3.4
# #
# @example # @example
# require 'lotus/utils/callbacks' # require 'hanami/utils/callbacks'
# #
# chain = Lotus::Utils::Callbacks::Chain.new # chain = Hanami::Utils::Callbacks::Chain.new
# #
# # Append a Proc to be used as a callback, it will be wrapped by `Callback` # # Append a Proc to be used as a callback, it will be wrapped by `Callback`
# # The optional argument(s) correspond to the one passed when invoked the chain with `run`. # # The optional argument(s) correspond to the one passed when invoked the chain with `run`.
@ -69,16 +69,16 @@ module Lotus
# #
# @see #append # @see #append
# @see #run # @see #run
# @see Lotus::Utils::Callbacks::Callback # @see Hanami::Utils::Callbacks::Callback
# @see Lotus::Utils::Callbacks::MethodCallback # @see Hanami::Utils::Callbacks::MethodCallback
# @see Lotus::Utils::Callbacks::Chain#freeze # @see Hanami::Utils::Callbacks::Chain#freeze
# #
# @since 0.3.4 # @since 0.3.4
# #
# @example # @example
# require 'lotus/utils/callbacks' # require 'hanami/utils/callbacks'
# #
# chain = Lotus::Utils::Callbacks::Chain.new # chain = Hanami::Utils::Callbacks::Chain.new
# #
# # Add a Proc to be used as a callback, it will be wrapped by `Callback` # # Add a Proc to be used as a callback, it will be wrapped by `Callback`
# # The optional argument(s) correspond to the one passed when invoked the chain with `run`. # # The optional argument(s) correspond to the one passed when invoked the chain with `run`.
@ -106,7 +106,7 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/callbacks' # require 'hanami/utils/callbacks'
# #
# class Action # class Action
# private # private
@ -120,7 +120,7 @@ module Lotus
# action = Action.new # action = Action.new
# params = Hash[id: 23] # params = Hash[id: 23]
# #
# chain = Lotus::Utils::Callbacks::Chain.new # chain = Hanami::Utils::Callbacks::Chain.new
# chain.append :authenticate!, :set_article # chain.append :authenticate!, :set_article
# #
# chain.run(action, params) # chain.run(action, params)
@ -129,7 +129,7 @@ module Lotus
# #
# #
# #
# chain = Lotus::Utils::Callbacks::Chain.new # chain = Hanami::Utils::Callbacks::Chain.new
# #
# chain.append do # chain.append do
# # some authentication logic # # some authentication logic
@ -155,9 +155,9 @@ module Lotus
# @see http://ruby-doc.org/core/Object.html#method-i-freeze # @see http://ruby-doc.org/core/Object.html#method-i-freeze
# #
# @example # @example
# require 'lotus/utils/callbacks' # require 'hanami/utils/callbacks'
# #
# chain = Lotus::Utils::Callbacks::Chain.new # chain = Hanami::Utils::Callbacks::Chain.new
# chain.freeze # chain.freeze
# #
# chain.frozen? # => true # chain.frozen? # => true
@ -192,16 +192,16 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/callbacks' # require 'hanami/utils/callbacks'
# #
# callable = Proc.new{} # it responds to #call # callable = Proc.new{} # it responds to #call
# method = :upcase # it doesn't responds to #call # method = :upcase # it doesn't responds to #call
# #
# Lotus::Utils::Callbacks::Factory.fabricate(callable).class # Hanami::Utils::Callbacks::Factory.fabricate(callable).class
# # => Lotus::Utils::Callbacks::Callback # # => Hanami::Utils::Callbacks::Callback
# #
# Lotus::Utils::Callbacks::Factory.fabricate(method).class # Hanami::Utils::Callbacks::Factory.fabricate(method).class
# # => Lotus::Utils::Callbacks::MethodCallback # # => Hanami::Utils::Callbacks::MethodCallback
def self.fabricate(callback) def self.fabricate(callback)
if callback.respond_to?(:call) if callback.respond_to?(:call)
Callback.new(callback) Callback.new(callback)
@ -240,7 +240,7 @@ module Lotus
# #
# @since 0.1.0 # @since 0.1.0
# #
# @see Lotus::Utils::Callbacks::Chain#run # @see Hanami::Utils::Callbacks::Chain#run
def call(context, *args) def call(context, *args)
context.instance_exec(*args, &callback) context.instance_exec(*args, &callback)
end end
@ -262,7 +262,7 @@ module Lotus
# #
# @since 0.1.0 # @since 0.1.0
# #
# @see Lotus::Utils::Callbacks::Chain#run # @see Hanami::Utils::Callbacks::Chain#run
def call(context, *args) def call(context, *args)
method = context.method(callback) method = context.method(callback)

View File

@ -1,6 +1,6 @@
require 'lotus/utils/string' require 'hanami/utils/string'
module Lotus module Hanami
module Utils module Utils
# Class utilities # Class utilities
# @since 0.1.0 # @since 0.1.0
@ -16,7 +16,7 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/class' # require 'hanami/utils/class'
# #
# module App # module App
# module Service # module Service
@ -29,14 +29,14 @@ module Lotus
# end # end
# #
# # basic usage # # basic usage
# Lotus::Utils::Class.load!('App::Service') # => App::Service # Hanami::Utils::Class.load!('App::Service') # => App::Service
# Lotus::Utils::Class.load!(App::Service) # => App::Service # Hanami::Utils::Class.load!(App::Service) # => App::Service
# #
# # with explicit namespace # # with explicit namespace
# Lotus::Utils::Class.load!('Service', App) # => App::Service # Hanami::Utils::Class.load!('Service', App) # => App::Service
# #
# # with missing constant # # with missing constant
# Lotus::Utils::Class.load!('Unknown') # => raises NameError # Hanami::Utils::Class.load!('Unknown') # => raises NameError
def self.load!(name, namespace = Object) def self.load!(name, namespace = Object)
namespace.const_get(name.to_s) namespace.const_get(name.to_s)
end end
@ -51,10 +51,10 @@ module Lotus
# #
# @since 0.3.1 # @since 0.3.1
# #
# @see Lotus::Utils::String#tokenize # @see Hanami::Utils::String#tokenize
# #
# @example # @example
# require 'lotus/utils/class' # require 'hanami/utils/class'
# #
# module App # module App
# module Service # module Service
@ -67,17 +67,17 @@ module Lotus
# end # end
# #
# # basic usage # # basic usage
# Lotus::Utils::Class.load_from_pattern!('App::Service') # => App::Service # Hanami::Utils::Class.load_from_pattern!('App::Service') # => App::Service
# #
# # with explicit namespace # # with explicit namespace
# Lotus::Utils::Class.load_from_pattern!('Service', App) # => App::Service # Hanami::Utils::Class.load_from_pattern!('Service', App) # => App::Service
# #
# # with pattern # # with pattern
# Lotus::Utils::Class.load_from_pattern!('App::Service(::Endpoint|Endpoint)') # => App::Service::Endpoint # Hanami::Utils::Class.load_from_pattern!('App::Service(::Endpoint|Endpoint)') # => App::Service::Endpoint
# Lotus::Utils::Class.load_from_pattern!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint # Hanami::Utils::Class.load_from_pattern!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint
# #
# # with missing constant # # with missing constant
# Lotus::Utils::Class.load_from_pattern!('Unknown') # => raises NameError # Hanami::Utils::Class.load_from_pattern!('Unknown') # => raises NameError
def self.load_from_pattern!(pattern, namespace = Object) def self.load_from_pattern!(pattern, namespace = Object)
String.new(pattern).tokenize do |token| String.new(pattern).tokenize do |token|
begin begin

View File

@ -1,12 +1,12 @@
require 'set' require 'set'
require 'lotus/utils/duplicable' require 'hanami/utils/duplicable'
module Lotus module Hanami
module Utils module Utils
# Inheritable class level variable accessors. # Inheritable class level variable accessors.
# @since 0.1.0 # @since 0.1.0
# #
# @see Lotus::Utils::ClassAttribute::ClassMethods # @see Hanami::Utils::ClassAttribute::ClassMethods
module ClassAttribute module ClassAttribute
def self.included(base) def self.included(base)
base.extend ClassMethods base.extend ClassMethods
@ -26,10 +26,10 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/class_attribute' # require 'hanami/utils/class_attribute'
# #
# class Vehicle # class Vehicle
# include Lotus::Utils::ClassAttribute # include Hanami::Utils::ClassAttribute
# class_attribute :engines, :wheels # class_attribute :engines, :wheels
# #
# self.engines = 0 # self.engines = 0

View File

@ -1,6 +1,6 @@
require 'lotus/utils' require 'hanami/utils'
module Lotus module Hanami
module Utils module Utils
# Prints a deprecation warning when initialized # Prints a deprecation warning when initialized
# #
@ -13,11 +13,11 @@ module Lotus
# @since 0.3.1 # @since 0.3.1
# #
# @example Direct usage # @example Direct usage
# require 'lotus/utils/deprecation' # require 'hanami/utils/deprecation'
# #
# class Engine # class Engine
# def old_method # def old_method
# Lotus::Utils::Deprecation.new('old_method is deprecated, please use new_method') # Hanami::Utils::Deprecation.new('old_method is deprecated, please use new_method')
# new_method # new_method
# end # end
# #
@ -31,11 +31,11 @@ module Lotus
# # => started # # => started
# #
# @example Indirect usage # @example Indirect usage
# require 'lotus/utils/deprecation' # require 'hanami/utils/deprecation'
# #
# class Engine # class Engine
# def old_method # def old_method
# Lotus::Utils::Deprecation.new('old_method is deprecated, please use new_method') # Hanami::Utils::Deprecation.new('old_method is deprecated, please use new_method')
# new_method # new_method
# end # end
# #

View File

@ -1,4 +1,4 @@
module Lotus module Hanami
module Utils module Utils
# Safe dup logic # Safe dup logic
# #
@ -26,40 +26,40 @@ module Lotus
# @since 0.6.0 # @since 0.6.0
# #
# @example Basic Usage With Types That Can't Be Duped # @example Basic Usage With Types That Can't Be Duped
# require 'lotus/utils/duplicable' # require 'hanami/utils/duplicable'
# #
# object = 23 # object = 23
# puts object.object_id # => 47 # puts object.object_id # => 47
# #
# result = Lotus::Utils::Duplicable.dup(object) # result = Hanami::Utils::Duplicable.dup(object)
# #
# puts result # => 23 # puts result # => 23
# puts result.object_id # => 47 - Same object, because numbers can't be duped # puts result.object_id # => 47 - Same object, because numbers can't be duped
# #
# @example Basic Usage With Types That Can Be Duped # @example Basic Usage With Types That Can Be Duped
# require 'lotus/utils/duplicable' # require 'hanami/utils/duplicable'
# #
# object = "hello" # object = "hello"
# puts object.object_id # => 70172661782360 # puts object.object_id # => 70172661782360
# #
# result = Lotus::Utils::Duplicable.dup(object) # result = Hanami::Utils::Duplicable.dup(object)
# #
# puts result # => "hello" # puts result # => "hello"
# puts result.object_id # => 70172671467020 Different object # puts result.object_id # => 70172671467020 Different object
# #
# @example Custom Logic # @example Custom Logic
# require 'lotus/utils/duplicable' # require 'hanami/utils/duplicable'
# require 'lotus/utils/hash' # require 'hanami/utils/hash'
# #
# hash = { a: 1 } # hash = { a: 1 }
# puts hash.object_id # => 70207105061680 # puts hash.object_id # => 70207105061680
# #
# result = Lotus::Utils::Duplicable.dup(hash) do |value| # result = Hanami::Utils::Duplicable.dup(hash) do |value|
# case value # case value
# when Lotus::Utils::Hash # when Hanami::Utils::Hash
# value.deep_dup # value.deep_dup
# when ::Hash # when ::Hash
# Lotus::Utils::Hash.new(value).deep_dup.to_h # Hanami::Utils::Hash.new(value).deep_dup.to_h
# end # end
# end # end
# #

View File

@ -1,4 +1,4 @@
module Lotus module Hanami
module Utils module Utils
# HTML escape utilities # HTML escape utilities
# #
@ -72,7 +72,7 @@ module Lotus
# @since 0.4.0 # @since 0.4.0
# @api private # @api private
# #
# @see Lotus::Utils::Escape.html # @see Hanami::Utils::Escape.html
HTML_CHARS = { HTML_CHARS = {
'&' => '&amp;', '&' => '&amp;',
'<' => '&lt;', '<' => '&lt;',
@ -100,7 +100,7 @@ module Lotus
# @since 0.4.0 # @since 0.4.0
# @api private # @api private
# #
# @see Lotus::Utils::Escape.html_attribute # @see Hanami::Utils::Escape.html_attribute
HTML_ENTITIES = { HTML_ENTITIES = {
34 => 'quot', # quotation mark 34 => 'quot', # quotation mark
38 => 'amp', # ampersand 38 => 'amp', # ampersand
@ -361,15 +361,15 @@ module Lotus
# @since 0.4.0 # @since 0.4.0
# @api private # @api private
# #
# @see Lotus::Utils::Escape.url # @see Hanami::Utils::Escape.url
DEFAULT_URL_SCHEMES = ['http', 'https', 'mailto'].freeze DEFAULT_URL_SCHEMES = ['http', 'https', 'mailto'].freeze
# The output of an escape. # The output of an escape.
# #
# It's marked with this special class for two reasons: # It's marked with this special class for two reasons:
# #
# * Don't double escape the same string (this is for `Lotus::Helpers` compatibility) # * Don't double escape the same string (this is for `Hanami::Helpers` compatibility)
# * Leave open the possibility to developers to mark a string as safe with an higher API (eg. `#raw` in `Lotus::View` or `Lotus::Helpers`) # * Leave open the possibility to developers to mark a string as safe with an higher API (eg. `#raw` in `Hanami::View` or `Hanami::Helpers`)
# #
# @since 0.4.0 # @since 0.4.0
# @api private # @api private
@ -411,12 +411,12 @@ module Lotus
# @see https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet OWASP XSS Cheat Sheet Rule #1 # @see https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet OWASP XSS Cheat Sheet Rule #1
# #
# @example Good practice # @example Good practice
# <div><%= Lotus::Utils::Escape.html('<script>alert(1);</script>') %></div> # <div><%= Hanami::Utils::Escape.html('<script>alert(1);</script>') %></div>
# <div>&lt;script&gt;alert(1);&lt;&#x2F;script&gt;</div> # <div>&lt;script&gt;alert(1);&lt;&#x2F;script&gt;</div>
# #
# @example Bad practice # @example Bad practice
# # WRONG Use Escape.html_attribute # # WRONG Use Escape.html_attribute
# <a title="<%= Lotus::Utils::Escape.html('...') %>">link</a> # <a title="<%= Hanami::Utils::Escape.html('...') %>">link</a>
def self.html(input) def self.html(input)
input = encode(input) input = encode(input)
return input if input.is_a?(SafeString) return input if input.is_a?(SafeString)
@ -445,11 +445,11 @@ module Lotus
# @see https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet OWASP XSS Cheat Sheet Rule #2 # @see https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet OWASP XSS Cheat Sheet Rule #2
# #
# @example Good practice # @example Good practice
# <a title="<%= Lotus::Utils::Escape.html_attribute('...') %>">link</a> # <a title="<%= Hanami::Utils::Escape.html_attribute('...') %>">link</a>
# #
# @example Good but expensive practice # @example Good but expensive practice
# # Alternatively you can use Escape.html # # Alternatively you can use Escape.html
# <p><%= Lotus::Utils::Escape.html_attribute('...') %></p> # <p><%= Hanami::Utils::Escape.html_attribute('...') %></p>
def self.html_attribute(input) def self.html_attribute(input)
input = encode(input) input = encode(input)
return input if input.is_a?(SafeString) return input if input.is_a?(SafeString)
@ -478,16 +478,16 @@ module Lotus
# #
# @since 0.4.0 # @since 0.4.0
# #
# @see Lotus::Utils::Escape::DEFAULT_URL_SCHEMES # @see Hanami::Utils::Escape::DEFAULT_URL_SCHEMES
# @see http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/URI.html#method-c-extract # @see http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/URI.html#method-c-extract
# #
# @example Basic usage # @example Basic usage
# <% # <%
# good_input = "http://lotusrb.org" # good_input = "http://hanamirb.org"
# evil_input = "javascript:alert('xss')" # evil_input = "javascript:alert('xss')"
# #
# escaped_good_input = Lotus::Utils::Escape.url(good_input) # => "http://lotusrb.org" # escaped_good_input = Hanami::Utils::Escape.url(good_input) # => "http://hanamirb.org"
# escaped_evil_input = Lotus::Utils::Escape.url(evil_input) # => "" # escaped_evil_input = Hanami::Utils::Escape.url(evil_input) # => ""
# %> # %>
# #
# <a href="<%= escaped_good_input %>">personal website</a> # <a href="<%= escaped_good_input %>">personal website</a>
@ -500,8 +500,8 @@ module Lotus
# accepted = "ftps://ftp.example.org" # accepted = "ftps://ftp.example.org"
# rejected = "http://www.example.org" # rejected = "http://www.example.org"
# #
# escaped_accepted = Lotus::Utils::Escape.url(accepted) # => "ftps://ftp.example.org" # escaped_accepted = Hanami::Utils::Escape.url(accepted) # => "ftps://ftp.example.org"
# escaped_rejected = Lotus::Utils::Escape.url(rejected) # => "" # escaped_rejected = Hanami::Utils::Escape.url(rejected) # => ""
# %> # %>
# #
# <a href="<%= escaped_accepted %>">FTP</a> # <a href="<%= escaped_accepted %>">FTP</a>

View File

@ -1,6 +1,6 @@
require 'lotus/utils/duplicable' require 'hanami/utils/duplicable'
module Lotus module Hanami
module Utils module Utils
# Hash on steroids # Hash on steroids
# @since 0.1.0 # @since 0.1.0
@ -8,8 +8,8 @@ module Lotus
# @since 0.6.0 # @since 0.6.0
# @api private # @api private
# #
# @see Lotus::Utils::Hash#deep_dup # @see Hanami::Utils::Hash#deep_dup
# @see Lotus::Utils::Duplicable # @see Hanami::Utils::Duplicable
DUPLICATE_LOGIC = Proc.new do |value| DUPLICATE_LOGIC = Proc.new do |value|
case value case value
when Hash when Hash
@ -24,22 +24,22 @@ module Lotus
# @param hash [#to_h] the value we want to use to initialize this instance # @param hash [#to_h] the value we want to use to initialize this instance
# @param blk [Proc] define the default value # @param blk [Proc] define the default value
# #
# @return [Lotus::Utils::Hash] self # @return [Hanami::Utils::Hash] self
# #
# @since 0.1.0 # @since 0.1.0
# #
# @see http://www.ruby-doc.org/core/Hash.html#method-c-5B-5D # @see http://www.ruby-doc.org/core/Hash.html#method-c-5B-5D
# #
# @example Passing a Hash # @example Passing a Hash
# require 'lotus/utils/hash' # require 'hanami/utils/hash'
# #
# hash = Lotus::Utils::Hash.new('l' => 23) # hash = Hanami::Utils::Hash.new('l' => 23)
# hash['l'] # => 23 # hash['l'] # => 23
# #
# @example Passing a block for default # @example Passing a block for default
# require 'lotus/utils/hash' # require 'hanami/utils/hash'
# #
# hash = Lotus::Utils::Hash.new {|h,k| h[k] = [] } # hash = Hanami::Utils::Hash.new {|h,k| h[k] = [] }
# hash['foo'].push 'bar' # hash['foo'].push 'bar'
# #
# hash.to_h # => { 'foo' => ['bar'] } # hash.to_h # => { 'foo' => ['bar'] }
@ -55,9 +55,9 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/hash' # require 'hanami/utils/hash'
# #
# hash = Lotus::Utils::Hash.new 'a' => 23, 'b' => { 'c' => ['x','y','z'] } # hash = Hanami::Utils::Hash.new 'a' => 23, 'b' => { 'c' => ['x','y','z'] }
# hash.symbolize! # hash.symbolize!
# #
# hash.keys # => [:a, :b] # hash.keys # => [:a, :b]
@ -80,9 +80,9 @@ module Lotus
# @since 0.3.2 # @since 0.3.2
# #
# @example # @example
# require 'lotus/utils/hash' # require 'hanami/utils/hash'
# #
# hash = Lotus::Utils::Hash.new a: 23, b: { c: ['x','y','z'] } # hash = Hanami::Utils::Hash.new a: 23, b: { c: ['x','y','z'] }
# hash.stringify! # hash.stringify!
# #
# hash.keys # => [:a, :b] # hash.keys # => [:a, :b]
@ -98,16 +98,16 @@ module Lotus
self self
end end
# Return a deep copy of the current Lotus::Utils::Hash # Return a deep copy of the current Hanami::Utils::Hash
# #
# @return [Hash] a deep duplicated self # @return [Hash] a deep duplicated self
# #
# @since 0.3.1 # @since 0.3.1
# #
# @example # @example
# require 'lotus/utils/hash' # require 'hanami/utils/hash'
# #
# hash = Lotus::Utils::Hash.new( # hash = Hanami::Utils::Hash.new(
# 'nil' => nil, # 'nil' => nil,
# 'false' => false, # 'false' => false,
# 'true' => true, # 'true' => true,
@ -120,13 +120,13 @@ module Lotus
# 'rational' => Rational(0.3), # 'rational' => Rational(0.3),
# 'string' => 'foo bar', # 'string' => 'foo bar',
# 'hash' => { a: 1, b: 'two', c: :three }, # 'hash' => { a: 1, b: 'two', c: :three },
# 'u_hash' => Lotus::Utils::Hash.new({ a: 1, b: 'two', c: :three }) # 'u_hash' => Hanami::Utils::Hash.new({ a: 1, b: 'two', c: :three })
# ) # )
# #
# duped = hash.deep_dup # duped = hash.deep_dup
# #
# hash.class # => Lotus::Utils::Hash # hash.class # => Hanami::Utils::Hash
# duped.class # => Lotus::Utils::Hash # duped.class # => Hanami::Utils::Hash
# #
# hash.object_id # => 70147385937100 # hash.object_id # => 70147385937100
# duped.object_id # => 70147385950620 # duped.object_id # => 70147385950620
@ -157,8 +157,8 @@ module Lotus
# duped['hash'][:b] # => "TWO" # duped['hash'][:b] # => "TWO"
# hash['hash'][:b] # => "two" # hash['hash'][:b] # => "two"
# #
# # it deeply duplicates Lotus::Utils::Hash, by preserving the class # # it deeply duplicates Hanami::Utils::Hash, by preserving the class
# duped['u_hash'].class # => Lotus::Utils::Hash # duped['u_hash'].class # => Hanami::Utils::Hash
def deep_dup def deep_dup
Hash.new.tap do |result| Hash.new.tap do |result|
@hash.each {|k, v| result[k] = Duplicable.dup(v, &DUPLICATE_LOGIC) } @hash.each {|k, v| result[k] = Duplicable.dup(v, &DUPLICATE_LOGIC) }

View File

@ -1,6 +1,6 @@
require 'lotus/utils/class_attribute' require 'hanami/utils/class_attribute'
module Lotus module Hanami
module Utils module Utils
# String inflector # String inflector
# #
@ -270,13 +270,13 @@ module Lotus
# #
# @since 0.6.0 # @since 0.6.0
# #
# @see Lotus::Utils::Inflector.exception # @see Hanami::Utils::Inflector.exception
# @see Lotus::Utils::Inflector.uncountable # @see Hanami::Utils::Inflector.uncountable
# #
# @example # @example
# require 'lotus/utils/inflector' # require 'hanami/utils/inflector'
# #
# Lotus::Utils::Inflector.inflections do # Hanami::Utils::Inflector.inflections do
# exception 'analysis', 'analyses' # exception 'analysis', 'analyses'
# exception 'alga', 'algae' # exception 'alga', 'algae'
# uncountable 'music', 'butter' # uncountable 'music', 'butter'
@ -292,13 +292,13 @@ module Lotus
# #
# @since 0.6.0 # @since 0.6.0
# #
# @see Lotus::Utils::Inflector.inflections # @see Hanami::Utils::Inflector.inflections
# @see Lotus::Utils::Inflector.uncountable # @see Hanami::Utils::Inflector.uncountable
# #
# @example # @example
# require 'lotus/utils/inflector' # require 'hanami/utils/inflector'
# #
# Lotus::Utils::Inflector.inflections do # Hanami::Utils::Inflector.inflections do
# exception 'alga', 'algae' # exception 'alga', 'algae'
# end # end
def self.exception(singular, plural) def self.exception(singular, plural)
@ -312,13 +312,13 @@ module Lotus
# #
# @since 0.6.0 # @since 0.6.0
# #
# @see Lotus::Utils::Inflector.inflections # @see Hanami::Utils::Inflector.inflections
# @see Lotus::Utils::Inflector.exception # @see Hanami::Utils::Inflector.exception
# #
# @example # @example
# require 'lotus/utils/inflector' # require 'hanami/utils/inflector'
# #
# Lotus::Utils::Inflector.inflections do # Hanami::Utils::Inflector.inflections do
# uncountable 'music', 'art' # uncountable 'music', 'art'
# end # end
def self.uncountable(*words) def self.uncountable(*words)

View File

@ -1,4 +1,4 @@
module Lotus module Hanami
module Utils module Utils
# IO utils # IO utils
# #
@ -16,13 +16,13 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/io' # require 'hanami/utils/io'
# #
# class Test # class Test
# TEST_VALUE = 'initial' # TEST_VALUE = 'initial'
# end # end
# #
# Lotus::Utils::IO.silence_warnings do # Hanami::Utils::IO.silence_warnings do
# Test::TEST_VALUE = 'redefined' # Test::TEST_VALUE = 'redefined'
# end # end
def self.silence_warnings def self.silence_warnings

View File

@ -3,7 +3,7 @@ require 'date'
require 'time' require 'time'
require 'pathname' require 'pathname'
require 'bigdecimal' require 'bigdecimal'
require 'lotus/utils' require 'hanami/utils'
# Define top level constant Boolean, so it can be easily used by other libraries # Define top level constant Boolean, so it can be easily used by other libraries
# in coercions DSLs # in coercions DSLs
@ -12,7 +12,7 @@ require 'lotus/utils'
class Boolean class Boolean
end unless defined?(Boolean) end unless defined?(Boolean)
module Lotus module Hanami
module Utils module Utils
# Kernel utilities # Kernel utilities
# @since 0.1.1 # @since 0.1.1
@ -22,7 +22,7 @@ module Lotus
# @since 0.3.3 # @since 0.3.3
# @api private # @api private
# #
# @see Lotus::Utils::Kernel.Integer # @see Hanami::Utils::Kernel.Integer
NUMERIC_MATCHER = /\A([\d\/\.\+iE]+|NaN|Infinity)\z/.freeze NUMERIC_MATCHER = /\A([\d\/\.\+iE]+|NaN|Infinity)\z/.freeze
# Coerces the argument to be an Array. # Coerces the argument to be an Array.
@ -47,19 +47,19 @@ module Lotus
# @see http://www.ruby-doc.org/core/Array.html#method-i-uniq # @see http://www.ruby-doc.org/core/Array.html#method-i-uniq
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Array(nil) # => [] # Hanami::Utils::Kernel.Array(nil) # => []
# Lotus::Utils::Kernel.Array(true) # => [true] # Hanami::Utils::Kernel.Array(true) # => [true]
# Lotus::Utils::Kernel.Array(false) # => [false] # Hanami::Utils::Kernel.Array(false) # => [false]
# Lotus::Utils::Kernel.Array(1) # => [1] # Hanami::Utils::Kernel.Array(1) # => [1]
# Lotus::Utils::Kernel.Array([1]) # => [1] # Hanami::Utils::Kernel.Array([1]) # => [1]
# Lotus::Utils::Kernel.Array([1, [2]]) # => [1,2] # Hanami::Utils::Kernel.Array([1, [2]]) # => [1,2]
# Lotus::Utils::Kernel.Array([1, [2, nil]]) # => [1,2] # Hanami::Utils::Kernel.Array([1, [2, nil]]) # => [1,2]
# Lotus::Utils::Kernel.Array([1, [2, nil, 1]]) # => [1,2] # Hanami::Utils::Kernel.Array([1, [2, nil, 1]]) # => [1,2]
# #
# @example Array Interface # @example Array Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# ResultSet = Struct.new(:records) do # ResultSet = Struct.new(:records) do
# def to_a # def to_a
@ -74,10 +74,10 @@ module Lotus
# end # end
# #
# set = ResultSet.new([2,1,3]) # set = ResultSet.new([2,1,3])
# Lotus::Utils::Kernel.Array(set) # => [1,2,3] # Hanami::Utils::Kernel.Array(set) # => [1,2,3]
# #
# response = Response.new(200, {}, 'hello') # response = Response.new(200, {}, 'hello')
# Lotus::Utils::Kernel.Array(response) # => [200, {}, "hello"] # Hanami::Utils::Kernel.Array(response) # => [200, {}, "hello"]
def self.Array(arg) def self.Array(arg)
super(arg).dup.tap do |a| super(arg).dup.tap do |a|
a.flatten! a.flatten!
@ -97,21 +97,21 @@ module Lotus
# @since 0.1.1 # @since 0.1.1
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Set(nil) # => #<Set: {}> # Hanami::Utils::Kernel.Set(nil) # => #<Set: {}>
# Lotus::Utils::Kernel.Set(true) # => #<Set: {true}> # Hanami::Utils::Kernel.Set(true) # => #<Set: {true}>
# Lotus::Utils::Kernel.Set(false) # => #<Set: {false}> # Hanami::Utils::Kernel.Set(false) # => #<Set: {false}>
# Lotus::Utils::Kernel.Set(1) # => #<Set: {1}> # Hanami::Utils::Kernel.Set(1) # => #<Set: {1}>
# Lotus::Utils::Kernel.Set([1]) # => #<Set: {1}> # Hanami::Utils::Kernel.Set([1]) # => #<Set: {1}>
# Lotus::Utils::Kernel.Set([1, 1]) # => #<Set: {1}> # Hanami::Utils::Kernel.Set([1, 1]) # => #<Set: {1}>
# Lotus::Utils::Kernel.Set([1, [2]]) # => #<Set: {1, [2]}> # Hanami::Utils::Kernel.Set([1, [2]]) # => #<Set: {1, [2]}>
# Lotus::Utils::Kernel.Set([1, [2, nil]]) # => #<Set: {1, [2, nil]}> # Hanami::Utils::Kernel.Set([1, [2, nil]]) # => #<Set: {1, [2, nil]}>
# Lotus::Utils::Kernel.Set({a: 1}) # => #<Set: {[:a, 1]}> # Hanami::Utils::Kernel.Set({a: 1}) # => #<Set: {[:a, 1]}>
# #
# @example Set Interface # @example Set Interface
# require 'securerandom' # require 'securerandom'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# UuidSet = Class.new do # UuidSet = Class.new do
# def initialize(*uuids) # def initialize(*uuids)
@ -126,13 +126,13 @@ module Lotus
# end # end
# #
# uuids = UuidSet.new(SecureRandom.uuid) # uuids = UuidSet.new(SecureRandom.uuid)
# Lotus::Utils::Kernel.Set(uuids) # Hanami::Utils::Kernel.Set(uuids)
# # => #<Set: {"daa798b4-630c-4e11-b29d-92f0b1c7d075"}> # # => #<Set: {"daa798b4-630c-4e11-b29d-92f0b1c7d075"}>
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Set(BasicObject.new) # => TypeError # Hanami::Utils::Kernel.Set(BasicObject.new) # => TypeError
def self.Set(arg) def self.Set(arg)
if arg.respond_to?(:to_set) if arg.respond_to?(:to_set)
arg.to_set arg.to_set
@ -156,15 +156,15 @@ module Lotus
# @see http://www.ruby-doc.org/core/Kernel.html#method-i-Hash # @see http://www.ruby-doc.org/core/Kernel.html#method-i-Hash
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Hash(nil) # => {} # Hanami::Utils::Kernel.Hash(nil) # => {}
# Lotus::Utils::Kernel.Hash({a: 1}) # => { :a => 1 } # Hanami::Utils::Kernel.Hash({a: 1}) # => { :a => 1 }
# Lotus::Utils::Kernel.Hash([[:a, 1]]) # => { :a => 1 } # Hanami::Utils::Kernel.Hash([[:a, 1]]) # => { :a => 1 }
# Lotus::Utils::Kernel.Hash(Set.new([[:a, 1]])) # => { :a => 1 } # Hanami::Utils::Kernel.Hash(Set.new([[:a, 1]])) # => { :a => 1 }
# #
# @example Hash Interface # @example Hash Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Room = Class.new do # Room = Class.new do
# def initialize(*args) # def initialize(*args)
@ -187,16 +187,16 @@ module Lotus
# end # end
# #
# room = Room.new(:key, 123456) # room = Room.new(:key, 123456)
# Lotus::Utils::Kernel.Hash(room) # => { :key => 123456 } # Hanami::Utils::Kernel.Hash(room) # => { :key => 123456 }
# #
# record = Record.new(name: 'L') # record = Record.new(name: 'L')
# Lotus::Utils::Kernel.Hash(record) # => { :name => "L" } # Hanami::Utils::Kernel.Hash(record) # => { :name => "L" }
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Hash(input) # => TypeError # Hanami::Utils::Kernel.Hash(input) # => TypeError
if RUBY_VERSION >= '2.1' if RUBY_VERSION >= '2.1'
def self.Hash(arg) def self.Hash(arg)
if arg.respond_to?(:to_h) if arg.respond_to?(:to_h)
@ -238,23 +238,23 @@ module Lotus
# #
# @example Basic Usage # @example Basic Usage
# require 'bigdecimal' # require 'bigdecimal'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Integer(1) # => 1 # Hanami::Utils::Kernel.Integer(1) # => 1
# Lotus::Utils::Kernel.Integer(1.2) # => 1 # Hanami::Utils::Kernel.Integer(1.2) # => 1
# Lotus::Utils::Kernel.Integer(011) # => 9 # Hanami::Utils::Kernel.Integer(011) # => 9
# Lotus::Utils::Kernel.Integer(0xf5) # => 245 # Hanami::Utils::Kernel.Integer(0xf5) # => 245
# Lotus::Utils::Kernel.Integer("1") # => 1 # Hanami::Utils::Kernel.Integer("1") # => 1
# Lotus::Utils::Kernel.Integer(Rational(0.3)) # => 0 # Hanami::Utils::Kernel.Integer(Rational(0.3)) # => 0
# Lotus::Utils::Kernel.Integer(Complex(0.3)) # => 0 # Hanami::Utils::Kernel.Integer(Complex(0.3)) # => 0
# Lotus::Utils::Kernel.Integer(BigDecimal.new(12.00001)) # => 12 # Hanami::Utils::Kernel.Integer(BigDecimal.new(12.00001)) # => 12
# Lotus::Utils::Kernel.Integer(176605528590345446089) # Hanami::Utils::Kernel.Integer(176605528590345446089)
# # => 176605528590345446089 # # => 176605528590345446089
# #
# Lotus::Utils::Kernel.Integer(Time.now) # => 1396947161 # Hanami::Utils::Kernel.Integer(Time.now) # => 1396947161
# #
# @example Integer Interface # @example Integer Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# UltimateAnswer = Struct.new(:question) do # UltimateAnswer = Struct.new(:question) do
# def to_int # def to_int
@ -263,71 +263,71 @@ module Lotus
# end # end
# #
# answer = UltimateAnswer.new('The Ultimate Question of Life') # answer = UltimateAnswer.new('The Ultimate Question of Life')
# Lotus::Utils::Kernel.Integer(answer) # => 42 # Hanami::Utils::Kernel.Integer(answer) # => 42
# #
# @example Error Handling # @example Error Handling
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # nil # # nil
# Kernel.Integer(nil) # => TypeError # Kernel.Integer(nil) # => TypeError
# Lotus::Utils::Kernel.Integer(nil) # => 0 # Hanami::Utils::Kernel.Integer(nil) # => 0
# #
# # float represented as a string # # float represented as a string
# Kernel.Integer("23.4") # => TypeError # Kernel.Integer("23.4") # => TypeError
# Lotus::Utils::Kernel.Integer("23.4") # => 23 # Hanami::Utils::Kernel.Integer("23.4") # => 23
# #
# # rational represented as a string # # rational represented as a string
# Kernel.Integer("2/3") # => TypeError # Kernel.Integer("2/3") # => TypeError
# Lotus::Utils::Kernel.Integer("2/3") # => 2 # Hanami::Utils::Kernel.Integer("2/3") # => 2
# #
# # complex represented as a string # # complex represented as a string
# Kernel.Integer("2.5/1") # => TypeError # Kernel.Integer("2.5/1") # => TypeError
# Lotus::Utils::Kernel.Integer("2.5/1") # => 2 # Hanami::Utils::Kernel.Integer("2.5/1") # => 2
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'date' # require 'date'
# require 'bigdecimal' # require 'bigdecimal'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # Missing #to_int and #to_i # # Missing #to_int and #to_i
# input = OpenStruct.new(color: 'purple') # input = OpenStruct.new(color: 'purple')
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # String that doesn't represent an integer # # String that doesn't represent an integer
# input = 'hello' # input = 'hello'
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # When true # # When true
# input = true # input = true
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # When false # # When false
# input = false # input = false
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # When Date # # When Date
# input = Date.today # input = Date.today
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # When DateTime # # When DateTime
# input = DateTime.now # input = DateTime.now
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # bigdecimal infinity # # bigdecimal infinity
# input = BigDecimal.new("Infinity") # input = BigDecimal.new("Infinity")
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # bigdecimal NaN # # bigdecimal NaN
# input = BigDecimal.new("NaN") # input = BigDecimal.new("NaN")
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # big rational # # big rational
# input = Rational(-8) ** Rational(1, 3) # input = Rational(-8) ** Rational(1, 3)
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
# #
# # big complex represented as a string # # big complex represented as a string
# input = Complex(2, 3) # input = Complex(2, 3)
# Lotus::Utils::Kernel.Integer(input) # => TypeError # Hanami::Utils::Kernel.Integer(input) # => TypeError
def self.Integer(arg) def self.Integer(arg)
super(arg) super(arg)
rescue ArgumentError, TypeError, NoMethodError rescue ArgumentError, TypeError, NoMethodError
@ -358,21 +358,21 @@ module Lotus
# @see http://www.ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/BigDecimal.html # @see http://www.ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/BigDecimal.html
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.BigDecimal(1) # => 1 # Hanami::Utils::Kernel.BigDecimal(1) # => 1
# Lotus::Utils::Kernel.BigDecimal(1.2) # => 1 # Hanami::Utils::Kernel.BigDecimal(1.2) # => 1
# Lotus::Utils::Kernel.BigDecimal(011) # => 9 # Hanami::Utils::Kernel.BigDecimal(011) # => 9
# Lotus::Utils::Kernel.BigDecimal(0xf5) # => 245 # Hanami::Utils::Kernel.BigDecimal(0xf5) # => 245
# Lotus::Utils::Kernel.BigDecimal("1") # => 1 # Hanami::Utils::Kernel.BigDecimal("1") # => 1
# Lotus::Utils::Kernel.BigDecimal(Rational(0.3)) # => 0.3 # Hanami::Utils::Kernel.BigDecimal(Rational(0.3)) # => 0.3
# Lotus::Utils::Kernel.BigDecimal(Complex(0.3)) # => 0.3 # Hanami::Utils::Kernel.BigDecimal(Complex(0.3)) # => 0.3
# Lotus::Utils::Kernel.BigDecimal(BigDecimal.new(12.00001)) # => 12.00001 # Hanami::Utils::Kernel.BigDecimal(BigDecimal.new(12.00001)) # => 12.00001
# Lotus::Utils::Kernel.BigDecimal(176605528590345446089) # Hanami::Utils::Kernel.BigDecimal(176605528590345446089)
# # => 176605528590345446089 # # => 176605528590345446089
# #
# @example BigDecimal Interface # @example BigDecimal Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# UltimateAnswer = Struct.new(:question) do # UltimateAnswer = Struct.new(:question) do
# def to_d # def to_d
@ -381,43 +381,43 @@ module Lotus
# end # end
# #
# answer = UltimateAnswer.new('The Ultimate Question of Life') # answer = UltimateAnswer.new('The Ultimate Question of Life')
# Lotus::Utils::Kernel.BigDecimal(answer) # Hanami::Utils::Kernel.BigDecimal(answer)
# # => #<BigDecimal:7fabfd148588,'0.42E2',9(27)> # # => #<BigDecimal:7fabfd148588,'0.42E2',9(27)>
# #
# @example Unchecked exceptions # @example Unchecked exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # When nil # # When nil
# input = nil # input = nil
# Lotus::Utils::Kernel.BigDecimal(nil) # => TypeError # Hanami::Utils::Kernel.BigDecimal(nil) # => TypeError
# #
# # When true # # When true
# input = true # input = true
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
# #
# # When false # # When false
# input = false # input = false
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
# #
# # When Date # # When Date
# input = Date.today # input = Date.today
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
# #
# # When DateTime # # When DateTime
# input = DateTime.now # input = DateTime.now
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
# #
# # When Time # # When Time
# input = Time.now # input = Time.now
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
# #
# # String that doesn't represent a big decimal # # String that doesn't represent a big decimal
# input = 'hello' # input = 'hello'
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
def self.BigDecimal(arg) def self.BigDecimal(arg)
case arg case arg
when ->(a) { a.respond_to?(:to_d) } then arg.to_d when ->(a) { a.respond_to?(:to_d) } then arg.to_d
@ -449,23 +449,23 @@ module Lotus
# #
# @example Basic Usage # @example Basic Usage
# require 'bigdecimal' # require 'bigdecimal'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Float(1) # => 1.0 # Hanami::Utils::Kernel.Float(1) # => 1.0
# Lotus::Utils::Kernel.Float(1.2) # => 1.2 # Hanami::Utils::Kernel.Float(1.2) # => 1.2
# Lotus::Utils::Kernel.Float(011) # => 9.0 # Hanami::Utils::Kernel.Float(011) # => 9.0
# Lotus::Utils::Kernel.Float(0xf5) # => 245.0 # Hanami::Utils::Kernel.Float(0xf5) # => 245.0
# Lotus::Utils::Kernel.Float("1") # => 1.0 # Hanami::Utils::Kernel.Float("1") # => 1.0
# Lotus::Utils::Kernel.Float(Rational(0.3)) # => 0.3 # Hanami::Utils::Kernel.Float(Rational(0.3)) # => 0.3
# Lotus::Utils::Kernel.Float(Complex(0.3)) # => 0.3 # Hanami::Utils::Kernel.Float(Complex(0.3)) # => 0.3
# Lotus::Utils::Kernel.Float(BigDecimal.new(12.00001)) # => 12.00001 # Hanami::Utils::Kernel.Float(BigDecimal.new(12.00001)) # => 12.00001
# Lotus::Utils::Kernel.Float(176605528590345446089) # Hanami::Utils::Kernel.Float(176605528590345446089)
# # => 176605528590345446089.0 # # => 176605528590345446089.0
# #
# Lotus::Utils::Kernel.Float(Time.now) # => 397750945.515169 # Hanami::Utils::Kernel.Float(Time.now) # => 397750945.515169
# #
# @example Float Interface # @example Float Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class Pi # class Pi
# def to_f # def to_f
@ -474,76 +474,76 @@ module Lotus
# end # end
# #
# pi = Pi.new # pi = Pi.new
# Lotus::Utils::Kernel.Float(pi) # => 3.14 # Hanami::Utils::Kernel.Float(pi) # => 3.14
# #
# @example Error Handling # @example Error Handling
# require 'bigdecimal' # require 'bigdecimal'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # nil # # nil
# Kernel.Float(nil) # => TypeError # Kernel.Float(nil) # => TypeError
# Lotus::Utils::Kernel.Float(nil) # => 0.0 # Hanami::Utils::Kernel.Float(nil) # => 0.0
# #
# # float represented as a string # # float represented as a string
# Kernel.Float("23.4") # => TypeError # Kernel.Float("23.4") # => TypeError
# Lotus::Utils::Kernel.Float("23.4") # => 23.4 # Hanami::Utils::Kernel.Float("23.4") # => 23.4
# #
# # rational represented as a string # # rational represented as a string
# Kernel.Float("2/3") # => TypeError # Kernel.Float("2/3") # => TypeError
# Lotus::Utils::Kernel.Float("2/3") # => 2.0 # Hanami::Utils::Kernel.Float("2/3") # => 2.0
# #
# # complex represented as a string # # complex represented as a string
# Kernel.Float("2.5/1") # => TypeError # Kernel.Float("2.5/1") # => TypeError
# Lotus::Utils::Kernel.Float("2.5/1") # => 2.5 # Hanami::Utils::Kernel.Float("2.5/1") # => 2.5
# #
# # bigdecimal infinity # # bigdecimal infinity
# input = BigDecimal.new("Infinity") # input = BigDecimal.new("Infinity")
# Lotus::Utils::Kernel.Float(input) # => Infinity # Hanami::Utils::Kernel.Float(input) # => Infinity
# #
# # bigdecimal NaN # # bigdecimal NaN
# input = BigDecimal.new("NaN") # input = BigDecimal.new("NaN")
# Lotus::Utils::Kernel.Float(input) # => NaN # Hanami::Utils::Kernel.Float(input) # => NaN
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'date' # require 'date'
# require 'bigdecimal' # require 'bigdecimal'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # Missing #to_f # # Missing #to_f
# input = OpenStruct.new(color: 'purple') # input = OpenStruct.new(color: 'purple')
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # When true # # When true
# input = true # input = true
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # When false # # When false
# input = false # input = false
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # When Date # # When Date
# input = Date.today # input = Date.today
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # When DateTime # # When DateTime
# input = DateTime.now # input = DateTime.now
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # Missing #nil? # # Missing #nil?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # String that doesn't represent a float # # String that doesn't represent a float
# input = 'hello' # input = 'hello'
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # big rational # # big rational
# input = Rational(-8) ** Rational(1, 3) # input = Rational(-8) ** Rational(1, 3)
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
# #
# # big complex represented as a string # # big complex represented as a string
# input = Complex(2, 3) # input = Complex(2, 3)
# Lotus::Utils::Kernel.Float(input) # => TypeError # Hanami::Utils::Kernel.Float(input) # => TypeError
def self.Float(arg) def self.Float(arg)
super(arg) super(arg)
rescue ArgumentError, TypeError rescue ArgumentError, TypeError
@ -579,43 +579,43 @@ module Lotus
# @example Basic Usage # @example Basic Usage
# require 'date' # require 'date'
# require 'bigdecimal' # require 'bigdecimal'
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.String('') # => "" # Hanami::Utils::Kernel.String('') # => ""
# Lotus::Utils::Kernel.String('ciao') # => "ciao" # Hanami::Utils::Kernel.String('ciao') # => "ciao"
# #
# Lotus::Utils::Kernel.String(true) # => "true" # Hanami::Utils::Kernel.String(true) # => "true"
# Lotus::Utils::Kernel.String(false) # => "false" # Hanami::Utils::Kernel.String(false) # => "false"
# #
# Lotus::Utils::Kernel.String(:lotus) # => "lotus" # Hanami::Utils::Kernel.String(:hanami) # => "hanami"
# #
# Lotus::Utils::Kernel.String(Picture) # => "Picture" # class # Hanami::Utils::Kernel.String(Picture) # => "Picture" # class
# Lotus::Utils::Kernel.String(Lotus) # => "Lotus" # module # Hanami::Utils::Kernel.String(Hanami) # => "Hanami" # module
# #
# Lotus::Utils::Kernel.String([]) # => "[]" # Hanami::Utils::Kernel.String([]) # => "[]"
# Lotus::Utils::Kernel.String([1,2,3]) # => "[1, 2, 3]" # Hanami::Utils::Kernel.String([1,2,3]) # => "[1, 2, 3]"
# Lotus::Utils::Kernel.String(%w[a b c]) # => "[\"a\", \"b\", \"c\"]" # Hanami::Utils::Kernel.String(%w[a b c]) # => "[\"a\", \"b\", \"c\"]"
# #
# Lotus::Utils::Kernel.String({}) # => "{}" # Hanami::Utils::Kernel.String({}) # => "{}"
# Lotus::Utils::Kernel.String({a: 1, 'b' => 'c'}) # => "{:a=>1, \"b\"=>\"c\"}" # Hanami::Utils::Kernel.String({a: 1, 'b' => 'c'}) # => "{:a=>1, \"b\"=>\"c\"}"
# #
# Lotus::Utils::Kernel.String(Date.today) # => "2014-04-11" # Hanami::Utils::Kernel.String(Date.today) # => "2014-04-11"
# Lotus::Utils::Kernel.String(DateTime.now) # => "2014-04-11T10:15:06+02:00" # Hanami::Utils::Kernel.String(DateTime.now) # => "2014-04-11T10:15:06+02:00"
# Lotus::Utils::Kernel.String(Time.now) # => "2014-04-11 10:15:53 +0200" # Hanami::Utils::Kernel.String(Time.now) # => "2014-04-11 10:15:53 +0200"
# #
# Lotus::Utils::Kernel.String(1) # => "1" # Hanami::Utils::Kernel.String(1) # => "1"
# Lotus::Utils::Kernel.String(3.14) # => "3.14" # Hanami::Utils::Kernel.String(3.14) # => "3.14"
# Lotus::Utils::Kernel.String(013) # => "11" # Hanami::Utils::Kernel.String(013) # => "11"
# Lotus::Utils::Kernel.String(0xc0ff33) # => "12648243" # Hanami::Utils::Kernel.String(0xc0ff33) # => "12648243"
# #
# Lotus::Utils::Kernel.String(Rational(-22)) # => "-22/1" # Hanami::Utils::Kernel.String(Rational(-22)) # => "-22/1"
# Lotus::Utils::Kernel.String(Complex(11, 2)) # => "11+2i" # Hanami::Utils::Kernel.String(Complex(11, 2)) # => "11+2i"
# Lotus::Utils::Kernel.String(BigDecimal.new(7944.2343, 10)) # => "0.79442343E4" # Hanami::Utils::Kernel.String(BigDecimal.new(7944.2343, 10)) # => "0.79442343E4"
# Lotus::Utils::Kernel.String(BigDecimal.new('Infinity')) # => "Infinity" # Hanami::Utils::Kernel.String(BigDecimal.new('Infinity')) # => "Infinity"
# Lotus::Utils::Kernel.String(BigDecimal.new('NaN')) # => "Infinity" # Hanami::Utils::Kernel.String(BigDecimal.new('NaN')) # => "Infinity"
# #
# @example String interface # @example String interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# SimpleObject = Class.new(BasicObject) do # SimpleObject = Class.new(BasicObject) do
# def to_s # def to_s
@ -632,22 +632,22 @@ module Lotus
# simple = SimpleObject.new # simple = SimpleObject.new
# isbn = Isbn.new(123) # isbn = Isbn.new(123)
# #
# Lotus::Utils::Kernel.String(simple) # => "simple object" # Hanami::Utils::Kernel.String(simple) # => "simple object"
# Lotus::Utils::Kernel.String(isbn) # => "123" # Hanami::Utils::Kernel.String(isbn) # => "123"
# #
# @example Comparison with Ruby # @example Comparison with Ruby
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # nil # # nil
# Kernel.String(nil) # => "" # Kernel.String(nil) # => ""
# Lotus::Utils::Kernel.String(nil) # => "" # Hanami::Utils::Kernel.String(nil) # => ""
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # Missing #to_s or #to_str # # Missing #to_s or #to_str
# input = BaseObject.new # input = BaseObject.new
# Lotus::Utils::Kernel.String(input) # => TypeError # Hanami::Utils::Kernel.String(input) # => TypeError
if Utils.rubinius? if Utils.rubinius?
def self.String(arg) def self.String(arg)
case arg case arg
@ -681,25 +681,25 @@ module Lotus
# @since 0.1.1 # @since 0.1.1
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Date(Date.today) # Hanami::Utils::Kernel.Date(Date.today)
# # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)> # # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)>
# #
# Lotus::Utils::Kernel.Date(DateTime.now) # Hanami::Utils::Kernel.Date(DateTime.now)
# # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)> # # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)>
# #
# Lotus::Utils::Kernel.Date(Time.now) # Hanami::Utils::Kernel.Date(Time.now)
# # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)> # # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)>
# #
# Lotus::Utils::Kernel.Date('2014-04-17') # Hanami::Utils::Kernel.Date('2014-04-17')
# # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)> # # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)>
# #
# Lotus::Utils::Kernel.Date('2014-04-17 22:37:15') # Hanami::Utils::Kernel.Date('2014-04-17 22:37:15')
# # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)> # # => #<Date: 2014-04-17 ((2456765j,0s,0n),+0s,2299161j)>
# #
# @example Date Interface # @example Date Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class Christmas # class Christmas
# def to_date # def to_date
@ -707,23 +707,23 @@ module Lotus
# end # end
# end # end
# #
# Lotus::Utils::Kernel.Date(Christmas.new) # Hanami::Utils::Kernel.Date(Christmas.new)
# # => #<Date: 2014-12-25 ((2457017j,0s,0n),+0s,2299161j)> # # => #<Date: 2014-12-25 ((2457017j,0s,0n),+0s,2299161j)>
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # nil # # nil
# input = nil # input = nil
# Lotus::Utils::Kernel.Date(input) # => TypeError # Hanami::Utils::Kernel.Date(input) # => TypeError
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Date(input) # => TypeError # Hanami::Utils::Kernel.Date(input) # => TypeError
# #
# # Missing #to_s? # # Missing #to_s?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Date(input) # => TypeError # Hanami::Utils::Kernel.Date(input) # => TypeError
def self.Date(arg) def self.Date(arg)
if arg.respond_to?(:to_date) if arg.respond_to?(:to_date)
arg.to_date arg.to_date
@ -745,28 +745,28 @@ module Lotus
# @since 0.1.1 # @since 0.1.1
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.DateTime(3483943) # Hanami::Utils::Kernel.DateTime(3483943)
# # => Time.at(3483943).to_datetime #<DateTime: 1970-02-10T08:45:43+01:00 ((2440628j,27943s,0n),+3600s,2299161j)> # # => Time.at(3483943).to_datetime #<DateTime: 1970-02-10T08:45:43+01:00 ((2440628j,27943s,0n),+3600s,2299161j)>
# #
# Lotus::Utils::Kernel.DateTime(DateTime.now) # Hanami::Utils::Kernel.DateTime(DateTime.now)
# # => #<DateTime: 2014-04-18T09:33:49+02:00 ((2456766j,27229s,690849000n),+7200s,2299161j)> # # => #<DateTime: 2014-04-18T09:33:49+02:00 ((2456766j,27229s,690849000n),+7200s,2299161j)>
# #
# Lotus::Utils::Kernel.DateTime(Date.today) # Hanami::Utils::Kernel.DateTime(Date.today)
# # => #<DateTime: 2014-04-18T00:00:00+00:00 ((2456766j,0s,0n),+0s,2299161j)> # # => #<DateTime: 2014-04-18T00:00:00+00:00 ((2456766j,0s,0n),+0s,2299161j)>
# #
# Lotus::Utils::Kernel.Date(Time.now) # Hanami::Utils::Kernel.Date(Time.now)
# # => #<DateTime: 2014-04-18T09:34:49+02:00 ((2456766j,27289s,832907000n),+7200s,2299161j)> # # => #<DateTime: 2014-04-18T09:34:49+02:00 ((2456766j,27289s,832907000n),+7200s,2299161j)>
# #
# Lotus::Utils::Kernel.DateTime('2014-04-18') # Hanami::Utils::Kernel.DateTime('2014-04-18')
# # => #<DateTime: 2014-04-18T00:00:00+00:00 ((2456766j,0s,0n),+0s,2299161j)> # # => #<DateTime: 2014-04-18T00:00:00+00:00 ((2456766j,0s,0n),+0s,2299161j)>
# #
# Lotus::Utils::Kernel.DateTime('2014-04-18 09:35:42') # Hanami::Utils::Kernel.DateTime('2014-04-18 09:35:42')
# # => #<DateTime: 2014-04-18T09:35:42+00:00 ((2456766j,34542s,0n),+0s,2299161j)> # # => #<DateTime: 2014-04-18T09:35:42+00:00 ((2456766j,34542s,0n),+0s,2299161j)>
# #
# @example DateTime Interface # @example DateTime Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class NewYearEve # class NewYearEve
# def to_datetime # def to_datetime
@ -774,23 +774,23 @@ module Lotus
# end # end
# end # end
# #
# Lotus::Utils::Kernel.Date(NewYearEve.new) # Hanami::Utils::Kernel.Date(NewYearEve.new)
# # => #<DateTime: 2014-01-01T00:00:00+00:00 ((2456659j,0s,0n),+0s,2299161j)> # # => #<DateTime: 2014-01-01T00:00:00+00:00 ((2456659j,0s,0n),+0s,2299161j)>
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # When nil # # When nil
# input = nil # input = nil
# Lotus::Utils::Kernel.DateTime(input) # => TypeError # Hanami::Utils::Kernel.DateTime(input) # => TypeError
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.DateTime(input) # => TypeError # Hanami::Utils::Kernel.DateTime(input) # => TypeError
# #
# # Missing #to_s? # # Missing #to_s?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.DateTime(input) # => TypeError # Hanami::Utils::Kernel.DateTime(input) # => TypeError
def self.DateTime(arg) def self.DateTime(arg)
case arg case arg
when ->(a) { a.respond_to?(:to_datetime) } then arg.to_datetime when ->(a) { a.respond_to?(:to_datetime) } then arg.to_datetime
@ -813,25 +813,25 @@ module Lotus
# @since 0.1.1 # @since 0.1.1
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Time(Time.now) # Hanami::Utils::Kernel.Time(Time.now)
# # => 2014-04-18 15:56:39 +0200 # # => 2014-04-18 15:56:39 +0200
# #
# Lotus::Utils::Kernel.Time(DateTime.now) # Hanami::Utils::Kernel.Time(DateTime.now)
# # => 2014-04-18 15:56:39 +0200 # # => 2014-04-18 15:56:39 +0200
# #
# Lotus::Utils::Kernel.Time(Date.today) # Hanami::Utils::Kernel.Time(Date.today)
# # => 2014-04-18 00:00:00 +0200 # # => 2014-04-18 00:00:00 +0200
# #
# Lotus::Utils::Kernel.Time('2014-04-18') # Hanami::Utils::Kernel.Time('2014-04-18')
# # => 2014-04-18 00:00:00 +0200 # # => 2014-04-18 00:00:00 +0200
# #
# Lotus::Utils::Kernel.Time('2014-04-18 15:58:02') # Hanami::Utils::Kernel.Time('2014-04-18 15:58:02')
# # => 2014-04-18 15:58:02 +0200 # # => 2014-04-18 15:58:02 +0200
# #
# @example Time Interface # @example Time Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class Epoch # class Epoch
# def to_time # def to_time
@ -839,23 +839,23 @@ module Lotus
# end # end
# end # end
# #
# Lotus::Utils::Kernel.Time(Epoch.new) # Hanami::Utils::Kernel.Time(Epoch.new)
# # => 1970-01-01 01:00:00 +0100 # # => 1970-01-01 01:00:00 +0100
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # When nil # # When nil
# input = nil # input = nil
# Lotus::Utils::Kernel.Time(input) # => TypeError # Hanami::Utils::Kernel.Time(input) # => TypeError
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Time(input) # => TypeError # Hanami::Utils::Kernel.Time(input) # => TypeError
# #
# # Missing #to_s? # # Missing #to_s?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Time(input) # => TypeError # Hanami::Utils::Kernel.Time(input) # => TypeError
def self.Time(arg) def self.Time(arg)
case arg case arg
when ->(a) { a.respond_to?(:to_time) } then arg.to_time when ->(a) { a.respond_to?(:to_time) } then arg.to_time
@ -878,17 +878,17 @@ module Lotus
# @since 0.1.1 # @since 0.1.1
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Boolean(nil) # => false # Hanami::Utils::Kernel.Boolean(nil) # => false
# Lotus::Utils::Kernel.Boolean(0) # => false # Hanami::Utils::Kernel.Boolean(0) # => false
# Lotus::Utils::Kernel.Boolean(1) # => true # Hanami::Utils::Kernel.Boolean(1) # => true
# Lotus::Utils::Kernel.Boolean('0') # => false # Hanami::Utils::Kernel.Boolean('0') # => false
# Lotus::Utils::Kernel.Boolean('1') # => true # Hanami::Utils::Kernel.Boolean('1') # => true
# Lotus::Utils::Kernel.Boolean(Object.new) # => true # Hanami::Utils::Kernel.Boolean(Object.new) # => true
# #
# @example Boolean Interface # @example Boolean Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Answer = Struct.new(:answer) do # Answer = Struct.new(:answer) do
# def to_bool # def to_bool
@ -900,14 +900,14 @@ module Lotus
# end # end
# #
# answer = Answer.new('yes') # answer = Answer.new('yes')
# Lotus::Utils::Kernel.Boolean(answer) # => true # Hanami::Utils::Kernel.Boolean(answer) # => true
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Boolean(input) # => TypeError # Hanami::Utils::Kernel.Boolean(input) # => TypeError
def self.Boolean(arg) def self.Boolean(arg)
case arg case arg
when Numeric then arg > 0 && arg <= 1 when Numeric then arg > 0 && arg <= 1
@ -931,13 +931,13 @@ module Lotus
# @since 0.1.2 # @since 0.1.2
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Pathname(Pathname.new('/path/to')) # => #<Pathname:/path/to> # Hanami::Utils::Kernel.Pathname(Pathname.new('/path/to')) # => #<Pathname:/path/to>
# Lotus::Utils::Kernel.Pathname('/path/to') # => #<Pathname:/path/to> # Hanami::Utils::Kernel.Pathname('/path/to') # => #<Pathname:/path/to>
# #
# @example Pathname Interface # @example Pathname Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class HomePath # class HomePath
# def to_pathname # def to_pathname
@ -945,10 +945,10 @@ module Lotus
# end # end
# end # end
# #
# Lotus::Utils::Kernel.Pathname(HomePath.new) # => #<Pathname:/Users/luca> # Hanami::Utils::Kernel.Pathname(HomePath.new) # => #<Pathname:/Users/luca>
# #
# @example String Interface # @example String Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class RootPath # class RootPath
# def to_str # def to_str
@ -956,18 +956,18 @@ module Lotus
# end # end
# end # end
# #
# Lotus::Utils::Kernel.Pathname(RootPath.new) # => #<Pathname:/> # Hanami::Utils::Kernel.Pathname(RootPath.new) # => #<Pathname:/>
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # When nil # # When nil
# input = nil # input = nil
# Lotus::Utils::Kernel.Pathname(input) # => TypeError # Hanami::Utils::Kernel.Pathname(input) # => TypeError
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Pathname(input) # => TypeError # Hanami::Utils::Kernel.Pathname(input) # => TypeError
def self.Pathname(arg) def self.Pathname(arg)
case arg case arg
when ->(a) { a.respond_to?(:to_pathname) } then arg.to_pathname when ->(a) { a.respond_to?(:to_pathname) } then arg.to_pathname
@ -989,13 +989,13 @@ module Lotus
# @since 0.2.0 # @since 0.2.0
# #
# @example Basic Usage # @example Basic Usage
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# Lotus::Utils::Kernel.Symbol(:hello) # => :hello # Hanami::Utils::Kernel.Symbol(:hello) # => :hello
# Lotus::Utils::Kernel.Symbol('hello') # => :hello # Hanami::Utils::Kernel.Symbol('hello') # => :hello
# #
# @example Symbol Interface # @example Symbol Interface
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# class StatusSymbol # class StatusSymbol
# def to_sym # def to_sym
@ -1003,22 +1003,22 @@ module Lotus
# end # end
# end # end
# #
# Lotus::Utils::Kernel.Symbol(StatusSymbol.new) # => :success # Hanami::Utils::Kernel.Symbol(StatusSymbol.new) # => :success
# #
# @example Unchecked Exceptions # @example Unchecked Exceptions
# require 'lotus/utils/kernel' # require 'hanami/utils/kernel'
# #
# # When nil # # When nil
# input = nil # input = nil
# Lotus::Utils::Kernel.Symbol(input) # => TypeError # Hanami::Utils::Kernel.Symbol(input) # => TypeError
# #
# # When empty string # # When empty string
# input = '' # input = ''
# Lotus::Utils::Kernel.Symbol(input) # => TypeError # Hanami::Utils::Kernel.Symbol(input) # => TypeError
# #
# # Missing #respond_to? # # Missing #respond_to?
# input = BasicObject.new # input = BasicObject.new
# Lotus::Utils::Kernel.Symbol(input) # => TypeError # Hanami::Utils::Kernel.Symbol(input) # => TypeError
def self.Symbol(arg) def self.Symbol(arg)
case arg case arg
when '' then raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol" when '' then raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"

View File

@ -1,6 +1,6 @@
require 'lotus/utils/kernel' require 'hanami/utils/kernel'
module Lotus module Hanami
module Utils module Utils
# A collection of loading paths. # A collection of loading paths.
# #
@ -11,12 +11,12 @@ module Lotus
# @param paths [String, Pathname, Array<String>, Array<Pathname>] A single # @param paths [String, Pathname, Array<String>, Array<Pathname>] A single
# or a collection of objects that can be converted into a Pathname # or a collection of objects that can be converted into a Pathname
# #
# @return [Lotus::Utils::LoadPaths] self # @return [Hanami::Utils::LoadPaths] self
# #
# @since 0.2.0 # @since 0.2.0
# #
# @see http://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html # @see http://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html
# @see Lotus::Utils::Kernel.Pathname # @see Hanami::Utils::Kernel.Pathname
def initialize(*paths) def initialize(*paths)
@paths = Utils::Kernel.Array(paths) @paths = Utils::Kernel.Array(paths)
end end
@ -31,19 +31,19 @@ module Lotus
# @see http://ruby-doc.org/core/Object.html#method-i-dup # @see http://ruby-doc.org/core/Object.html#method-i-dup
# #
# @example # @example
# require 'lotus/utils/load_paths' # require 'hanami/utils/load_paths'
# #
# paths = Lotus::Utils::LoadPaths.new '.' # paths = Hanami::Utils::LoadPaths.new '.'
# paths2 = paths.dup # paths2 = paths.dup
# #
# paths << '..' # paths << '..'
# paths2 << '../..' # paths2 << '../..'
# #
# paths # paths
# # => #<Lotus::Utils::LoadPaths:0x007f84e0cad430 @paths=[".", ".."]> # # => #<Hanami::Utils::LoadPaths:0x007f84e0cad430 @paths=[".", ".."]>
# #
# paths2 # paths2
# # => #<Lotus::Utils::LoadPaths:0x007faedc4ad3e0 @paths=[".", "../.."]> # # => #<Hanami::Utils::LoadPaths:0x007faedc4ad3e0 @paths=[".", "../.."]>
def initialize_copy(original) def initialize_copy(original)
@paths = original.instance_variable_get(:@paths).dup @paths = original.instance_variable_get(:@paths).dup
end end
@ -73,41 +73,41 @@ module Lotus
# @param paths [String, Pathname, Array<String>, Array<Pathname>] A single # @param paths [String, Pathname, Array<String>, Array<Pathname>] A single
# or a collection of objects that can be converted into a Pathname # or a collection of objects that can be converted into a Pathname
# #
# @return [Lotus::Utils::LoadPaths] self # @return [Hanami::Utils::LoadPaths] self
# #
# @raise [RuntimeError] if the object was previously frozen # @raise [RuntimeError] if the object was previously frozen
# #
# @since 0.2.0 # @since 0.2.0
# #
# @see http://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html # @see http://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html
# @see Lotus::Utils::Kernel.Pathname # @see Hanami::Utils::Kernel.Pathname
# @see Lotus::Utils::LoadPaths#freeze # @see Hanami::Utils::LoadPaths#freeze
# #
# @example Basic usage # @example Basic usage
# require 'lotus/utils/load_paths' # require 'hanami/utils/load_paths'
# #
# paths = Lotus::Utils::LoadPaths.new # paths = Hanami::Utils::LoadPaths.new
# paths.push '.' # paths.push '.'
# paths.push '..', '../..' # paths.push '..', '../..'
# #
# @example Chainable calls # @example Chainable calls
# require 'lotus/utils/load_paths' # require 'hanami/utils/load_paths'
# #
# paths = Lotus::Utils::LoadPaths.new # paths = Hanami::Utils::LoadPaths.new
# paths.push('.') # paths.push('.')
# .push('..', '../..') # .push('..', '../..')
# #
# @example Shovel alias (#<<) # @example Shovel alias (#<<)
# require 'lotus/utils/load_paths' # require 'hanami/utils/load_paths'
# #
# paths = Lotus::Utils::LoadPaths.new # paths = Hanami::Utils::LoadPaths.new
# paths << '.' # paths << '.'
# paths << ['..', '../..'] # paths << ['..', '../..']
# #
# @example Chainable calls with shovel alias (#<<) # @example Chainable calls with shovel alias (#<<)
# require 'lotus/utils/load_paths' # require 'hanami/utils/load_paths'
# #
# paths = Lotus::Utils::LoadPaths.new # paths = Hanami::Utils::LoadPaths.new
# paths << '.' << '../..' # paths << '.' << '../..'
def push(*paths) def push(*paths)
@paths.push(*paths) @paths.push(*paths)
@ -124,9 +124,9 @@ module Lotus
# @see http://ruby-doc.org/core/Object.html#method-i-freeze # @see http://ruby-doc.org/core/Object.html#method-i-freeze
# #
# @example # @example
# require 'lotus/utils/load_paths' # require 'hanami/utils/load_paths'
# #
# paths = Lotus::Utils::LoadPaths.new # paths = Hanami::Utils::LoadPaths.new
# paths.freeze # paths.freeze
# #
# paths.frozen? # => true # paths.frozen? # => true

View File

@ -1,12 +1,12 @@
require 'lotus/utils/string' require 'hanami/utils/string'
require 'lotus/utils/kernel' require 'hanami/utils/kernel'
module Lotus module Hanami
module Utils module Utils
# Prefixed string # Prefixed string
# #
# @since 0.1.0 # @since 0.1.0
class PathPrefix < Lotus::Utils::String class PathPrefix < Hanami::Utils::String
# Path separator # Path separator
# #
# @since 0.3.1 # @since 0.3.1
@ -22,7 +22,7 @@ module Lotus
# #
# @since 0.1.0 # @since 0.1.0
# #
# @see Lotus::Utils::PathPrefix::DEFAULT_SEPARATOR # @see Hanami::Utils::PathPrefix::DEFAULT_SEPARATOR
def initialize(string = nil, separator = DEFAULT_SEPARATOR) def initialize(string = nil, separator = DEFAULT_SEPARATOR)
super(string) super(string)
@separator = separator @separator = separator
@ -33,25 +33,25 @@ module Lotus
# #
# @param strings [::String] the token(s) we want to join # @param strings [::String] the token(s) we want to join
# #
# @return [Lotus::Utils::PathPrefix] the joined string # @return [Hanami::Utils::PathPrefix] the joined string
# #
# @since 0.1.0 # @since 0.1.0
# #
# @example Single string # @example Single string
# require 'lotus/utils/path_prefix' # require 'hanami/utils/path_prefix'
# #
# path_prefix = Lotus::Utils::PathPrefix.new('/posts') # path_prefix = Hanami::Utils::PathPrefix.new('/posts')
# path_prefix.join('new').to_s # => "/posts/new" # path_prefix.join('new').to_s # => "/posts/new"
# path_prefix.join('/new').to_s # => "/posts/new" # path_prefix.join('/new').to_s # => "/posts/new"
# #
# path_prefix = Lotus::Utils::PathPrefix.new('posts') # path_prefix = Hanami::Utils::PathPrefix.new('posts')
# path_prefix.join('new').to_s # => "/posts/new" # path_prefix.join('new').to_s # => "/posts/new"
# path_prefix.join('/new').to_s # => "/posts/new" # path_prefix.join('/new').to_s # => "/posts/new"
# #
# @example Multiple strings # @example Multiple strings
# require 'lotus/utils/path_prefix' # require 'hanami/utils/path_prefix'
# #
# path_prefix = Lotus::Utils::PathPrefix.new('myapp') # path_prefix = Hanami::Utils::PathPrefix.new('myapp')
# path_prefix.join('/assets', 'application.js').to_s # path_prefix.join('/assets', 'application.js').to_s
# # => "/myapp/assets/application.js" # # => "/myapp/assets/application.js"
def join(*strings) def join(*strings)
@ -64,7 +64,7 @@ module Lotus
# @param strings [::String] the tokens we want to join # @param strings [::String] the tokens we want to join
# @param separator [::String] the separator used between tokens # @param separator [::String] the separator used between tokens
# #
# @return [Lotus::Utils::PathPrefix] the joined string # @return [Hanami::Utils::PathPrefix] the joined string
# #
# @raise [TypeError] if one of the argument can't be treated as a # @raise [TypeError] if one of the argument can't be treated as a
# string # string
@ -72,9 +72,9 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/path_prefix' # require 'hanami/utils/path_prefix'
# #
# path_prefix = Lotus::Utils::PathPrefix.new 'posts' # path_prefix = Hanami::Utils::PathPrefix.new 'posts'
# path_prefix.relative_join('new').to_s # => 'posts/new' # path_prefix.relative_join('new').to_s # => 'posts/new'
# path_prefix.relative_join('new', '_').to_s # => 'posts_new' # path_prefix.relative_join('new', '_').to_s # => 'posts_new'
def relative_join(strings, separator = @separator) def relative_join(strings, separator = @separator)
@ -114,10 +114,10 @@ module Lotus
# @api private # @api private
# #
# @example # @example
# require 'lotus/utils/path_prefix' # require 'hanami/utils/path_prefix'
# #
# Lotus::Utils::PathPrefix.new('/posts').absolute? #=> true # Hanami::Utils::PathPrefix.new('/posts').absolute? #=> true
# Lotus::Utils::PathPrefix.new('posts').absolute? #=> false # Hanami::Utils::PathPrefix.new('posts').absolute? #=> false
def absolute? def absolute?
@string.start_with?(separator) @string.start_with?(separator)
end end

View File

@ -1,6 +1,6 @@
require 'lotus/utils/inflector' require 'hanami/utils/inflector'
module Lotus module Hanami
module Utils module Utils
# String on steroids # String on steroids
# #
@ -85,42 +85,42 @@ module Lotus
# Return a titleized version of the string # Return a titleized version of the string
# #
# @return [Lotus::Utils::String] the transformed string # @return [Hanami::Utils::String] the transformed string
# #
# @since 0.4.0 # @since 0.4.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'lotus utils' # string = Hanami::Utils::String.new 'hanami utils'
# string.titleize # => "Lotus Utils" # string.titleize # => "Hanami Utils"
def titleize def titleize
self.class.new underscore.split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR) self.class.new underscore.split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
end end
# Return a capitalized version of the string # Return a capitalized version of the string
# #
# @return [Lotus::Utils::String] the transformed string # @return [Hanami::Utils::String] the transformed string
# #
# @since 0.5.2 # @since 0.5.2
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'lotus' # string = Hanami::Utils::String.new 'hanami'
# string.capitalize # => "Lotus" # string.capitalize # => "Hanami"
# #
# string = Lotus::Utils::String.new 'lotus utils' # string = Hanami::Utils::String.new 'hanami utils'
# string.capitalize # => "Lotus utils" # string.capitalize # => "Hanami utils"
# #
# string = Lotus::Utils::String.new 'Lotus Utils' # string = Hanami::Utils::String.new 'Hanami Utils'
# string.capitalize # => "Lotus utils" # string.capitalize # => "Hanami utils"
# #
# string = Lotus::Utils::String.new 'lotus_utils' # string = Hanami::Utils::String.new 'hanami_utils'
# string.capitalize # => "Lotus utils" # string.capitalize # => "Hanami utils"
# #
# string = Lotus::Utils::String.new 'lotus-utils' # string = Hanami::Utils::String.new 'hanami-utils'
# string.capitalize # => "Lotus utils" # string.capitalize # => "Hanami utils"
def capitalize def capitalize
head, *tail = underscore.split(CLASSIFY_SEPARATOR) head, *tail = underscore.split(CLASSIFY_SEPARATOR)
@ -136,10 +136,10 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'lotus_utils' # string = Hanami::Utils::String.new 'hanami_utils'
# string.classify # => 'LotusUtils' # string.classify # => 'HanamiUtils'
def classify def classify
words = split(CLASSIFY_WORD_SEPARATOR).map!(&:capitalize) words = split(CLASSIFY_WORD_SEPARATOR).map!(&:capitalize)
delimiters = scan(CLASSIFY_WORD_SEPARATOR) delimiters = scan(CLASSIFY_WORD_SEPARATOR)
@ -161,10 +161,10 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'LotusUtils' # string = Hanami::Utils::String.new 'HanamiUtils'
# string.underscore # => 'lotus_utils' # string.underscore # => 'hanami_utils'
def underscore def underscore
new_string = gsub(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR) new_string = gsub(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
new_string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET) new_string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
@ -176,21 +176,21 @@ module Lotus
# Return a downcased and dash separated version of the string # Return a downcased and dash separated version of the string
# #
# @return [Lotus::Utils::String] the transformed string # @return [Hanami::Utils::String] the transformed string
# #
# @since 0.4.0 # @since 0.4.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'Lotus Utils' # string = Hanami::Utils::String.new 'Hanami Utils'
# string.dasherize # => 'lotus-utils' # string.dasherize # => 'hanami-utils'
# #
# string = Lotus::Utils::String.new 'lotus_utils' # string = Hanami::Utils::String.new 'hanami_utils'
# string.dasherize # => 'lotus-utils' # string.dasherize # => 'hanami-utils'
# #
# string = Lotus::Utils::String.new 'LotusUtils' # string = Hanami::Utils::String.new 'HanamiUtils'
# string.dasherize # => "lotus-utils" # string.dasherize # => "hanami-utils"
def dasherize def dasherize
self.class.new underscore.split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR) self.class.new underscore.split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
end end
@ -202,12 +202,12 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'Lotus::Utils::String' # string = Hanami::Utils::String.new 'Hanami::Utils::String'
# string.demodulize # => 'String' # string.demodulize # => 'String'
# #
# string = Lotus::Utils::String.new 'String' # string = Hanami::Utils::String.new 'String'
# string.demodulize # => 'String' # string.demodulize # => 'String'
def demodulize def demodulize
self.class.new split(NAMESPACE_SEPARATOR).last self.class.new split(NAMESPACE_SEPARATOR).last
@ -220,12 +220,12 @@ module Lotus
# @since 0.1.2 # @since 0.1.2
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'Lotus::Utils::String' # string = Hanami::Utils::String.new 'Hanami::Utils::String'
# string.namespace # => 'Lotus' # string.namespace # => 'Hanami'
# #
# string = Lotus::Utils::String.new 'String' # string = Hanami::Utils::String.new 'String'
# string.namespace # => 'String' # string.namespace # => 'String'
def namespace def namespace
self.class.new split(NAMESPACE_SEPARATOR).first self.class.new split(NAMESPACE_SEPARATOR).first
@ -241,16 +241,16 @@ module Lotus
# @since 0.1.0 # @since 0.1.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new 'Lotus::(Utils|App)' # string = Hanami::Utils::String.new 'Hanami::(Utils|App)'
# string.tokenize do |token| # string.tokenize do |token|
# puts token # puts token
# end # end
# #
# # => # # =>
# 'Lotus::Utils' # 'Hanami::Utils'
# 'Lotus::App' # 'Hanami::App'
def tokenize def tokenize
if match = TOKENIZE_REGEXP.match(@string) if match = TOKENIZE_REGEXP.match(@string)
pre, post = match.pre_match, match.post_match pre, post = match.pre_match, match.post_match
@ -267,24 +267,24 @@ module Lotus
# Return a pluralized version of self. # Return a pluralized version of self.
# #
# @return [Lotus::Utils::String] the pluralized string. # @return [Hanami::Utils::String] the pluralized string.
# #
# @api private # @api private
# @since 0.4.1 # @since 0.4.1
# #
# @see Lotus::Utils::Inflector # @see Hanami::Utils::Inflector
def pluralize def pluralize
self.class.new Inflector.pluralize(self) self.class.new Inflector.pluralize(self)
end end
# Return a singularized version of self. # Return a singularized version of self.
# #
# @return [Lotus::Utils::String] the singularized string. # @return [Hanami::Utils::String] the singularized string.
# #
# @api private # @api private
# @since 0.4.1 # @since 0.4.1
# #
# @see Lotus::Utils::Inflector # @see Hanami::Utils::Inflector
def singularize def singularize
self.class.new Inflector.singularize(self) self.class.new Inflector.singularize(self)
end end
@ -364,23 +364,23 @@ module Lotus
# This method does NOT mutate the original string. # This method does NOT mutate the original string.
# #
# @param pattern [Regexp, String] the pattern to find # @param pattern [Regexp, String] the pattern to find
# @param replacement [String, Lotus::Utils::String] the string to replace # @param replacement [String, Hanami::Utils::String] the string to replace
# #
# @return [Lotus::Utils::String] the replaced string # @return [Hanami::Utils::String] the replaced string
# #
# @since 0.6.0 # @since 0.6.0
# #
# @example # @example
# require 'lotus/utils/string' # require 'hanami/utils/string'
# #
# string = Lotus::Utils::String.new('authors/books/index') # string = Hanami::Utils::String.new('authors/books/index')
# result = string.rsub(/\//, '#') # result = string.rsub(/\//, '#')
# #
# puts string # puts string
# # => #<Lotus::Utils::String:0x007fdb41233ad8 @string="authors/books/index"> # # => #<Hanami::Utils::String:0x007fdb41233ad8 @string="authors/books/index">
# #
# puts result # puts result
# # => #<Lotus::Utils::String:0x007fdb41232ed0 @string="authors/books#index"> # # => #<Hanami::Utils::String:0x007fdb41232ed0 @string="authors/books#index">
def rsub(pattern, replacement) def rsub(pattern, replacement)
if i = rindex(pattern) if i = rindex(pattern)
s = @string.dup s = @string.dup

View File

@ -1,8 +1,8 @@
module Lotus module Hanami
module Utils module Utils
# Defines the version # Defines the version
# #
# @since 0.1.0 # @since 0.1.0
VERSION = '0.6.1'.freeze VERSION = '0.7.0'.freeze
end end
end end

View File

@ -1 +0,0 @@
require 'lotus/utils'

View File

@ -1,8 +1,8 @@
require 'test_helper' require 'test_helper'
require 'bigdecimal' require 'bigdecimal'
require 'lotus/utils/attributes' require 'hanami/utils/attributes'
describe Lotus::Utils::Attributes do describe Hanami::Utils::Attributes do
describe '#initialize' do describe '#initialize' do
before do before do
class AttributesSet class AttributesSet
@ -17,57 +17,57 @@ describe Lotus::Utils::Attributes do
end end
it 'accepts an object that implements #to_h' do it 'accepts an object that implements #to_h' do
attributes = Lotus::Utils::Attributes.new(AttributesSet.new) attributes = Hanami::Utils::Attributes.new(AttributesSet.new)
attributes.to_h.must_equal({'a' => 1}) attributes.to_h.must_equal({'a' => 1})
end end
it "ignores hash default" do it "ignores hash default" do
attributes = Lotus::Utils::Attributes.new{|h,k| h[k] = [] } attributes = Hanami::Utils::Attributes.new{|h,k| h[k] = [] }
attributes.get('uknown').must_be_nil attributes.get('uknown').must_be_nil
end end
it 'recursively stringify keys' do it 'recursively stringify keys' do
attributes = Lotus::Utils::Attributes.new({a: 1, b: { 2 => [3, 4] }}) attributes = Hanami::Utils::Attributes.new({a: 1, b: { 2 => [3, 4] }})
attributes.to_h.must_equal({'a'=>1, 'b'=>{'2'=>[3,4]}}) attributes.to_h.must_equal({'a'=>1, 'b'=>{'2'=>[3,4]}})
end end
end end
describe '#get' do describe '#get' do
it 'returns value associated to the given key (string)' do it 'returns value associated to the given key (string)' do
attributes = Lotus::Utils::Attributes.new('foo' => 'bar') attributes = Hanami::Utils::Attributes.new('foo' => 'bar')
attributes.get('foo').must_equal 'bar' attributes.get('foo').must_equal 'bar'
attributes.get(:foo).must_equal 'bar' attributes.get(:foo).must_equal 'bar'
end end
it 'returns value associated to the given key (symbol)' do it 'returns value associated to the given key (symbol)' do
attributes = Lotus::Utils::Attributes.new(foo: 'bar') attributes = Hanami::Utils::Attributes.new(foo: 'bar')
attributes.get(:foo).must_equal 'bar' attributes.get(:foo).must_equal 'bar'
attributes.get('foo').must_equal 'bar' attributes.get('foo').must_equal 'bar'
end end
it 'returns value associated to the given key (number)' do it 'returns value associated to the given key (number)' do
attributes = Lotus::Utils::Attributes.new( 23 => 'foo') attributes = Hanami::Utils::Attributes.new( 23 => 'foo')
attributes.get(23).must_equal 'foo' attributes.get(23).must_equal 'foo'
attributes.get('23').must_equal 'foo' attributes.get('23').must_equal 'foo'
end end
it 'correctly handles Ruby falsey' do it 'correctly handles Ruby falsey' do
attributes = Lotus::Utils::Attributes.new('foo' => false) attributes = Hanami::Utils::Attributes.new('foo' => false)
attributes.get(:foo).must_equal false attributes.get(:foo).must_equal false
attributes.get('foo').must_equal false attributes.get('foo').must_equal false
attributes = Lotus::Utils::Attributes.new(foo: false) attributes = Hanami::Utils::Attributes.new(foo: false)
attributes.get(:foo).must_equal false attributes.get(:foo).must_equal false
end end
it 'ignores hash default' do it 'ignores hash default' do
attributes = Lotus::Utils::Attributes.new{|h,k| h[k] = [] } attributes = Hanami::Utils::Attributes.new{|h,k| h[k] = [] }
attributes.get('foo').must_be_nil attributes.get('foo').must_be_nil
attributes.get(:foo).must_be_nil attributes.get(:foo).must_be_nil
end end
it 'overrides clashing keys' do it 'overrides clashing keys' do
attributes = Lotus::Utils::Attributes.new('foo' => 'bar', foo: 'baz') attributes = Hanami::Utils::Attributes.new('foo' => 'bar', foo: 'baz')
attributes.get('foo').must_equal 'baz' attributes.get('foo').must_equal 'baz'
attributes.get(:foo).must_equal 'baz' attributes.get(:foo).must_equal 'baz'
end end
@ -75,40 +75,40 @@ describe Lotus::Utils::Attributes do
describe '#[]' do describe '#[]' do
it 'returns value associated to the given key (string)' do it 'returns value associated to the given key (string)' do
attributes = Lotus::Utils::Attributes.new('foo' => 'bar') attributes = Hanami::Utils::Attributes.new('foo' => 'bar')
attributes['foo'].must_equal 'bar' attributes['foo'].must_equal 'bar'
attributes[:foo].must_equal 'bar' attributes[:foo].must_equal 'bar'
end end
it 'returns value associated to the given key (symbol)' do it 'returns value associated to the given key (symbol)' do
attributes = Lotus::Utils::Attributes.new(foo: 'bar') attributes = Hanami::Utils::Attributes.new(foo: 'bar')
attributes[:foo].must_equal 'bar' attributes[:foo].must_equal 'bar'
attributes['foo'].must_equal 'bar' attributes['foo'].must_equal 'bar'
end end
it 'returns value associated to the given key (number)' do it 'returns value associated to the given key (number)' do
attributes = Lotus::Utils::Attributes.new( 23 => 'foo') attributes = Hanami::Utils::Attributes.new( 23 => 'foo')
attributes[23].must_equal 'foo' attributes[23].must_equal 'foo'
attributes['23'].must_equal 'foo' attributes['23'].must_equal 'foo'
end end
it 'correctly handles Ruby falsey' do it 'correctly handles Ruby falsey' do
attributes = Lotus::Utils::Attributes.new('foo' => false) attributes = Hanami::Utils::Attributes.new('foo' => false)
attributes[:foo].must_equal false attributes[:foo].must_equal false
attributes['foo'].must_equal false attributes['foo'].must_equal false
attributes = Lotus::Utils::Attributes.new(foo: false) attributes = Hanami::Utils::Attributes.new(foo: false)
attributes[:foo].must_equal false attributes[:foo].must_equal false
end end
it 'ignores hash default' do it 'ignores hash default' do
attributes = Lotus::Utils::Attributes.new{|h,k| h[k] = [] } attributes = Hanami::Utils::Attributes.new{|h,k| h[k] = [] }
attributes['foo'].must_be_nil attributes['foo'].must_be_nil
attributes[:foo].must_be_nil attributes[:foo].must_be_nil
end end
it 'overrides clashing keys' do it 'overrides clashing keys' do
attributes = Lotus::Utils::Attributes.new('foo' => 'bar', foo: 'baz') attributes = Hanami::Utils::Attributes.new('foo' => 'bar', foo: 'baz')
attributes['foo'].must_equal 'baz' attributes['foo'].must_equal 'baz'
attributes[:foo].must_equal 'baz' attributes[:foo].must_equal 'baz'
end end
@ -116,11 +116,11 @@ describe Lotus::Utils::Attributes do
describe '#set' do describe '#set' do
it 'is a void operation' do it 'is a void operation' do
Lotus::Utils::Attributes.new.set('foo', 11).must_be_nil Hanami::Utils::Attributes.new.set('foo', 11).must_be_nil
end end
it 'sets a value (string)' do it 'sets a value (string)' do
attributes = Lotus::Utils::Attributes.new attributes = Hanami::Utils::Attributes.new
attributes.set('foo', 'bar') attributes.set('foo', 'bar')
attributes.get('foo').must_equal 'bar' attributes.get('foo').must_equal 'bar'
@ -128,7 +128,7 @@ describe Lotus::Utils::Attributes do
end end
it 'sets a value (symbol)' do it 'sets a value (symbol)' do
attributes = Lotus::Utils::Attributes.new attributes = Hanami::Utils::Attributes.new
attributes.set(:foo, 'bar') attributes.set(:foo, 'bar')
attributes.get('foo').must_equal 'bar' attributes.get('foo').must_equal 'bar'
@ -136,7 +136,7 @@ describe Lotus::Utils::Attributes do
end end
it 'sets a value (number)' do it 'sets a value (number)' do
attributes = Lotus::Utils::Attributes.new attributes = Hanami::Utils::Attributes.new
attributes.set(23, 'bar') attributes.set(23, 'bar')
attributes.get(23).must_equal 'bar' attributes.get(23).must_equal 'bar'
@ -147,7 +147,7 @@ describe Lotus::Utils::Attributes do
describe '#to_h' do describe '#to_h' do
before do before do
@value = Class.new do @value = Class.new do
def lotus_nested_attributes? def hanami_nested_attributes?
true true
end end
@ -157,26 +157,26 @@ describe Lotus::Utils::Attributes do
end.new end.new
end end
it 'returns an instance of ::Lotus::Utils::Hash' do it 'returns an instance of ::Hanami::Utils::Hash' do
attributes = Lotus::Utils::Attributes.new attributes = Hanami::Utils::Attributes.new
attributes.to_h.must_be_kind_of(::Hash) attributes.to_h.must_be_kind_of(::Hash)
end end
it 'returns a hash serialization' do it 'returns a hash serialization' do
attributes = Lotus::Utils::Attributes.new(foo: 'bar') attributes = Hanami::Utils::Attributes.new(foo: 'bar')
attributes.to_h.must_equal({'foo' => 'bar'}) attributes.to_h.must_equal({'foo' => 'bar'})
end end
it 'prevents information escape' do it 'prevents information escape' do
actual = Lotus::Utils::Attributes.new({'a' => 1}) actual = Hanami::Utils::Attributes.new({'a' => 1})
hash = actual.to_h hash = actual.to_h
hash.merge!('b' => 2) hash.merge!('b' => 2)
actual.get('b').must_be_nil actual.get('b').must_be_nil
end end
it 'forces ::Lotus::Utils::Hash values when a validations nested attributes is given' do it 'forces ::Hanami::Utils::Hash values when a validations nested attributes is given' do
attributes = Lotus::Utils::Attributes.new(val: @value) attributes = Hanami::Utils::Attributes.new(val: @value)
actual = attributes.to_h actual = attributes.to_h
actual.must_equal({'val' => { 'foo' => 'bar'}}) actual.must_equal({'val' => { 'foo' => 'bar'}})
@ -184,9 +184,9 @@ describe Lotus::Utils::Attributes do
end end
# Bug # Bug
# See: https://github.com/lotus/validations/issues/58#issuecomment-99144243 # See: https://github.com/hanami/validations/issues/58#issuecomment-99144243
it 'fallbacks to the original value if TypeError is raised' do it 'fallbacks to the original value if TypeError is raised' do
attributes = Lotus::Utils::Attributes.new(val: [1, 2]) attributes = Hanami::Utils::Attributes.new(val: [1, 2])
actual = attributes.to_h actual = attributes.to_h
actual.must_equal({'val' => [1, 2]}) actual.must_equal({'val' => [1, 2]})

View File

@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/callbacks' require 'hanami/utils/callbacks'
Lotus::Utils::Callbacks::Chain.class_eval do Hanami::Utils::Callbacks::Chain.class_eval do
def size def size
@chain.size @chain.size
end end
@ -41,9 +41,9 @@ class Action
end end
end end
describe Lotus::Utils::Callbacks::Chain do describe Hanami::Utils::Callbacks::Chain do
before do before do
@chain = Lotus::Utils::Callbacks::Chain.new @chain = Hanami::Utils::Callbacks::Chain.new
end end
describe '#append' do describe '#append' do
@ -263,17 +263,17 @@ describe Lotus::Utils::Callbacks::Chain do
end end
end end
describe Lotus::Utils::Callbacks::Factory do describe Hanami::Utils::Callbacks::Factory do
describe '.fabricate' do describe '.fabricate' do
before do before do
@callback = Lotus::Utils::Callbacks::Factory.fabricate(callback) @callback = Hanami::Utils::Callbacks::Factory.fabricate(callback)
end end
describe 'when a callable is passed' do describe 'when a callable is passed' do
let(:callback) { Callable.new } let(:callback) { Callable.new }
it 'fabricates a Callback' do it 'fabricates a Callback' do
@callback.must_be_kind_of(Lotus::Utils::Callbacks::Callback) @callback.must_be_kind_of(Hanami::Utils::Callbacks::Callback)
end end
it 'wraps the given callback' do it 'wraps the given callback' do
@ -285,7 +285,7 @@ describe Lotus::Utils::Callbacks::Factory do
let(:callback) { :symbolize! } let(:callback) { :symbolize! }
it 'fabricates a MethodCallback' do it 'fabricates a MethodCallback' do
@callback.must_be_kind_of(Lotus::Utils::Callbacks::MethodCallback) @callback.must_be_kind_of(Hanami::Utils::Callbacks::MethodCallback)
end end
it 'wraps the given callback' do it 'wraps the given callback' do
@ -295,9 +295,9 @@ describe Lotus::Utils::Callbacks::Factory do
end end
end end
describe Lotus::Utils::Callbacks::Callback do describe Hanami::Utils::Callbacks::Callback do
before do before do
@callback = Lotus::Utils::Callbacks::Callback.new(callback) @callback = Hanami::Utils::Callbacks::Callback.new(callback)
end end
let(:callback) { Proc.new{|params| logger.push("set_article: #{ params[:id] }") } } let(:callback) { Proc.new{|params| logger.push("set_article: #{ params[:id] }") } }
@ -311,9 +311,9 @@ describe Lotus::Utils::Callbacks::Callback do
end end
end end
describe Lotus::Utils::Callbacks::MethodCallback do describe Hanami::Utils::Callbacks::MethodCallback do
before do before do
@callback = Lotus::Utils::Callbacks::MethodCallback.new(callback) @callback = Hanami::Utils::Callbacks::MethodCallback.new(callback)
end end
let(:callback) { :set_article } let(:callback) { :set_article }
@ -327,7 +327,7 @@ describe Lotus::Utils::Callbacks::MethodCallback do
end end
it 'implements #hash' do it 'implements #hash' do
cb = Lotus::Utils::Callbacks::MethodCallback.new(callback) cb = Hanami::Utils::Callbacks::MethodCallback.new(callback)
cb.send(:hash).must_equal(@callback.send(:hash)) cb.send(:hash).must_equal(@callback.send(:hash))
end end
end end

View File

@ -1,10 +1,10 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/class_attribute' require 'hanami/utils/class_attribute'
describe Lotus::Utils::ClassAttribute do describe Hanami::Utils::ClassAttribute do
before do before do
class ClassAttributeTest class ClassAttributeTest
include Lotus::Utils::ClassAttribute include Hanami::Utils::ClassAttribute
class_attribute :callbacks, :functions, :values class_attribute :callbacks, :functions, :values
self.callbacks = [:a] self.callbacks = [:a]
self.values = [1] self.values = [1]
@ -20,7 +20,7 @@ describe Lotus::Utils::ClassAttribute do
end end
class Vehicle class Vehicle
include Lotus::Utils::ClassAttribute include Hanami::Utils::ClassAttribute
class_attribute :engines, :wheels class_attribute :engines, :wheels
self.engines = 0 self.engines = 0
@ -89,7 +89,7 @@ describe Lotus::Utils::ClassAttribute do
module Routing module Routing
class Resource class Resource
class Action class Action
include Lotus::Utils::ClassAttribute include Hanami::Utils::ClassAttribute
class_attribute :verb class_attribute :verb
end end

View File

@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/class' require 'hanami/utils/class'
describe Lotus::Utils::Class do describe Hanami::Utils::Class do
before do before do
module App module App
module Layer module Layer
@ -21,61 +21,61 @@ describe Lotus::Utils::Class do
describe '.load!' do describe '.load!' do
it 'loads the class from the given static string' do it 'loads the class from the given static string' do
Lotus::Utils::Class.load!('App::Layer::Step').must_equal(App::Layer::Step) Hanami::Utils::Class.load!('App::Layer::Step').must_equal(App::Layer::Step)
end end
it 'loads the class from the given static string and namespace' do it 'loads the class from the given static string and namespace' do
Lotus::Utils::Class.load!('Step', App::Layer).must_equal(App::Layer::Step) Hanami::Utils::Class.load!('Step', App::Layer).must_equal(App::Layer::Step)
end end
it 'loads the class from the given class name' do it 'loads the class from the given class name' do
Lotus::Utils::Class.load!(App::Layer::Step).must_equal(App::Layer::Step) Hanami::Utils::Class.load!(App::Layer::Step).must_equal(App::Layer::Step)
end end
it 'raises an error in case of missing class' do it 'raises an error in case of missing class' do
-> { Lotus::Utils::Class.load!('Missing') }.must_raise(NameError) -> { Hanami::Utils::Class.load!('Missing') }.must_raise(NameError)
end end
end end
describe '.load_from_pattern!' do describe '.load_from_pattern!' do
it 'loads the class from the given static string' do it 'loads the class from the given static string' do
Lotus::Utils::Class.load_from_pattern!('App::Layer::Step').must_equal(App::Layer::Step) Hanami::Utils::Class.load_from_pattern!('App::Layer::Step').must_equal(App::Layer::Step)
end end
it 'raises error for missing constant' do it 'raises error for missing constant' do
error = -> { Lotus::Utils::Class.load_from_pattern!('MissingConstant') }.must_raise(NameError) error = -> { Hanami::Utils::Class.load_from_pattern!('MissingConstant') }.must_raise(NameError)
error.message.must_equal "uninitialized constant MissingConstant" error.message.must_equal "uninitialized constant MissingConstant"
end end
it 'raises error for missing constant with multiple alternatives' do it 'raises error for missing constant with multiple alternatives' do
error = -> { Lotus::Utils::Class.load_from_pattern!('Missing(Constant|Class)') }.must_raise(NameError) error = -> { Hanami::Utils::Class.load_from_pattern!('Missing(Constant|Class)') }.must_raise(NameError)
error.message.must_equal "uninitialized constant Missing(Constant|Class)" error.message.must_equal "uninitialized constant Missing(Constant|Class)"
end end
it 'raises error with full constant name' do it 'raises error with full constant name' do
error = -> { Lotus::Utils::Class.load_from_pattern!('Step', App) }.must_raise(NameError) error = -> { Hanami::Utils::Class.load_from_pattern!('Step', App) }.must_raise(NameError)
error.message.must_equal "uninitialized constant App::Step" error.message.must_equal "uninitialized constant App::Step"
end end
it 'raises error with full constant name and multiple alternatives' do it 'raises error with full constant name and multiple alternatives' do
error = -> { Lotus::Utils::Class.load_from_pattern!('(Step|Point)', App) }.must_raise(NameError) error = -> { Hanami::Utils::Class.load_from_pattern!('(Step|Point)', App) }.must_raise(NameError)
error.message.must_equal "uninitialized constant App::(Step|Point)" error.message.must_equal "uninitialized constant App::(Step|Point)"
end end
it 'loads the class from given string, by interpolating tokens' do it 'loads the class from given string, by interpolating tokens' do
Lotus::Utils::Class.load_from_pattern!('App::Service(::Point|Point)').must_equal(App::Service::Point) Hanami::Utils::Class.load_from_pattern!('App::Service(::Point|Point)').must_equal(App::Service::Point)
end end
it 'loads the class from given string, by interpolating string tokens and respecting their order' do it 'loads the class from given string, by interpolating string tokens and respecting their order' do
Lotus::Utils::Class.load_from_pattern!('App::Service(Point|::Point)').must_equal(App::ServicePoint) Hanami::Utils::Class.load_from_pattern!('App::Service(Point|::Point)').must_equal(App::ServicePoint)
end end
it 'loads the class from given string, by interpolating tokens and not stopping after first fail' do it 'loads the class from given string, by interpolating tokens and not stopping after first fail' do
Lotus::Utils::Class.load_from_pattern!('App::(Layer|Layer::)Step').must_equal(App::Layer::Step) Hanami::Utils::Class.load_from_pattern!('App::(Layer|Layer::)Step').must_equal(App::Layer::Step)
end end
it 'loads class from given string and namespace' do it 'loads class from given string and namespace' do
Lotus::Utils::Class.load_from_pattern!('(Layer|Layer::)Step', App).must_equal(App::Layer::Step) Hanami::Utils::Class.load_from_pattern!('(Layer|Layer::)Step', App).must_equal(App::Layer::Step)
end end
end end
end end

View File

@ -1,9 +1,9 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/deprecation' require 'hanami/utils/deprecation'
class DeprecationTest class DeprecationTest
def old_method def old_method
Lotus::Utils::Deprecation.new('old_method is deprecated, please use new_method') Hanami::Utils::Deprecation.new('old_method is deprecated, please use new_method')
new_method new_method
end end
@ -21,16 +21,16 @@ class DeprecationWrapperTest
end end
end end
describe Lotus::Utils::Deprecation do describe Hanami::Utils::Deprecation do
it 'prints a deprecation warning for direct call' do it 'prints a deprecation warning for direct call' do
_, err = capture_io do _, err = capture_io do
DeprecationTest.new.old_method DeprecationTest.new.old_method
end end
stack = if Lotus::Utils.jruby? stack = if Hanami::Utils.jruby?
$0 == __FILE__ ? "#{ __FILE__ }:27:in `(root)'" : $0 == __FILE__ ? "#{ __FILE__ }:27:in `(root)'" :
"#{ __FILE__ }:27:in `block in test_0001_prints a deprecation warning for direct call'" "#{ __FILE__ }:27:in `block in test_0001_prints a deprecation warning for direct call'"
elsif Lotus::Utils.rubinius? elsif Hanami::Utils.rubinius?
$0 == __FILE__ ? "#{ ::File.expand_path(__FILE__) }:27:in `__script__'" : $0 == __FILE__ ? "#{ ::File.expand_path(__FILE__) }:27:in `__script__'" :
"#{ __FILE__ }:27:in `__script__'" "#{ __FILE__ }:27:in `__script__'"
else else

View File

@ -1,9 +1,9 @@
require 'test_helper' require 'test_helper'
require 'set' require 'set'
require 'bigdecimal' require 'bigdecimal'
require 'lotus/utils/duplicable' require 'hanami/utils/duplicable'
describe Lotus::Utils::Duplicable do describe Hanami::Utils::Duplicable do
describe "#dup" do describe "#dup" do
describe "non duplicable types" do describe "non duplicable types" do
before do before do
@ -28,7 +28,7 @@ describe Lotus::Utils::Duplicable do
end end
it "doesn't dup symbol" do it "doesn't dup symbol" do
assert_same_duped_object :lotus assert_same_duped_object :hanami
end end
it "doesn't dup integer" do it "doesn't dup integer" do
@ -62,7 +62,7 @@ describe Lotus::Utils::Duplicable do
end end
it "duplicates string" do it "duplicates string" do
assert_different_duped_object "Lotus" assert_different_duped_object "Hanami"
end end
it "duplicates date" do it "duplicates date" do
@ -84,7 +84,7 @@ describe Lotus::Utils::Duplicable do
actual = nil actual = nil
_, stderr = capture_io do _, stderr = capture_io do
actual = Lotus::Utils::Duplicable.dup(object) actual = Hanami::Utils::Duplicable.dup(object)
end end
stderr.must_be_empty stderr.must_be_empty
@ -94,7 +94,7 @@ describe Lotus::Utils::Duplicable do
end end
def assert_different_duped_object(object) def assert_different_duped_object(object)
actual = Lotus::Utils::Duplicable.dup(object) actual = Hanami::Utils::Duplicable.dup(object)
actual.must_equal object actual.must_equal object
actual.object_id.wont_equal object.object_id actual.object_id.wont_equal object.object_id

View File

@ -1,15 +1,15 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils' require 'hanami/utils'
require 'lotus/utils/escape' require 'hanami/utils/escape'
describe Lotus::Utils::Escape do describe Hanami::Utils::Escape do
let(:mod) { Lotus::Utils::Escape } let(:mod) { Hanami::Utils::Escape }
describe '.html' do describe '.html' do
TEST_ENCODINGS.each do |encoding| TEST_ENCODINGS.each do |encoding|
describe "#{ encoding }" do describe "#{ encoding }" do
it "doesn't escape safe string" do it "doesn't escape safe string" do
input = Lotus::Utils::Escape::SafeString.new('&') input = Hanami::Utils::Escape::SafeString.new('&')
result = mod.html(input.encode(encoding)) result = mod.html(input.encode(encoding))
result.must_equal '&' result.must_equal '&'
end end
@ -120,7 +120,7 @@ describe Lotus::Utils::Escape do
TEST_ENCODINGS.each do |encoding| TEST_ENCODINGS.each do |encoding|
describe "#{ encoding }" do describe "#{ encoding }" do
it "doesn't escape safe string" do it "doesn't escape safe string" do
input = Lotus::Utils::Escape::SafeString.new('&') input = Hanami::Utils::Escape::SafeString.new('&')
result = mod.html_attribute(input.encode(encoding)) result = mod.html_attribute(input.encode(encoding))
result.must_equal '&' result.must_equal '&'
end end
@ -260,7 +260,7 @@ describe Lotus::Utils::Escape do
end end
TEST_HTML_ENTITIES.each do |char, entity| TEST_HTML_ENTITIES.each do |char, entity|
test_name = Lotus::Utils.jruby? ? char.ord : char test_name = Hanami::Utils.jruby? ? char.ord : char
it "escapes #{ test_name }" do it "escapes #{ test_name }" do
result = mod.html_attribute(char) result = mod.html_attribute(char)
@ -273,7 +273,7 @@ describe Lotus::Utils::Escape do
TEST_ENCODINGS.each do |encoding| TEST_ENCODINGS.each do |encoding|
describe "#{ encoding }" do describe "#{ encoding }" do
it "doesn't escape safe string" do it "doesn't escape safe string" do
input = Lotus::Utils::Escape::SafeString.new('javascript:alert(0);') input = Hanami::Utils::Escape::SafeString.new('javascript:alert(0);')
result = mod.url(input.encode(encoding)) result = mod.url(input.encode(encoding))
result.must_equal 'javascript:alert(0);' result.must_equal 'javascript:alert(0);'
end end
@ -288,24 +288,24 @@ describe Lotus::Utils::Escape do
result.must_equal '' result.must_equal ''
end end
it "escapes 'http://lotusrb.org'" do it "escapes 'http://hanamirb.org'" do
result = mod.url('http://lotusrb.org'.encode(encoding)) result = mod.url('http://hanamirb.org'.encode(encoding))
result.must_equal 'http://lotusrb.org' result.must_equal 'http://hanamirb.org'
end end
it "escapes 'https://lotusrb.org'" do it "escapes 'https://hanamirb.org'" do
result = mod.url('https://lotusrb.org'.encode(encoding)) result = mod.url('https://hanamirb.org'.encode(encoding))
result.must_equal 'https://lotusrb.org' result.must_equal 'https://hanamirb.org'
end end
it "escapes 'https://lotusrb.org#introduction'" do it "escapes 'https://hanamirb.org#introduction'" do
result = mod.url('https://lotusrb.org#introduction'.encode(encoding)) result = mod.url('https://hanamirb.org#introduction'.encode(encoding))
result.must_equal 'https://lotusrb.org#introduction' result.must_equal 'https://hanamirb.org#introduction'
end end
it "escapes 'https://lotusrb.org/guides/index.html'" do it "escapes 'https://hanamirb.org/guides/index.html'" do
result = mod.url('https://lotusrb.org/guides/index.html'.encode(encoding)) result = mod.url('https://hanamirb.org/guides/index.html'.encode(encoding))
result.must_equal 'https://lotusrb.org/guides/index.html' result.must_equal 'https://hanamirb.org/guides/index.html'
end end
it "escapes 'mailto:user@example.com'" do it "escapes 'mailto:user@example.com'" do

View File

@ -597,8 +597,8 @@ TEST_SINGULARS = {
"kiss" => "kisses", "kiss" => "kisses",
}.merge(TEST_PLURALS) }.merge(TEST_PLURALS)
require 'lotus/utils/inflector' require 'hanami/utils/inflector'
Lotus::Utils::Inflector.inflections do Hanami::Utils::Inflector.inflections do
exception 'analysis', 'analyses' exception 'analysis', 'analyses'
exception 'alga', 'algae' exception 'alga', 'algae'
uncountable 'music', 'butter' uncountable 'music', 'butter'

View File

@ -1,24 +1,24 @@
require 'test_helper' require 'test_helper'
require 'bigdecimal' require 'bigdecimal'
require 'lotus/utils/hash' require 'hanami/utils/hash'
describe Lotus::Utils::Hash do describe Hanami::Utils::Hash do
describe '#initialize' do describe '#initialize' do
it 'holds values passed to the constructor' do it 'holds values passed to the constructor' do
hash = Lotus::Utils::Hash.new('foo' => 'bar') hash = Hanami::Utils::Hash.new('foo' => 'bar')
hash['foo'].must_equal('bar') hash['foo'].must_equal('bar')
end end
it 'assigns default via block' do it 'assigns default via block' do
hash = Lotus::Utils::Hash.new {|h,k| h[k] = []} hash = Hanami::Utils::Hash.new {|h,k| h[k] = []}
hash['foo'].push 'bar' hash['foo'].push 'bar'
hash.must_equal({'foo' => ['bar']}) hash.must_equal({'foo' => ['bar']})
end end
it 'accepts a Lotus::Utils::Hash' do it 'accepts a Hanami::Utils::Hash' do
arg = Lotus::Utils::Hash.new('foo' => 'bar') arg = Hanami::Utils::Hash.new('foo' => 'bar')
hash = Lotus::Utils::Hash.new(arg) hash = Hanami::Utils::Hash.new(arg)
hash.to_h.must_be_kind_of(::Hash) hash.to_h.must_be_kind_of(::Hash)
end end
@ -26,7 +26,7 @@ describe Lotus::Utils::Hash do
describe '#symbolize!' do describe '#symbolize!' do
it 'symbolize keys' do it 'symbolize keys' do
hash = Lotus::Utils::Hash.new('fub' => 'baz') hash = Hanami::Utils::Hash.new('fub' => 'baz')
hash.symbolize! hash.symbolize!
hash['fub'].must_be_nil hash['fub'].must_be_nil
@ -34,17 +34,17 @@ describe Lotus::Utils::Hash do
end end
it 'symbolize nested hashes' do it 'symbolize nested hashes' do
hash = Lotus::Utils::Hash.new('nested' => {'key' => 'value'}) hash = Hanami::Utils::Hash.new('nested' => {'key' => 'value'})
hash.symbolize! hash.symbolize!
hash[:nested].must_be_kind_of Lotus::Utils::Hash hash[:nested].must_be_kind_of Hanami::Utils::Hash
hash[:nested][:key].must_equal('value') hash[:nested][:key].must_equal('value')
end end
end end
describe '#stringify!' do describe '#stringify!' do
it 'covert keys to strings' do it 'covert keys to strings' do
hash = Lotus::Utils::Hash.new(fub: 'baz') hash = Hanami::Utils::Hash.new(fub: 'baz')
hash.stringify! hash.stringify!
hash[:fub].must_be_nil hash[:fub].must_be_nil
@ -52,22 +52,22 @@ describe Lotus::Utils::Hash do
end end
it 'stringifies nested hashes' do it 'stringifies nested hashes' do
hash = Lotus::Utils::Hash.new(nested: {key: 'value'}) hash = Hanami::Utils::Hash.new(nested: {key: 'value'})
hash.stringify! hash.stringify!
hash['nested'].must_be_kind_of Lotus::Utils::Hash hash['nested'].must_be_kind_of Hanami::Utils::Hash
hash['nested']['key'].must_equal('value') hash['nested']['key'].must_equal('value')
end end
end end
describe '#deep_dup' do describe '#deep_dup' do
it 'returns an instance of Utils::Hash' do it 'returns an instance of Utils::Hash' do
duped = Lotus::Utils::Hash.new('foo' => 'bar').deep_dup duped = Hanami::Utils::Hash.new('foo' => 'bar').deep_dup
duped.must_be_kind_of(Lotus::Utils::Hash) duped.must_be_kind_of(Hanami::Utils::Hash)
end end
it 'returns a hash with duplicated values' do it 'returns a hash with duplicated values' do
hash = Lotus::Utils::Hash.new('foo' => 'bar', 'baz' => 'x') hash = Hanami::Utils::Hash.new('foo' => 'bar', 'baz' => 'x')
duped = hash.deep_dup duped = hash.deep_dup
duped['foo'] = nil duped['foo'] = nil
@ -91,7 +91,7 @@ describe Lotus::Utils::Hash do
'rational' => Rational(0.3) 'rational' => Rational(0.3)
} }
hash = Lotus::Utils::Hash.new(original) hash = Hanami::Utils::Hash.new(original)
duped = hash.deep_dup duped = hash.deep_dup
duped.must_equal(original) duped.must_equal(original)
@ -99,7 +99,7 @@ describe Lotus::Utils::Hash do
end end
it 'returns a hash with nested duplicated values' do it 'returns a hash with nested duplicated values' do
hash = Lotus::Utils::Hash.new('foo' => {'bar' => 'baz'}, 'x' => Lotus::Utils::Hash.new('y' => 'z')) hash = Hanami::Utils::Hash.new('foo' => {'bar' => 'baz'}, 'x' => Hanami::Utils::Hash.new('y' => 'z'))
duped = hash.deep_dup duped = hash.deep_dup
duped['foo']['bar'].reverse! duped['foo']['bar'].reverse!
@ -110,38 +110,38 @@ describe Lotus::Utils::Hash do
end end
it 'preserves original class' do it 'preserves original class' do
duped = Lotus::Utils::Hash.new('foo' => {}, 'x' => Lotus::Utils::Hash.new).deep_dup duped = Hanami::Utils::Hash.new('foo' => {}, 'x' => Hanami::Utils::Hash.new).deep_dup
duped['foo'].must_be_kind_of(::Hash) duped['foo'].must_be_kind_of(::Hash)
duped['x'].must_be_kind_of(Lotus::Utils::Hash) duped['x'].must_be_kind_of(Hanami::Utils::Hash)
end end
end end
describe 'hash interface' do describe 'hash interface' do
it 'returns a new Lotus::Utils::Hash for methods which return a ::Hash' do it 'returns a new Hanami::Utils::Hash for methods which return a ::Hash' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
result = hash.clear result = hash.clear
assert hash.empty? assert hash.empty?
result.must_be_kind_of(Lotus::Utils::Hash) result.must_be_kind_of(Hanami::Utils::Hash)
end end
it 'returns a value that is compliant with ::Hash return value' do it 'returns a value that is compliant with ::Hash return value' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
result = hash.assoc('a') result = hash.assoc('a')
result.must_equal ['a', 1] result.must_equal ['a', 1]
end end
it 'responds to whatever ::Hash responds to' do it 'responds to whatever ::Hash responds to' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
hash.must_respond_to :rehash hash.must_respond_to :rehash
hash.wont_respond_to :unknown_method hash.wont_respond_to :unknown_method
end end
it 'accepts blocks for methods' do it 'accepts blocks for methods' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
result = hash.delete_if {|k, _| k == 'a' } result = hash.delete_if {|k, _| k == 'a' }
assert result.empty? assert result.empty?
@ -149,7 +149,7 @@ describe Lotus::Utils::Hash do
describe '#to_h' do describe '#to_h' do
it 'returns a ::Hash' do it 'returns a ::Hash' do
actual = Lotus::Utils::Hash.new({'a' => 1}).to_h actual = Hanami::Utils::Hash.new({'a' => 1}).to_h
actual.must_equal({'a' => 1}) actual.must_equal({'a' => 1})
end end
@ -163,7 +163,7 @@ describe Lotus::Utils::Hash do
} }
} }
utils_hash = Lotus::Utils::Hash.new(hash) utils_hash = Hanami::Utils::Hash.new(hash)
utils_hash.wont_be_kind_of(::Hash) utils_hash.wont_be_kind_of(::Hash)
actual = utils_hash.to_h actual = utils_hash.to_h
@ -185,7 +185,7 @@ describe Lotus::Utils::Hash do
} }
} }
utils_hash = Lotus::Utils::Hash.new(hash).symbolize! utils_hash = Hanami::Utils::Hash.new(hash).symbolize!
utils_hash.wont_be_kind_of(::Hash) utils_hash.wont_be_kind_of(::Hash)
actual = utils_hash.to_h actual = utils_hash.to_h
@ -198,7 +198,7 @@ describe Lotus::Utils::Hash do
end end
it 'prevents information escape' do it 'prevents information escape' do
actual = Lotus::Utils::Hash.new({'a' => 1}) actual = Hanami::Utils::Hash.new({'a' => 1})
hash = actual.to_h hash = actual.to_h
hash.merge!('b' => 2) hash.merge!('b' => 2)
@ -207,7 +207,7 @@ describe Lotus::Utils::Hash do
it 'prevents information escape for nested hash' it 'prevents information escape for nested hash'
# it 'prevents information escape for nested hash' do # it 'prevents information escape for nested hash' do
# actual = Lotus::Utils::Hash.new({'a' => {'b' => 2}}) # actual = Hanami::Utils::Hash.new({'a' => {'b' => 2}})
# hash = actual.to_h # hash = actual.to_h
# subhash = hash['a'] # subhash = hash['a']
# subhash.merge!('c' => 3) # subhash.merge!('c' => 3)
@ -218,7 +218,7 @@ describe Lotus::Utils::Hash do
describe '#to_hash' do describe '#to_hash' do
it 'returns a ::Hash' do it 'returns a ::Hash' do
actual = Lotus::Utils::Hash.new({'a' => 1}).to_hash actual = Hanami::Utils::Hash.new({'a' => 1}).to_hash
actual.must_equal({'a' => 1}) actual.must_equal({'a' => 1})
end end
@ -232,7 +232,7 @@ describe Lotus::Utils::Hash do
} }
} }
utils_hash = Lotus::Utils::Hash.new(hash) utils_hash = Hanami::Utils::Hash.new(hash)
utils_hash.wont_be_kind_of(::Hash) utils_hash.wont_be_kind_of(::Hash)
actual = utils_hash.to_h actual = utils_hash.to_h
@ -254,7 +254,7 @@ describe Lotus::Utils::Hash do
} }
} }
utils_hash = Lotus::Utils::Hash.new(hash).symbolize! utils_hash = Hanami::Utils::Hash.new(hash).symbolize!
utils_hash.wont_be_kind_of(::Hash) utils_hash.wont_be_kind_of(::Hash)
actual = utils_hash.to_h actual = utils_hash.to_h
@ -267,7 +267,7 @@ describe Lotus::Utils::Hash do
end end
it 'prevents information escape' do it 'prevents information escape' do
actual = Lotus::Utils::Hash.new({'a' => 1}) actual = Hanami::Utils::Hash.new({'a' => 1})
hash = actual.to_hash hash = actual.to_hash
hash.merge!('b' => 2) hash.merge!('b' => 2)
@ -277,12 +277,12 @@ describe Lotus::Utils::Hash do
describe '#to_a' do describe '#to_a' do
it 'returns an ::Array' do it 'returns an ::Array' do
actual = Lotus::Utils::Hash.new({'a' => 1}).to_a actual = Hanami::Utils::Hash.new({'a' => 1}).to_a
actual.must_equal([['a', 1]]) actual.must_equal([['a', 1]])
end end
it 'prevents information escape' do it 'prevents information escape' do
actual = Lotus::Utils::Hash.new({'a' => 1}) actual = Hanami::Utils::Hash.new({'a' => 1})
array = actual.to_a array = actual.to_a
array.push(['b', 2]) array.push(['b', 2])
@ -292,54 +292,54 @@ describe Lotus::Utils::Hash do
describe 'equality' do describe 'equality' do
it 'has a working equality' do it 'has a working equality' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
other = Lotus::Utils::Hash.new({'a' => 1}) other = Hanami::Utils::Hash.new({'a' => 1})
assert hash == other assert hash == other
end end
it 'has a working equality with raw hashes' do it 'has a working equality with raw hashes' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
assert hash == {'a' => 1} assert hash == {'a' => 1}
end end
end end
describe 'case equality' do describe 'case equality' do
it 'has a working case equality' do it 'has a working case equality' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
other = Lotus::Utils::Hash.new({'a' => 1}) other = Hanami::Utils::Hash.new({'a' => 1})
assert hash === other assert hash === other
end end
it 'has a working case equality with raw hashes' do it 'has a working case equality with raw hashes' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
assert hash === {'a' => 1} assert hash === {'a' => 1}
end end
end end
describe 'value equality' do describe 'value equality' do
it 'has a working value equality' do it 'has a working value equality' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
other = Lotus::Utils::Hash.new({'a' => 1}) other = Hanami::Utils::Hash.new({'a' => 1})
assert hash.eql?(other) assert hash.eql?(other)
end end
it 'has a working value equality with raw hashes' do it 'has a working value equality with raw hashes' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
assert hash.eql?({'a' => 1}) assert hash.eql?({'a' => 1})
end end
end end
describe 'identity equality' do describe 'identity equality' do
it 'has a working identity equality' do it 'has a working identity equality' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
assert hash.equal?(hash) assert hash.equal?(hash)
end end
it 'has a working identity equality with raw hashes' do it 'has a working identity equality with raw hashes' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
assert !hash.equal?({'a' => 1}) assert !hash.equal?({'a' => 1})
end end
end end
@ -347,7 +347,7 @@ describe Lotus::Utils::Hash do
describe '#hash' do describe '#hash' do
it 'returns the same hash result of ::Hash' do it 'returns the same hash result of ::Hash' do
expected = {'l' => 23}.hash expected = {'l' => 23}.hash
actual = Lotus::Utils::Hash.new({'l' => 23}).hash actual = Hanami::Utils::Hash.new({'l' => 23}).hash
actual.must_equal expected actual.must_equal expected
end end
@ -356,7 +356,7 @@ describe Lotus::Utils::Hash do
describe '#inspect' do describe '#inspect' do
it 'returns the same output of ::Hash' do it 'returns the same output of ::Hash' do
expected = {'l' => 23, l: 23}.inspect expected = {'l' => 23, l: 23}.inspect
actual = Lotus::Utils::Hash.new({'l' => 23, l: 23}).inspect actual = Hanami::Utils::Hash.new({'l' => 23, l: 23}).inspect
actual.must_equal expected actual.must_equal expected
end end
@ -365,16 +365,16 @@ describe Lotus::Utils::Hash do
describe 'unknown method' do describe 'unknown method' do
it 'raises error' do it 'raises error' do
begin begin
Lotus::Utils::Hash.new('l' => 23).party! Hanami::Utils::Hash.new('l' => 23).party!
rescue NoMethodError => e rescue NoMethodError => e
e.message.must_equal %(undefined method `party!' for {\"l\"=>23}:Lotus::Utils::Hash) e.message.must_equal %(undefined method `party!' for {\"l\"=>23}:Hanami::Utils::Hash)
end end
end end
# See: https://github.com/lotus/utils/issues/48 # See: https://github.com/hanami/utils/issues/48
it 'returns the correct object when a NoMethodError is raised' do it 'returns the correct object when a NoMethodError is raised' do
hash = Lotus::Utils::Hash.new({'a' => 1}) hash = Hanami::Utils::Hash.new({'a' => 1})
exception_message = if Lotus::Utils.rubinius? exception_message = if Hanami::Utils.rubinius?
"undefined method `foo' on 1:Fixnum." "undefined method `foo' on 1:Fixnum."
else else
"undefined method `foo' for 1:Fixnum" "undefined method `foo' for 1:Fixnum"

View File

@ -1,64 +1,64 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/inflector' require 'hanami/utils/inflector'
require 'lotus/utils/string' require 'hanami/utils/string'
describe Lotus::Utils::Inflector do describe Hanami::Utils::Inflector do
describe '.inflections' do describe '.inflections' do
it 'adds exception for singular rule' do it 'adds exception for singular rule' do
actual = Lotus::Utils::Inflector.singularize('analyses') # see test/fixtures.rb actual = Hanami::Utils::Inflector.singularize('analyses') # see test/fixtures.rb
actual.must_equal 'analysis' actual.must_equal 'analysis'
actual = Lotus::Utils::Inflector.singularize('algae') # see test/fixtures.rb actual = Hanami::Utils::Inflector.singularize('algae') # see test/fixtures.rb
actual.must_equal 'alga' actual.must_equal 'alga'
end end
it 'adds exception for plural rule' do it 'adds exception for plural rule' do
actual = Lotus::Utils::Inflector.pluralize('analysis') # see test/fixtures.rb actual = Hanami::Utils::Inflector.pluralize('analysis') # see test/fixtures.rb
actual.must_equal 'analyses' actual.must_equal 'analyses'
actual = Lotus::Utils::Inflector.pluralize('alga') # see test/fixtures.rb actual = Hanami::Utils::Inflector.pluralize('alga') # see test/fixtures.rb
actual.must_equal 'algae' actual.must_equal 'algae'
end end
it 'adds exception for uncountable rule' do it 'adds exception for uncountable rule' do
actual = Lotus::Utils::Inflector.pluralize('music') # see test/fixtures.rb actual = Hanami::Utils::Inflector.pluralize('music') # see test/fixtures.rb
actual.must_equal 'music' actual.must_equal 'music'
actual = Lotus::Utils::Inflector.singularize('music') # see test/fixtures.rb actual = Hanami::Utils::Inflector.singularize('music') # see test/fixtures.rb
actual.must_equal 'music' actual.must_equal 'music'
actual = Lotus::Utils::Inflector.pluralize('butter') # see test/fixtures.rb actual = Hanami::Utils::Inflector.pluralize('butter') # see test/fixtures.rb
actual.must_equal 'butter' actual.must_equal 'butter'
actual = Lotus::Utils::Inflector.singularize('butter') # see test/fixtures.rb actual = Hanami::Utils::Inflector.singularize('butter') # see test/fixtures.rb
actual.must_equal 'butter' actual.must_equal 'butter'
end end
end end
describe '.pluralize' do describe '.pluralize' do
it "returns nil when nil is given" do it "returns nil when nil is given" do
actual = Lotus::Utils::Inflector.pluralize(nil) actual = Hanami::Utils::Inflector.pluralize(nil)
actual.must_be_nil actual.must_be_nil
end end
it "returns empty string when empty string is given" do it "returns empty string when empty string is given" do
actual = Lotus::Utils::Inflector.pluralize("") actual = Hanami::Utils::Inflector.pluralize("")
actual.must_be_empty actual.must_be_empty
end end
it "returns empty string when empty string is given (multiple chars)" do it "returns empty string when empty string is given (multiple chars)" do
actual = Lotus::Utils::Inflector.pluralize(string = " ") actual = Hanami::Utils::Inflector.pluralize(string = " ")
actual.must_equal string actual.must_equal string
end end
it "returns instance of String" do it "returns instance of String" do
result = Lotus::Utils::Inflector.pluralize("Lotus") result = Hanami::Utils::Inflector.pluralize("Hanami")
result.class.must_equal ::String result.class.must_equal ::String
end end
it "doesn't modify original string" do it "doesn't modify original string" do
string = "application" string = "application"
result = Lotus::Utils::Inflector.pluralize(string) result = Hanami::Utils::Inflector.pluralize(string)
result.object_id.wont_equal(string.object_id) result.object_id.wont_equal(string.object_id)
string.must_equal("application") string.must_equal("application")
@ -66,51 +66,51 @@ describe Lotus::Utils::Inflector do
TEST_PLURALS.each do |singular, plural| TEST_PLURALS.each do |singular, plural|
it %(pluralizes "#{ singular }" to "#{ plural }") do it %(pluralizes "#{ singular }" to "#{ plural }") do
actual = Lotus::Utils::Inflector.pluralize(singular) actual = Hanami::Utils::Inflector.pluralize(singular)
actual.must_equal plural actual.must_equal plural
end end
it %(pluralizes titleized "#{ Lotus::Utils::String.new(singular).titleize }" to "#{ plural }") do it %(pluralizes titleized "#{ Hanami::Utils::String.new(singular).titleize }" to "#{ plural }") do
actual = Lotus::Utils::Inflector.pluralize(Lotus::Utils::String.new(singular).titleize) actual = Hanami::Utils::Inflector.pluralize(Hanami::Utils::String.new(singular).titleize)
actual.must_equal Lotus::Utils::String.new(plural).titleize actual.must_equal Hanami::Utils::String.new(plural).titleize
end end
# it %(doesn't pluralize "#{ plural }" as it's already plural) do # it %(doesn't pluralize "#{ plural }" as it's already plural) do
# actual = Lotus::Utils::Inflector.pluralize(plural) # actual = Hanami::Utils::Inflector.pluralize(plural)
# actual.must_equal plural # actual.must_equal plural
# end # end
# it %(doesn't pluralize titleized "#{ Lotus::Utils::String.new(singular).titleize }" as it's already plural) do # it %(doesn't pluralize titleized "#{ Hanami::Utils::String.new(singular).titleize }" as it's already plural) do
# actual = Lotus::Utils::Inflector.pluralize(Lotus::Utils::String.new(plural).titleize) # actual = Hanami::Utils::Inflector.pluralize(Hanami::Utils::String.new(plural).titleize)
# actual.must_equal Lotus::Utils::String.new(plural).titleize # actual.must_equal Hanami::Utils::String.new(plural).titleize
# end # end
end end
end end
describe '.singularize' do describe '.singularize' do
it "returns nil when nil is given" do it "returns nil when nil is given" do
actual = Lotus::Utils::Inflector.singularize(nil) actual = Hanami::Utils::Inflector.singularize(nil)
actual.must_be_nil actual.must_be_nil
end end
it "returns empty string when empty string is given" do it "returns empty string when empty string is given" do
actual = Lotus::Utils::Inflector.singularize("") actual = Hanami::Utils::Inflector.singularize("")
actual.must_be_empty actual.must_be_empty
end end
it "returns empty string when empty string is given (multiple chars)" do it "returns empty string when empty string is given (multiple chars)" do
actual = Lotus::Utils::Inflector.singularize(string = " ") actual = Hanami::Utils::Inflector.singularize(string = " ")
actual.must_equal string actual.must_equal string
end end
it "returns instance of String" do it "returns instance of String" do
result = Lotus::Utils::Inflector.singularize("application") result = Hanami::Utils::Inflector.singularize("application")
result.class.must_equal ::String result.class.must_equal ::String
end end
it "doesn't modify original string" do it "doesn't modify original string" do
string = "applications" string = "applications"
result = Lotus::Utils::Inflector.singularize(string) result = Hanami::Utils::Inflector.singularize(string)
result.object_id.wont_equal(string.object_id) result.object_id.wont_equal(string.object_id)
string.must_equal("applications") string.must_equal("applications")
@ -118,23 +118,23 @@ describe Lotus::Utils::Inflector do
TEST_SINGULARS.each do |singular, plural| TEST_SINGULARS.each do |singular, plural|
it %(singularizes "#{ plural }" to "#{ singular }") do it %(singularizes "#{ plural }" to "#{ singular }") do
actual = Lotus::Utils::Inflector.singularize(plural) actual = Hanami::Utils::Inflector.singularize(plural)
actual.must_equal singular actual.must_equal singular
end end
it %(singularizes titleized "#{ Lotus::Utils::String.new(plural).titleize }" to "#{ singular }") do it %(singularizes titleized "#{ Hanami::Utils::String.new(plural).titleize }" to "#{ singular }") do
actual = Lotus::Utils::Inflector.singularize(Lotus::Utils::String.new(plural).titleize) actual = Hanami::Utils::Inflector.singularize(Hanami::Utils::String.new(plural).titleize)
actual.must_equal Lotus::Utils::String.new(singular).titleize actual.must_equal Hanami::Utils::String.new(singular).titleize
end end
# it %(doesn't singularizes "#{ singular }" as it's already singular) do # it %(doesn't singularizes "#{ singular }" as it's already singular) do
# actual = Lotus::Utils::Inflector.singularize(singular) # actual = Hanami::Utils::Inflector.singularize(singular)
# actual.must_equal singular # actual.must_equal singular
# end # end
# it %(doesn't singularizes titleized "#{ Lotus::Utils::String.new(plural).titleize }" as it's already singular) do # it %(doesn't singularizes titleized "#{ Hanami::Utils::String.new(plural).titleize }" as it's already singular) do
# actual = Lotus::Utils::Inflector.singularize(Lotus::Utils::String.new(singular).titleize) # actual = Hanami::Utils::Inflector.singularize(Hanami::Utils::String.new(singular).titleize)
# actual.must_equal Lotus::Utils::String.new(singular).titleize # actual.must_equal Hanami::Utils::String.new(singular).titleize
# end # end
end end
end end

View File

@ -1,15 +1,15 @@
require 'test_helper' require 'test_helper'
require 'lotus/interactor' require 'hanami/interactor'
class InteractorWithoutInitialize class InteractorWithoutInitialize
include Lotus::Interactor include Hanami::Interactor
def call def call
end end
end end
class InteractorWithoutCall class InteractorWithoutCall
include Lotus::Interactor include Hanami::Interactor
end end
class User class User
@ -31,7 +31,7 @@ class User
end end
class Signup class Signup
include Lotus::Interactor include Hanami::Interactor
expose :user, :params expose :user, :params
def initialize(params) def initialize(params)
@ -53,7 +53,7 @@ class Signup
end end
class ErrorInteractor class ErrorInteractor
include Lotus::Interactor include Hanami::Interactor
expose :operations expose :operations
def initialize def initialize
@ -83,7 +83,7 @@ class ErrorInteractor
end end
class ErrorBangInteractor class ErrorBangInteractor
include Lotus::Interactor include Hanami::Interactor
expose :operations expose :operations
def initialize def initialize
@ -108,7 +108,7 @@ class ErrorBangInteractor
end end
class PublishVideo class PublishVideo
include Lotus::Interactor include Hanami::Interactor
def call def call
end end
@ -126,7 +126,7 @@ class PublishVideo
end end
class CreateUser class CreateUser
include Lotus::Interactor include Hanami::Interactor
expose :user expose :user
def initialize(params) def initialize(params)
@ -151,7 +151,7 @@ class UpdateUser < CreateUser
end end
end end
describe Lotus::Interactor do describe Hanami::Interactor do
describe '#initialize' do describe '#initialize' do
it "works when it isn't overridden" do it "works when it isn't overridden" do
InteractorWithoutInitialize.new InteractorWithoutInitialize.new
@ -165,7 +165,7 @@ describe Lotus::Interactor do
describe '#call' do describe '#call' do
it "returns a result" do it "returns a result" do
result = Signup.new(name: 'Luca').call result = Signup.new(name: 'Luca').call
assert result.class == Lotus::Interactor::Result, "Expected `result' to be kind of `Lotus::Interactor::Result'" assert result.class == Hanami::Interactor::Result, "Expected `result' to be kind of `Hanami::Interactor::Result'"
end end
it "is successful by default" do it "is successful by default" do
@ -237,7 +237,7 @@ describe Lotus::Interactor do
result.operations.must_equal [:prepare!, :persist!, :log!] result.operations.must_equal [:prepare!, :persist!, :log!]
end end
# See https://github.com/lotus/utils/issues/69 # See https://github.com/hanami/utils/issues/69
it 'returns false as control flow for caller' do it 'returns false as control flow for caller' do
interactor = PublishVideo.new interactor = PublishVideo.new
assert !interactor.valid?, "Expected interactor to not be valid" assert !interactor.valid?, "Expected interactor to not be valid"
@ -264,27 +264,27 @@ describe Lotus::Interactor do
end end
end end
describe Lotus::Interactor::Result do describe Hanami::Interactor::Result do
describe '#initialize' do describe '#initialize' do
it 'allows to skip payload' do it 'allows to skip payload' do
Lotus::Interactor::Result.new Hanami::Interactor::Result.new
end end
it 'accepts a payload' do it 'accepts a payload' do
result = Lotus::Interactor::Result.new(foo: 'bar') result = Hanami::Interactor::Result.new(foo: 'bar')
result.foo.must_equal 'bar' result.foo.must_equal 'bar'
end end
end end
describe '#success?' do describe '#success?' do
it 'is successful by default' do it 'is successful by default' do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
assert result.success?, "Expected `result' to be successful" assert result.success?, "Expected `result' to be successful"
end end
describe "when it has errors" do describe "when it has errors" do
it "isn't successful" do it "isn't successful" do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.add_error "There was a problem" result.add_error "There was a problem"
assert !result.success?, "Expected `result' to NOT be successful" assert !result.success?, "Expected `result' to NOT be successful"
end end
@ -293,7 +293,7 @@ describe Lotus::Interactor::Result do
describe '#fail!' do describe '#fail!' do
it 'causes a failure' do it 'causes a failure' do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.fail! result.fail!
assert !result.success?, "Expected `result' to NOT be successful" assert !result.success?, "Expected `result' to NOT be successful"
@ -302,14 +302,14 @@ describe Lotus::Interactor::Result do
describe '#prepare!' do describe '#prepare!' do
it 'merges the current payload' do it 'merges the current payload' do
result = Lotus::Interactor::Result.new(foo: 'bar') result = Hanami::Interactor::Result.new(foo: 'bar')
result.prepare!(foo: 23) result.prepare!(foo: 23)
result.foo.must_equal 23 result.foo.must_equal 23
end end
it 'returns self' do it 'returns self' do
result = Lotus::Interactor::Result.new(foo: 'bar') result = Hanami::Interactor::Result.new(foo: 'bar')
returning = result.prepare!(foo: 23) returning = result.prepare!(foo: 23)
assert returning == result, "Expected `returning' to equal `result'" assert returning == result, "Expected `returning' to equal `result'"
@ -318,19 +318,19 @@ describe Lotus::Interactor::Result do
describe "#errors" do describe "#errors" do
it "empty by default" do it "empty by default" do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.errors.must_be :empty? result.errors.must_be :empty?
end end
it "returns all the errors" do it "returns all the errors" do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.add_error ['Error 1', 'Error 2'] result.add_error ['Error 1', 'Error 2']
result.errors.must_equal ['Error 1', 'Error 2'] result.errors.must_equal ['Error 1', 'Error 2']
end end
it "prevents information escape" do it "prevents information escape" do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.add_error ['Error 1', 'Error 2'] result.add_error ['Error 1', 'Error 2']
result.errors.clear result.errors.clear
@ -341,12 +341,12 @@ describe Lotus::Interactor::Result do
describe "#error" do describe "#error" do
it "nil by default" do it "nil by default" do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.error.must_be_nil result.error.must_be_nil
end end
it "returns only the first error" do it "returns only the first error" do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.add_error ['Error 1', 'Error 2'] result.add_error ['Error 1', 'Error 2']
result.error.must_equal 'Error 1' result.error.must_equal 'Error 1'
@ -355,21 +355,21 @@ describe Lotus::Interactor::Result do
describe '#respond_to?' do describe '#respond_to?' do
it 'returns true for concrete methods' do it 'returns true for concrete methods' do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
assert result.respond_to?(:success?), "Expected `result' to respond to `#success?'" assert result.respond_to?(:success?), "Expected `result' to respond to `#success?'"
assert result.respond_to?('success?'), "Expected `result' to respond to `#success?'" assert result.respond_to?('success?'), "Expected `result' to respond to `#success?'"
end end
it 'returns true for methods derived from payload' do it 'returns true for methods derived from payload' do
result = Lotus::Interactor::Result.new(foo: 1) result = Hanami::Interactor::Result.new(foo: 1)
assert result.respond_to?(:foo), "Expected `result' to respond to `#foo'" assert result.respond_to?(:foo), "Expected `result' to respond to `#foo'"
assert result.respond_to?('foo'), "Expected `result' to respond to `#foo'" assert result.respond_to?('foo'), "Expected `result' to respond to `#foo'"
end end
it 'returns true for methods derived from merged payload' do it 'returns true for methods derived from merged payload' do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
result.prepare!('bar' => 2) result.prepare!('bar' => 2)
assert result.respond_to?(:bar), "Expected `result' to respond to `#bar'" assert result.respond_to?(:bar), "Expected `result' to respond to `#bar'"
@ -378,10 +378,10 @@ describe Lotus::Interactor::Result do
end end
describe '#inspect' do describe '#inspect' do
let(:result) { Lotus::Interactor::Result.new(id: 23, user: User.new) } let(:result) { Hanami::Interactor::Result.new(id: 23, user: User.new) }
it 'reports the class name and the object_id' do it 'reports the class name and the object_id' do
result.inspect.must_match %(#<Lotus::Interactor::Result) result.inspect.must_match %(#<Hanami::Interactor::Result)
end end
it 'reports the object_id' do it 'reports the object_id' do
@ -400,13 +400,13 @@ describe Lotus::Interactor::Result do
describe 'payload' do describe 'payload' do
it 'returns all the values passed in the payload' do it 'returns all the values passed in the payload' do
result = Lotus::Interactor::Result.new(a: 1, b: 2) result = Hanami::Interactor::Result.new(a: 1, b: 2)
result.a.must_equal 1 result.a.must_equal 1
result.b.must_equal 2 result.b.must_equal 2
end end
it 'returns all the values after a merge' do it 'returns all the values after a merge' do
result = Lotus::Interactor::Result.new(a: 1, b: 2) result = Hanami::Interactor::Result.new(a: 1, b: 2)
result.prepare!(a: 23, c: 3) result.prepare!(a: 23, c: 3)
result.a.must_equal 23 result.a.must_equal 23
@ -415,17 +415,17 @@ describe Lotus::Interactor::Result do
end end
it "doesn't ignore forwarded messages" do it "doesn't ignore forwarded messages" do
result = Lotus::Interactor::Result.new(params: {name: 'Luca'}) result = Hanami::Interactor::Result.new(params: {name: 'Luca'})
result.params[:name].must_equal 'Luca' result.params[:name].must_equal 'Luca'
end end
it 'raises an error when unknown message is passed' do it 'raises an error when unknown message is passed' do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
-> { result.unknown }.must_raise NoMethodError -> { result.unknown }.must_raise NoMethodError
end end
it 'raises an error when unknown message is passed with args' do it 'raises an error when unknown message is passed with args' do
result = Lotus::Interactor::Result.new result = Hanami::Interactor::Result.new
-> { result.unknown(:foo) }.must_raise NoMethodError -> { result.unknown(:foo) }.must_raise NoMethodError
end end
end end

View File

@ -1,15 +1,15 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/io' require 'hanami/utils/io'
class IOTest class IOTest
TEST_CONSTANT = 'initial' TEST_CONSTANT = 'initial'
end end
describe Lotus::Utils::IO do describe Hanami::Utils::IO do
describe '.silence_warnings' do describe '.silence_warnings' do
it 'lowers verbosity of stdout' do it 'lowers verbosity of stdout' do
_, err = capture_io do _, err = capture_io do
Lotus::Utils::IO.silence_warnings do Hanami::Utils::IO.silence_warnings do
IOTest::TEST_CONSTANT = 'redefined' IOTest::TEST_CONSTANT = 'redefined'
end end
end end

View File

@ -1,9 +1,9 @@
require 'test_helper' require 'test_helper'
require 'ostruct' require 'ostruct'
require 'bigdecimal' require 'bigdecimal'
require 'lotus/utils/kernel' require 'hanami/utils/kernel'
describe Lotus::Utils::Kernel do describe Hanami::Utils::Kernel do
describe '.Array' do describe '.Array' do
describe 'successful operations' do describe 'successful operations' do
before do before do
@ -19,7 +19,7 @@ describe Lotus::Utils::Kernel do
end end
end end
@result = Lotus::Utils::Kernel.Array(input) @result = Hanami::Utils::Kernel.Array(input)
end end
after do after do
@ -153,7 +153,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.Set(input) @result = Hanami::Utils::Kernel.Set(input)
end end
describe 'when nil is given' do describe 'when nil is given' do
@ -259,12 +259,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BaseObject.new } let(:input) { BaseObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Set(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Set(input) }.must_raise(TypeError)
end end
it 'returns informations about the failure' do it 'returns informations about the failure' do
begin begin
Lotus::Utils::Kernel.Set(input) Hanami::Utils::Kernel.Set(input)
rescue => e rescue => e
e.message.must_match "can't convert into Set" e.message.must_match "can't convert into Set"
end end
@ -310,7 +310,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.Hash(input) @result = Hanami::Utils::Kernel.Hash(input)
end end
describe 'when nil is given' do describe 'when nil is given' do
@ -367,12 +367,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BaseObject.new } let(:input) { BaseObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Hash(input) Hanami::Utils::Kernel.Hash(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Hash" e.message.must_equal "can't convert into Hash"
end end
@ -383,7 +383,7 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
end end
@ -391,7 +391,7 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
end end
@ -399,7 +399,7 @@ describe Lotus::Utils::Kernel do
let(:input) { [1] } let(:input) { [1] }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
end end
@ -408,7 +408,7 @@ describe Lotus::Utils::Kernel do
let(:input) { [:a, 1] } let(:input) { [:a, 1] }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
end end
end end
@ -417,7 +417,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Set.new([1]) } let(:input) { Set.new([1]) }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
end end
@ -426,7 +426,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Set.new([:a, 1]) } let(:input) { Set.new([:a, 1]) }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
end end
end end
end end
@ -442,7 +442,7 @@ describe Lotus::Utils::Kernel do
end end
end end
@result = Lotus::Utils::Kernel.Integer(input) @result = Hanami::Utils::Kernel.Integer(input)
end end
after do after do
@ -575,7 +575,7 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
end end
@ -583,7 +583,7 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
end end
@ -591,7 +591,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Date.today } let(:input) { Date.today }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
end end
@ -599,7 +599,7 @@ describe Lotus::Utils::Kernel do
let(:input) { DateTime.now } let(:input) { DateTime.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
end end
@ -607,12 +607,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Integer(input) Hanami::Utils::Kernel.Integer(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Integer" e.message.must_equal "can't convert into Integer"
end end
@ -623,12 +623,12 @@ describe Lotus::Utils::Kernel do
let(:input) { OpenStruct.new(color: 'purple') } let(:input) { OpenStruct.new(color: 'purple') }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Integer(input) Hanami::Utils::Kernel.Integer(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Integer" e.message.must_equal "can't convert #{input.inspect} into Integer"
end end
@ -639,7 +639,7 @@ describe Lotus::Utils::Kernel do
let(:input) { BigDecimal.new('Infinity') } let(:input) { BigDecimal.new('Infinity') }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
end end
@ -647,12 +647,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BigDecimal.new('NaN') } let(:input) { BigDecimal.new('NaN') }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Integer(input) Hanami::Utils::Kernel.Integer(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Integer" e.message.must_equal "can't convert #{input.inspect} into Integer"
end end
@ -663,12 +663,12 @@ describe Lotus::Utils::Kernel do
let(:input) { Complex(2,3) } let(:input) { Complex(2,3) }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Integer(input) Hanami::Utils::Kernel.Integer(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Integer" e.message.must_equal "can't convert #{input.inspect} into Integer"
end end
@ -679,12 +679,12 @@ describe Lotus::Utils::Kernel do
let(:input) { Rational(-8) ** Rational(1, 3) } let(:input) { Rational(-8) ** Rational(1, 3) }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Integer(input) Hanami::Utils::Kernel.Integer(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Integer" e.message.must_equal "can't convert #{input.inspect} into Integer"
end end
@ -695,7 +695,7 @@ describe Lotus::Utils::Kernel do
let(:input) { 'home' } let(:input) { 'home' }
it 'raises error' do it 'raises error' do
exception = -> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) exception = -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
exception.message.must_equal "can't convert #{input.inspect} into Integer" exception.message.must_equal "can't convert #{input.inspect} into Integer"
end end
end end
@ -704,7 +704,7 @@ describe Lotus::Utils::Kernel do
let(:input) { '23 street' } let(:input) { '23 street' }
it 'raises error' do it 'raises error' do
exception = -> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError) exception = -> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
exception.message.must_equal "can't convert #{input.inspect} into Integer" exception.message.must_equal "can't convert #{input.inspect} into Integer"
end end
end end
@ -720,7 +720,7 @@ describe Lotus::Utils::Kernel do
end end
end end
@result = Lotus::Utils::Kernel.BigDecimal(input) @result = Hanami::Utils::Kernel.BigDecimal(input)
end end
after do after do
@ -871,7 +871,7 @@ describe Lotus::Utils::Kernel do
let(:input) { nil } let(:input) { nil }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
end end
@ -879,7 +879,7 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
end end
@ -887,7 +887,7 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
end end
@ -895,7 +895,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Date.today } let(:input) { Date.today }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
end end
@ -903,7 +903,7 @@ describe Lotus::Utils::Kernel do
let(:input) { DateTime.now } let(:input) { DateTime.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
end end
@ -911,7 +911,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Time.now } let(:input) { Time.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
end end
@ -919,7 +919,7 @@ describe Lotus::Utils::Kernel do
let(:input) { 'home' } let(:input) { 'home' }
it 'raises error' do it 'raises error' do
exception = -> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) exception = -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
exception.message.must_equal "can't convert #{input.inspect} into BigDecimal" exception.message.must_equal "can't convert #{input.inspect} into BigDecimal"
end end
end end
@ -928,7 +928,7 @@ describe Lotus::Utils::Kernel do
let(:input) { '23.0 street' } let(:input) { '23.0 street' }
it 'raises error' do it 'raises error' do
exception = -> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) exception = -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
exception.message.must_equal "can't convert #{input.inspect} into BigDecimal" exception.message.must_equal "can't convert #{input.inspect} into BigDecimal"
end end
end end
@ -937,12 +937,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.BigDecimal(input) Hanami::Utils::Kernel.BigDecimal(input)
rescue => e rescue => e
e.message.must_equal "can't convert into BigDecimal" e.message.must_equal "can't convert into BigDecimal"
end end
@ -960,7 +960,7 @@ describe Lotus::Utils::Kernel do
end end
end end
@result = Lotus::Utils::Kernel.Float(input) @result = Hanami::Utils::Kernel.Float(input)
end end
after do after do
@ -1122,7 +1122,7 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
end end
@ -1130,7 +1130,7 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
end end
@ -1138,7 +1138,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Date.today } let(:input) { Date.today }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
end end
@ -1146,7 +1146,7 @@ describe Lotus::Utils::Kernel do
let(:input) { DateTime.now } let(:input) { DateTime.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
end end
@ -1154,7 +1154,7 @@ describe Lotus::Utils::Kernel do
let(:input) { 'home' } let(:input) { 'home' }
it 'raises error' do it 'raises error' do
exception = -> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) exception = -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
exception.message.must_equal "can't convert #{input.inspect} into Float" exception.message.must_equal "can't convert #{input.inspect} into Float"
end end
end end
@ -1163,7 +1163,7 @@ describe Lotus::Utils::Kernel do
let(:input) { '23.0 street' } let(:input) { '23.0 street' }
it 'raises error' do it 'raises error' do
exception = -> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) exception = -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
exception.message.must_equal "can't convert #{input.inspect} into Float" exception.message.must_equal "can't convert #{input.inspect} into Float"
end end
end end
@ -1172,12 +1172,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Float(input) Hanami::Utils::Kernel.Float(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Float" e.message.must_equal "can't convert into Float"
end end
@ -1188,7 +1188,7 @@ describe Lotus::Utils::Kernel do
let(:input) { OpenStruct.new(color: 'purple') } let(:input) { OpenStruct.new(color: 'purple') }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
end end
@ -1196,12 +1196,12 @@ describe Lotus::Utils::Kernel do
let(:input) { Complex(2,3) } let(:input) { Complex(2,3) }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Float(input) Hanami::Utils::Kernel.Float(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Float" e.message.must_equal "can't convert #{input.inspect} into Float"
end end
@ -1212,12 +1212,12 @@ describe Lotus::Utils::Kernel do
let(:input) { Rational(-8) ** Rational(1, 3) } let(:input) { Rational(-8) ** Rational(1, 3) }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Float(input) Hanami::Utils::Kernel.Float(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Float" e.message.must_equal "can't convert #{input.inspect} into Float"
end end
@ -1255,7 +1255,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.String(input) @result = Hanami::Utils::Kernel.String(input)
end end
describe 'when nil is given' do describe 'when nil is given' do
@ -1419,10 +1419,10 @@ describe Lotus::Utils::Kernel do
end end
describe 'when a symbol is given' do describe 'when a symbol is given' do
let(:input) { :lotus } let(:input) { :hanami }
it 'returns the string representation' do it 'returns the string representation' do
@result.must_equal 'lotus' @result.must_equal 'hanami'
end end
end end
@ -1475,10 +1475,10 @@ describe Lotus::Utils::Kernel do
end end
describe 'when a module is given' do describe 'when a module is given' do
let(:input) { Lotus } let(:input) { Hanami }
it 'returns the string representation' do it 'returns the string representation' do
@result.must_equal 'Lotus' @result.must_equal 'Hanami'
end end
end end
@ -1504,7 +1504,7 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.String(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.String(input) }.must_raise(TypeError)
end end
end end
end end
@ -1532,7 +1532,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.Boolean(input) @result = Hanami::Utils::Kernel.Boolean(input)
end end
describe 'when nil is given' do describe 'when nil is given' do
@ -1629,12 +1629,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Boolean(input) }.must_raise(TypeError) -> { Hanami::Utils::Kernel.Boolean(input) }.must_raise(TypeError)
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Boolean(input) Hanami::Utils::Kernel.Boolean(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Boolean" e.message.must_equal "can't convert into Boolean"
end end
@ -1665,7 +1665,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.Date(input) @result = Hanami::Utils::Kernel.Date(input)
end end
describe 'when a date is given' do describe 'when a date is given' do
@ -1722,12 +1722,12 @@ describe Lotus::Utils::Kernel do
let(:input) { nil } let(:input) { nil }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1738,12 +1738,12 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1754,12 +1754,12 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1770,12 +1770,12 @@ describe Lotus::Utils::Kernel do
let(:input) { 2 } let(:input) { 2 }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1786,12 +1786,12 @@ describe Lotus::Utils::Kernel do
let(:input) { 2332.903007 } let(:input) { 2332.903007 }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1802,12 +1802,12 @@ describe Lotus::Utils::Kernel do
let(:input) { 'lego' } let(:input) { 'lego' }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1818,12 +1818,12 @@ describe Lotus::Utils::Kernel do
let(:input) { '18:55' } let(:input) { '18:55' }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Date" e.message.must_equal "can't convert #{input.inspect} into Date"
end end
@ -1834,12 +1834,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Date" e.message.must_equal "can't convert into Date"
end end
@ -1850,12 +1850,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BaseObject.new } let(:input) { BaseObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Date(input) Hanami::Utils::Kernel.Date(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Date" e.message.must_equal "can't convert into Date"
end end
@ -1886,7 +1886,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.DateTime(input) @result = Hanami::Utils::Kernel.DateTime(input)
end end
describe 'when a datetime is given' do describe 'when a datetime is given' do
@ -1967,12 +1967,12 @@ describe Lotus::Utils::Kernel do
let(:input) { nil } let(:input) { nil }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.DateTime(input) Hanami::Utils::Kernel.DateTime(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into DateTime" e.message.must_equal "can't convert #{input.inspect} into DateTime"
end end
@ -1983,12 +1983,12 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.DateTime(input) Hanami::Utils::Kernel.DateTime(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into DateTime" e.message.must_equal "can't convert #{input.inspect} into DateTime"
end end
@ -1999,12 +1999,12 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.DateTime(input) Hanami::Utils::Kernel.DateTime(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into DateTime" e.message.must_equal "can't convert #{input.inspect} into DateTime"
end end
@ -2015,12 +2015,12 @@ describe Lotus::Utils::Kernel do
let(:input) { 'crab' } let(:input) { 'crab' }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.DateTime(input) Hanami::Utils::Kernel.DateTime(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into DateTime" e.message.must_equal "can't convert #{input.inspect} into DateTime"
end end
@ -2031,12 +2031,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.DateTime(input) Hanami::Utils::Kernel.DateTime(input)
rescue => e rescue => e
e.message.must_equal "can't convert into DateTime" e.message.must_equal "can't convert into DateTime"
end end
@ -2047,12 +2047,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BaseObject.new } let(:input) { BaseObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.DateTime(input) Hanami::Utils::Kernel.DateTime(input)
rescue => e rescue => e
e.message.must_equal "can't convert into DateTime" e.message.must_equal "can't convert into DateTime"
end end
@ -2083,7 +2083,7 @@ describe Lotus::Utils::Kernel do
describe 'successful operations' do describe 'successful operations' do
before do before do
@result = Lotus::Utils::Kernel.Time(input) @result = Hanami::Utils::Kernel.Time(input)
end end
describe 'when a time is given' do describe 'when a time is given' do
@ -2164,12 +2164,12 @@ describe Lotus::Utils::Kernel do
let(:input) { nil } let(:input) { nil }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Time(input) Hanami::Utils::Kernel.Time(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Time" e.message.must_equal "can't convert #{input.inspect} into Time"
end end
@ -2180,12 +2180,12 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Time(input) Hanami::Utils::Kernel.Time(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Time" e.message.must_equal "can't convert #{input.inspect} into Time"
end end
@ -2196,12 +2196,12 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Time(input) Hanami::Utils::Kernel.Time(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Time" e.message.must_equal "can't convert #{input.inspect} into Time"
end end
@ -2212,12 +2212,12 @@ describe Lotus::Utils::Kernel do
let(:input) { 'boat' } let(:input) { 'boat' }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Time(input) Hanami::Utils::Kernel.Time(input)
rescue => e rescue => e
e.message.must_equal "can't convert #{input.inspect} into Time" e.message.must_equal "can't convert #{input.inspect} into Time"
end end
@ -2228,12 +2228,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Time(input) Hanami::Utils::Kernel.Time(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Time" e.message.must_equal "can't convert into Time"
end end
@ -2244,12 +2244,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BaseObject.new } let(:input) { BaseObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Time(input) Hanami::Utils::Kernel.Time(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Time" e.message.must_equal "can't convert into Time"
end end
@ -2273,7 +2273,7 @@ describe Lotus::Utils::Kernel do
end end
end end
@result = Lotus::Utils::Kernel.Pathname(input) @result = Hanami::Utils::Kernel.Pathname(input)
end end
after do after do
@ -2319,7 +2319,7 @@ describe Lotus::Utils::Kernel do
let(:input) { nil } let(:input) { nil }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2327,7 +2327,7 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2335,7 +2335,7 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2343,7 +2343,7 @@ describe Lotus::Utils::Kernel do
let(:input) { 12 } let(:input) { 12 }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2351,7 +2351,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Date.today } let(:input) { Date.today }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2359,7 +2359,7 @@ describe Lotus::Utils::Kernel do
let(:input) { DateTime.now } let(:input) { DateTime.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2367,7 +2367,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Time.now } let(:input) { Time.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
end end
@ -2375,12 +2375,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Pathname(input) Hanami::Utils::Kernel.Pathname(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Pathname" e.message.must_equal "can't convert into Pathname"
end end
@ -2398,7 +2398,7 @@ describe Lotus::Utils::Kernel do
end end
end end
@result = Lotus::Utils::Kernel.Symbol(input) @result = Hanami::Utils::Kernel.Symbol(input)
end end
after do after do
@ -2435,7 +2435,7 @@ describe Lotus::Utils::Kernel do
let(:input) { nil } let(:input) { nil }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2443,7 +2443,7 @@ describe Lotus::Utils::Kernel do
let(:input) { '' } let(:input) { '' }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2451,7 +2451,7 @@ describe Lotus::Utils::Kernel do
let(:input) { true } let(:input) { true }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2459,7 +2459,7 @@ describe Lotus::Utils::Kernel do
let(:input) { false } let(:input) { false }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2467,7 +2467,7 @@ describe Lotus::Utils::Kernel do
let(:input) { 12 } let(:input) { 12 }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2475,7 +2475,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Date.today } let(:input) { Date.today }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2483,7 +2483,7 @@ describe Lotus::Utils::Kernel do
let(:input) { DateTime.now } let(:input) { DateTime.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2491,7 +2491,7 @@ describe Lotus::Utils::Kernel do
let(:input) { Time.now } let(:input) { Time.now }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
end end
@ -2499,12 +2499,12 @@ describe Lotus::Utils::Kernel do
let(:input) { BasicObject.new } let(:input) { BasicObject.new }
it 'raises error' do it 'raises error' do
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError -> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
end end
it 'returns useful informations about the failure' do it 'returns useful informations about the failure' do
begin begin
Lotus::Utils::Kernel.Symbol(input) Hanami::Utils::Kernel.Symbol(input)
rescue => e rescue => e
e.message.must_equal "can't convert into Symbol" e.message.must_equal "can't convert into Symbol"
end end

View File

@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/load_paths' require 'hanami/utils/load_paths'
Lotus::Utils::LoadPaths.class_eval do Hanami::Utils::LoadPaths.class_eval do
def empty? def empty?
@paths.empty? @paths.empty?
end end
@ -11,20 +11,20 @@ Lotus::Utils::LoadPaths.class_eval do
end end
end end
describe Lotus::Utils::LoadPaths do describe Hanami::Utils::LoadPaths do
describe '#initialize' do describe '#initialize' do
it 'can be initialized with zero paths' do it 'can be initialized with zero paths' do
paths = Lotus::Utils::LoadPaths.new paths = Hanami::Utils::LoadPaths.new
paths.must_be_empty paths.must_be_empty
end end
it 'can be initialized with one path' do it 'can be initialized with one path' do
paths = Lotus::Utils::LoadPaths.new '..' paths = Hanami::Utils::LoadPaths.new '..'
paths.must_include '..' paths.must_include '..'
end end
it 'can be initialized with more paths' do it 'can be initialized with more paths' do
paths = Lotus::Utils::LoadPaths.new '..', '../..' paths = Hanami::Utils::LoadPaths.new '..', '../..'
paths.must_include '..' paths.must_include '..'
paths.must_include '../..' paths.must_include '../..'
end end
@ -32,7 +32,7 @@ describe Lotus::Utils::LoadPaths do
describe '#each' do describe '#each' do
it 'coerces the given paths to pathnames and yields a block' do it 'coerces the given paths to pathnames and yields a block' do
paths = Lotus::Utils::LoadPaths.new '..', '../..' paths = Hanami::Utils::LoadPaths.new '..', '../..'
paths.each do |path| paths.each do |path|
path.must_be_kind_of Pathname path.must_be_kind_of Pathname
@ -40,12 +40,12 @@ describe Lotus::Utils::LoadPaths do
end end
it 'remove duplicates' do it 'remove duplicates' do
paths = Lotus::Utils::LoadPaths.new '..', '..' paths = Hanami::Utils::LoadPaths.new '..', '..'
paths.each(&Proc.new{}).size.must_equal 1 paths.each(&Proc.new{}).size.must_equal 1
end end
it 'raises an error if a path is unknown' do it 'raises an error if a path is unknown' do
paths = Lotus::Utils::LoadPaths.new 'unknown/path' paths = Hanami::Utils::LoadPaths.new 'unknown/path'
-> { -> {
paths.each { } paths.each { }
@ -55,7 +55,7 @@ describe Lotus::Utils::LoadPaths do
describe '#push' do describe '#push' do
it 'adds the given path' do it 'adds the given path' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths.push '..' paths.push '..'
paths.must_include '.' paths.must_include '.'
@ -63,7 +63,7 @@ describe Lotus::Utils::LoadPaths do
end end
it 'adds the given paths' do it 'adds the given paths' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths.push '..', '../..' paths.push '..', '../..'
paths.must_include '.' paths.must_include '.'
@ -72,19 +72,19 @@ describe Lotus::Utils::LoadPaths do
end end
it 'removes duplicates' do it 'removes duplicates' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths.push '.', '.' paths.push '.', '.'
paths.each(&Proc.new{}).size.must_equal 1 paths.each(&Proc.new{}).size.must_equal 1
end end
it 'removes nil' do it 'removes nil' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths.push nil paths.push nil
paths.each(&Proc.new{}).size.must_equal 1 paths.each(&Proc.new{}).size.must_equal 1
end end
it 'returns self so multiple operations can be performed' do it 'returns self so multiple operations can be performed' do
paths = Lotus::Utils::LoadPaths.new paths = Hanami::Utils::LoadPaths.new
returning = paths.push('.') returning = paths.push('.')
returning.must_be_same_as(paths) returning.must_be_same_as(paths)
@ -99,7 +99,7 @@ describe Lotus::Utils::LoadPaths do
describe '#<< (alias of #push)' do describe '#<< (alias of #push)' do
it 'adds the given path' do it 'adds the given path' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths << '..' paths << '..'
paths.must_include '.' paths.must_include '.'
@ -107,14 +107,14 @@ describe Lotus::Utils::LoadPaths do
end end
it 'adds the given paths' do it 'adds the given paths' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths << ['..', '../..'] paths << ['..', '../..']
assert paths == ['.', '..', '../..'] assert paths == ['.', '..', '../..']
end end
it 'returns self so multiple operations can be performed' do it 'returns self so multiple operations can be performed' do
paths = Lotus::Utils::LoadPaths.new paths = Hanami::Utils::LoadPaths.new
returning = paths << '.' returning = paths << '.'
returning.must_be_same_as(paths) returning.must_be_same_as(paths)
@ -129,7 +129,7 @@ describe Lotus::Utils::LoadPaths do
describe '#dup' do describe '#dup' do
it 'returns a copy of self' do it 'returns a copy of self' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths2 = paths.dup paths2 = paths.dup
paths << '..' paths << '..'
@ -147,7 +147,7 @@ describe Lotus::Utils::LoadPaths do
describe '#clone' do describe '#clone' do
it 'returns a copy of self' do it 'returns a copy of self' do
paths = Lotus::Utils::LoadPaths.new '.' paths = Hanami::Utils::LoadPaths.new '.'
paths2 = paths.clone paths2 = paths.clone
paths << '..' paths << '..'
@ -165,14 +165,14 @@ describe Lotus::Utils::LoadPaths do
describe '#freeze' do describe '#freeze' do
it 'freezes the object' do it 'freezes the object' do
paths = Lotus::Utils::LoadPaths.new paths = Hanami::Utils::LoadPaths.new
paths.freeze paths.freeze
paths.must_be :frozen? paths.must_be :frozen?
end end
it "doesn't allow to push paths" do it "doesn't allow to push paths" do
paths = Lotus::Utils::LoadPaths.new paths = Hanami::Utils::LoadPaths.new
paths.freeze paths.freeze
-> { paths.push '.' }.must_raise RuntimeError -> { paths.push '.' }.must_raise RuntimeError
@ -181,35 +181,35 @@ describe Lotus::Utils::LoadPaths do
describe '#==' do describe '#==' do
it "checks equality with LoadPaths" do it "checks equality with LoadPaths" do
paths = Lotus::Utils::LoadPaths.new('.', '.') paths = Hanami::Utils::LoadPaths.new('.', '.')
other = Lotus::Utils::LoadPaths.new('.') other = Hanami::Utils::LoadPaths.new('.')
other.must_equal paths other.must_equal paths
end end
it "it returns false if the paths aren't equal" do it "it returns false if the paths aren't equal" do
paths = Lotus::Utils::LoadPaths.new('.', '..') paths = Hanami::Utils::LoadPaths.new('.', '..')
other = Lotus::Utils::LoadPaths.new('.') other = Hanami::Utils::LoadPaths.new('.')
other.wont_equal paths other.wont_equal paths
end end
it "checks equality with Array" do it "checks equality with Array" do
paths = Lotus::Utils::LoadPaths.new('.', '.') paths = Hanami::Utils::LoadPaths.new('.', '.')
other = ['.'] other = ['.']
other.must_equal paths other.must_equal paths
end end
it "it returns false if given array isn't equal" do it "it returns false if given array isn't equal" do
paths = Lotus::Utils::LoadPaths.new('.', '..') paths = Hanami::Utils::LoadPaths.new('.', '..')
other = ['.'] other = ['.']
other.wont_equal paths other.wont_equal paths
end end
it "it returns false the type isn't matchable" do it "it returns false the type isn't matchable" do
paths = Lotus::Utils::LoadPaths.new('.', '..') paths = Hanami::Utils::LoadPaths.new('.', '..')
other = nil other = nil
other.wont_equal paths other.wont_equal paths

View File

@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
require 'lotus/logger' require 'hanami/logger'
describe Lotus::Logger do describe Hanami::Logger do
before do before do
#clear defined class #clear defined class
@ -9,14 +9,14 @@ describe Lotus::Logger do
end end
it 'like std logger, sets log level to info by default' do it 'like std logger, sets log level to info by default' do
class TestLogger < Lotus::Logger; end class TestLogger < Hanami::Logger; end
TestLogger.new.info?.must_equal true TestLogger.new.info?.must_equal true
end end
it 'always use STDOUT' do it 'always use STDOUT' do
output = output =
stub_stdout_constant do stub_stdout_constant do
class TestLogger < Lotus::Logger; end class TestLogger < Hanami::Logger; end
logger = TestLogger.new logger = TestLogger.new
logger.info('foo') logger.info('foo')
end end
@ -27,7 +27,7 @@ describe Lotus::Logger do
it 'has application_name when log' do it 'has application_name when log' do
output = output =
stub_stdout_constant do stub_stdout_constant do
module App; class TestLogger < Lotus::Logger; end; end module App; class TestLogger < Hanami::Logger; end; end
logger = App::TestLogger.new logger = App::TestLogger.new
logger.info('foo') logger.info('foo')
end end
@ -36,13 +36,13 @@ describe Lotus::Logger do
end end
it 'has default app tag when not in any namespace' do it 'has default app tag when not in any namespace' do
class TestLogger < Lotus::Logger; end class TestLogger < Hanami::Logger; end
TestLogger.new.application_name.must_equal 'Lotus' TestLogger.new.application_name.must_equal 'Hanami'
end end
it 'infers apptag from namespace' do it 'infers apptag from namespace' do
module App2 module App2
class TestLogger < Lotus::Logger;end class TestLogger < Hanami::Logger;end
class Bar class Bar
def hoge def hoge
TestLogger.new.send(:application_name).must_equal 'App2' TestLogger.new.send(:application_name).must_equal 'App2'
@ -53,7 +53,7 @@ describe Lotus::Logger do
end end
it 'uses custom application_name from override class' do it 'uses custom application_name from override class' do
class TestLogger < Lotus::Logger; def application_name; 'bar'; end; end class TestLogger < Hanami::Logger; def application_name; 'bar'; end; end
output = output =
stub_stdout_constant do stub_stdout_constant do
@ -67,10 +67,10 @@ describe Lotus::Logger do
stub_time_now do stub_time_now do
output = output =
stub_stdout_constant do stub_stdout_constant do
class TestLogger < Lotus::Logger;end class TestLogger < Hanami::Logger;end
TestLogger.new.info('foo') TestLogger.new.info('foo')
end end
output.must_equal "I, [1988-09-01T00:00:00.000000 ##{Process.pid}] INFO -- [Lotus] : foo\n" output.must_equal "I, [1988-09-01T00:00:00.000000 ##{Process.pid}] INFO -- [Hanami] : foo\n"
end end
end end
end end

View File

@ -1,152 +1,152 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils/path_prefix' require 'hanami/utils/path_prefix'
describe Lotus::Utils::PathPrefix do describe Hanami::Utils::PathPrefix do
it 'exposes itself as a string' do it 'exposes itself as a string' do
prefix = Lotus::Utils::PathPrefix.new prefix = Hanami::Utils::PathPrefix.new
assert prefix == '', "Expected #{ prefix } to equal ''" assert prefix == '', "Expected #{ prefix } to equal ''"
end end
it 'adds root prefix only when needed' do it 'adds root prefix only when needed' do
prefix = Lotus::Utils::PathPrefix.new('/fruits') prefix = Hanami::Utils::PathPrefix.new('/fruits')
assert prefix == '/fruits', "Expected #{ prefix } to equal '/fruits'" assert prefix == '/fruits', "Expected #{ prefix } to equal '/fruits'"
end end
describe '#join' do describe '#join' do
it 'returns a PathPrefix' do it 'returns a PathPrefix' do
prefix = Lotus::Utils::PathPrefix.new('orders', '?').join('new') prefix = Hanami::Utils::PathPrefix.new('orders', '?').join('new')
prefix.must_be_kind_of(Lotus::Utils::PathPrefix) prefix.must_be_kind_of(Hanami::Utils::PathPrefix)
prefix.__send__(:separator).must_equal('?') prefix.__send__(:separator).must_equal('?')
end end
it 'joins a string' do it 'joins a string' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.join('peaches').must_equal '/fruits/peaches' prefix.join('peaches').must_equal '/fruits/peaches'
end end
it 'joins a prefixed string' do it 'joins a prefixed string' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.join('/cherries').must_equal '/fruits/cherries' prefix.join('/cherries').must_equal '/fruits/cherries'
end end
it 'joins a string that is the same as the prefix' do it 'joins a string that is the same as the prefix' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.join('fruits').must_equal '/fruits/fruits' prefix.join('fruits').must_equal '/fruits/fruits'
end end
it 'joins a string when the root is blank' do it 'joins a string when the root is blank' do
prefix = Lotus::Utils::PathPrefix.new prefix = Hanami::Utils::PathPrefix.new
prefix.join('tea').must_equal '/tea' prefix.join('tea').must_equal '/tea'
end end
it 'joins a prefixed string when the root is blank' do it 'joins a prefixed string when the root is blank' do
prefix = Lotus::Utils::PathPrefix.new prefix = Hanami::Utils::PathPrefix.new
prefix.join('/tea').must_equal '/tea' prefix.join('/tea').must_equal '/tea'
end end
it 'joins multiple strings' do it 'joins multiple strings' do
prefix = Lotus::Utils::PathPrefix.new prefix = Hanami::Utils::PathPrefix.new
prefix.join('assets', 'application.js').must_equal '/assets/application.js' prefix.join('assets', 'application.js').must_equal '/assets/application.js'
prefix = Lotus::Utils::PathPrefix.new('myapp') prefix = Hanami::Utils::PathPrefix.new('myapp')
prefix.join('assets', 'application.js').must_equal '/myapp/assets/application.js' prefix.join('assets', 'application.js').must_equal '/myapp/assets/application.js'
prefix = Lotus::Utils::PathPrefix.new('/myapp') prefix = Hanami::Utils::PathPrefix.new('/myapp')
prefix.join('/assets', 'application.js').must_equal '/myapp/assets/application.js' prefix.join('/assets', 'application.js').must_equal '/myapp/assets/application.js'
end end
it 'rejects entries that are matching separator' do it 'rejects entries that are matching separator' do
prefix = Lotus::Utils::PathPrefix.new('/assets') prefix = Hanami::Utils::PathPrefix.new('/assets')
prefix.join('/').must_equal '/assets' prefix.join('/').must_equal '/assets'
end end
it 'removes trailing occurrences of separator' do it 'removes trailing occurrences of separator' do
prefix = Lotus::Utils::PathPrefix.new('curcuma') prefix = Hanami::Utils::PathPrefix.new('curcuma')
prefix.join(nil).must_equal '/curcuma' prefix.join(nil).must_equal '/curcuma'
end end
end end
describe '#relative_join' do describe '#relative_join' do
it 'returns a PathPrefix' do it 'returns a PathPrefix' do
prefix = Lotus::Utils::PathPrefix.new('orders', '&').relative_join('new') prefix = Hanami::Utils::PathPrefix.new('orders', '&').relative_join('new')
prefix.must_be_kind_of(Lotus::Utils::PathPrefix) prefix.must_be_kind_of(Hanami::Utils::PathPrefix)
prefix.__send__(:separator).must_equal('&') prefix.__send__(:separator).must_equal('&')
end end
it 'joins a string without prefixing with separator' do it 'joins a string without prefixing with separator' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.relative_join('peaches').must_equal 'fruits/peaches' prefix.relative_join('peaches').must_equal 'fruits/peaches'
end end
it 'joins a prefixed string without prefixing with separator' do it 'joins a prefixed string without prefixing with separator' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.relative_join('/cherries').must_equal 'fruits/cherries' prefix.relative_join('/cherries').must_equal 'fruits/cherries'
end end
it 'joins a string when the root is blank without prefixing with separator' do it 'joins a string when the root is blank without prefixing with separator' do
prefix = Lotus::Utils::PathPrefix.new prefix = Hanami::Utils::PathPrefix.new
prefix.relative_join('tea').must_equal 'tea' prefix.relative_join('tea').must_equal 'tea'
end end
it 'joins a prefixed string when the root is blank and removes the prefix' do it 'joins a prefixed string when the root is blank and removes the prefix' do
prefix = Lotus::Utils::PathPrefix.new prefix = Hanami::Utils::PathPrefix.new
prefix.relative_join('/tea').must_equal 'tea' prefix.relative_join('/tea').must_equal 'tea'
end end
it 'joins a string with custom separator' do it 'joins a string with custom separator' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.relative_join('cherries', '_').must_equal 'fruits_cherries' prefix.relative_join('cherries', '_').must_equal 'fruits_cherries'
end end
it 'joins a prefixed string without prefixing with custom separator' do it 'joins a prefixed string without prefixing with custom separator' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
prefix.relative_join('_cherries', '_').must_equal 'fruits_cherries' prefix.relative_join('_cherries', '_').must_equal 'fruits_cherries'
end end
it 'changes all the occurences of the current separator with the given one' do it 'changes all the occurences of the current separator with the given one' do
prefix = Lotus::Utils::PathPrefix.new('?fruits', '?') prefix = Hanami::Utils::PathPrefix.new('?fruits', '?')
prefix.relative_join('cherries', '_').must_equal 'fruits_cherries' prefix.relative_join('cherries', '_').must_equal 'fruits_cherries'
end end
it 'removes trailing occurrences of separator' do it 'removes trailing occurrences of separator' do
prefix = Lotus::Utils::PathPrefix.new('jojoba') prefix = Hanami::Utils::PathPrefix.new('jojoba')
prefix.relative_join(nil).must_equal 'jojoba' prefix.relative_join(nil).must_equal 'jojoba'
end end
it 'rejects entries that are matching separator' do it 'rejects entries that are matching separator' do
prefix = Lotus::Utils::PathPrefix.new('assets') prefix = Hanami::Utils::PathPrefix.new('assets')
prefix.relative_join('/').must_equal 'assets' prefix.relative_join('/').must_equal 'assets'
end end
it 'raises error if the given separator is nil' do it 'raises error if the given separator is nil' do
prefix = Lotus::Utils::PathPrefix.new('fruits') prefix = Hanami::Utils::PathPrefix.new('fruits')
-> { prefix.relative_join('_cherries', nil) }.must_raise TypeError -> { prefix.relative_join('_cherries', nil) }.must_raise TypeError
end end
end end
# describe '#resolve' do # describe '#resolve' do
# it 'resolves empty path' do # it 'resolves empty path' do
# prefix = Lotus::Utils::PathPrefix.new('') # prefix = Hanami::Utils::PathPrefix.new('')
# prefix.resolve.must_equal '/' # prefix.resolve.must_equal '/'
# end # end
# it 'resolves root path path' do # it 'resolves root path path' do
# prefix = Lotus::Utils::PathPrefix.new('/') # prefix = Hanami::Utils::PathPrefix.new('/')
# prefix.resolve.must_equal '/' # prefix.resolve.must_equal '/'
# end # end
# it 'absolutize relative path' do # it 'absolutize relative path' do
# prefix = Lotus::Utils::PathPrefix.new('coffees') # prefix = Hanami::Utils::PathPrefix.new('coffees')
# prefix.resolve.must_equal '/coffees' # prefix.resolve.must_equal '/coffees'
# end # end
# it 'leaves untouched absolute path' do # it 'leaves untouched absolute path' do
# prefix = Lotus::Utils::PathPrefix.new('/coffees') # prefix = Hanami::Utils::PathPrefix.new('/coffees')
# prefix.resolve.must_equal '/coffees' # prefix.resolve.must_equal '/coffees'
# end # end
# it 'removes double leading slashes' do # it 'removes double leading slashes' do
# prefix = Lotus::Utils::PathPrefix.new('//coffees') # prefix = Hanami::Utils::PathPrefix.new('//coffees')
# prefix.resolve.must_equal '/coffees' # prefix.resolve.must_equal '/coffees'
# end # end
# end # end
@ -154,60 +154,60 @@ describe Lotus::Utils::PathPrefix do
describe 'string interface' do describe 'string interface' do
describe 'equality' do describe 'equality' do
it 'has a working equality' do it 'has a working equality' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
other = Lotus::Utils::PathPrefix.new('lotus') other = Hanami::Utils::PathPrefix.new('hanami')
assert string == other assert string == other
end end
it 'has a working equality with raw strings' do it 'has a working equality with raw strings' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
assert string == 'lotus' assert string == 'hanami'
end end
end end
describe 'case equality' do describe 'case equality' do
it 'has a working case equality' do it 'has a working case equality' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
other = Lotus::Utils::PathPrefix.new('lotus') other = Hanami::Utils::PathPrefix.new('hanami')
assert string === other assert string === other
end end
it 'has a working case equality with raw strings' do it 'has a working case equality with raw strings' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
assert string === 'lotus' assert string === 'hanami'
end end
end end
describe 'value equality' do describe 'value equality' do
it 'has a working value equality' do it 'has a working value equality' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
other = Lotus::Utils::PathPrefix.new('lotus') other = Hanami::Utils::PathPrefix.new('hanami')
assert string.eql?(other) assert string.eql?(other)
end end
it 'has a working value equality with raw strings' do it 'has a working value equality with raw strings' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
assert string.eql?('lotus') assert string.eql?('hanami')
end end
end end
describe 'identity equality' do describe 'identity equality' do
it 'has a working identity equality' do it 'has a working identity equality' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
assert string.equal?(string) assert string.equal?(string)
end end
it 'has a working identity equality with raw strings' do it 'has a working identity equality with raw strings' do
string = Lotus::Utils::PathPrefix.new('lotus') string = Hanami::Utils::PathPrefix.new('hanami')
assert !string.equal?('lotus') assert !string.equal?('hanami')
end end
end end
describe '#hash' do describe '#hash' do
it 'returns the same hash result of ::String' do it 'returns the same hash result of ::String' do
expected = 'hello'.hash expected = 'hello'.hash
actual = Lotus::Utils::PathPrefix.new('hello').hash actual = Hanami::Utils::PathPrefix.new('hello').hash
actual.must_equal expected actual.must_equal expected
end end

View File

@ -1,208 +1,208 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils' require 'hanami/utils'
require 'lotus/utils/string' require 'hanami/utils/string'
describe Lotus::Utils::String do describe Hanami::Utils::String do
describe '#titleize' do describe '#titleize' do
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
Lotus::Utils::String.new('lotus').titleize.must_be_kind_of(Lotus::Utils::String) Hanami::Utils::String.new('hanami').titleize.must_be_kind_of(Hanami::Utils::String)
end end
it "doesn't mutate self" do it "doesn't mutate self" do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
string.titleize string.titleize
string.must_equal 'lotus' string.must_equal 'hanami'
end end
it 'returns an titleized string' do it 'returns an titleized string' do
Lotus::Utils::String.new('lotus').titleize.must_equal 'Lotus' Hanami::Utils::String.new('hanami').titleize.must_equal 'Hanami'
Lotus::Utils::String.new('LotusUtils').titleize.must_equal 'Lotus Utils' Hanami::Utils::String.new('HanamiUtils').titleize.must_equal 'Hanami Utils'
Lotus::Utils::String.new('lotus utils').titleize.must_equal 'Lotus Utils' Hanami::Utils::String.new('hanami utils').titleize.must_equal 'Hanami Utils'
Lotus::Utils::String.new('lotus_utils').titleize.must_equal 'Lotus Utils' Hanami::Utils::String.new('hanami_utils').titleize.must_equal 'Hanami Utils'
Lotus::Utils::String.new('lotus-utils').titleize.must_equal 'Lotus Utils' Hanami::Utils::String.new('hanami-utils').titleize.must_equal 'Hanami Utils'
Lotus::Utils::String.new("lotus' utils").titleize.must_equal "Lotus' Utils" Hanami::Utils::String.new("hanami' utils").titleize.must_equal "Hanami' Utils"
Lotus::Utils::String.new("lotus utils").titleize.must_equal "Lotus Utils" Hanami::Utils::String.new("hanami utils").titleize.must_equal "Hanami Utils"
Lotus::Utils::String.new("lotus` utils").titleize.must_equal "Lotus` Utils" Hanami::Utils::String.new("hanami` utils").titleize.must_equal "Hanami` Utils"
# Ruby's upcase works only with ASCII chars. # Ruby's upcase works only with ASCII chars.
# Lotus::Utils::String.new("è vero?").titleize.must_equal "È Vero?" # Hanami::Utils::String.new("è vero?").titleize.must_equal "È Vero?"
end end
end end
describe '#capitalize' do describe '#capitalize' do
# it 'returns an instance of Lotus::Utils::String' do # it 'returns an instance of Hanami::Utils::String' do
# Lotus::Utils::String.new('lotus').capitalize.must_be_kind_of(Lotus::Utils::String) # Hanami::Utils::String.new('hanami').capitalize.must_be_kind_of(Hanami::Utils::String)
# end # end
# it "doesn't mutate self" do # it "doesn't mutate self" do
# string = Lotus::Utils::String.new('lotus') # string = Hanami::Utils::String.new('hanami')
# string.capitalize # string.capitalize
# string.must_equal 'lotus' # string.must_equal 'hanami'
# end # end
it 'returns an capitalized string' do it 'returns an capitalized string' do
Lotus::Utils::String.new('lotus').capitalize.must_equal 'Lotus' Hanami::Utils::String.new('hanami').capitalize.must_equal 'Hanami'
Lotus::Utils::String.new('LotusUtils').capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new('HanamiUtils').capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new('lotus utils').capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new('hanami utils').capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new('lotus_utils').capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new('hanami_utils').capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new('lotus-utils').capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new('hanami-utils').capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new("lotus' utils").capitalize.must_equal "Lotus' utils" Hanami::Utils::String.new("hanami' utils").capitalize.must_equal "Hanami' utils"
Lotus::Utils::String.new("lotus utils").capitalize.must_equal "Lotus utils" Hanami::Utils::String.new("hanami utils").capitalize.must_equal "Hanami utils"
Lotus::Utils::String.new("lotus` utils").capitalize.must_equal "Lotus` utils" Hanami::Utils::String.new("hanami` utils").capitalize.must_equal "Hanami` utils"
# Ruby's upcase works only with ASCII chars. # Ruby's upcase works only with ASCII chars.
# Lotus::Utils::String.new("è vero?").capitalize.must_equal "È vero?" # Hanami::Utils::String.new("è vero?").capitalize.must_equal "È vero?"
Lotus::Utils::String.new('OneTwoThree').capitalize.must_equal 'One two three' Hanami::Utils::String.new('OneTwoThree').capitalize.must_equal 'One two three'
Lotus::Utils::String.new('one Two three').capitalize.must_equal 'One two three' Hanami::Utils::String.new('one Two three').capitalize.must_equal 'One two three'
Lotus::Utils::String.new('one_two_three').capitalize.must_equal 'One two three' Hanami::Utils::String.new('one_two_three').capitalize.must_equal 'One two three'
Lotus::Utils::String.new('one-two-three').capitalize.must_equal 'One two three' Hanami::Utils::String.new('one-two-three').capitalize.must_equal 'One two three'
Lotus::Utils::String.new(:LotusUtils).capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new(:HanamiUtils).capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new(:'lotus utils').capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new(:'hanami utils').capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new(:lotus_utils).capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new(:hanami_utils).capitalize.must_equal 'Hanami utils'
Lotus::Utils::String.new(:'lotus-utils').capitalize.must_equal 'Lotus utils' Hanami::Utils::String.new(:'hanami-utils').capitalize.must_equal 'Hanami utils'
end end
end end
describe '#classify' do describe '#classify' do
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
Lotus::Utils::String.new('lotus').classify.must_be_kind_of(Lotus::Utils::String) Hanami::Utils::String.new('hanami').classify.must_be_kind_of(Hanami::Utils::String)
end end
it 'returns a classified string' do it 'returns a classified string' do
Lotus::Utils::String.new('lotus').classify.must_equal('Lotus') Hanami::Utils::String.new('hanami').classify.must_equal('Hanami')
Lotus::Utils::String.new('lotus_router').classify.must_equal('LotusRouter') Hanami::Utils::String.new('hanami_router').classify.must_equal('HanamiRouter')
Lotus::Utils::String.new('lotus-router').classify.must_equal('Lotus::Router') Hanami::Utils::String.new('hanami-router').classify.must_equal('Hanami::Router')
Lotus::Utils::String.new('lotus/router').classify.must_equal('Lotus::Router') Hanami::Utils::String.new('hanami/router').classify.must_equal('Hanami::Router')
Lotus::Utils::String.new('lotus::router').classify.must_equal('Lotus::Router') Hanami::Utils::String.new('hanami::router').classify.must_equal('Hanami::Router')
Lotus::Utils::String.new('lotus::router/base_object').classify.must_equal('Lotus::Router::BaseObject') Hanami::Utils::String.new('hanami::router/base_object').classify.must_equal('Hanami::Router::BaseObject')
end end
it 'returns a classified string from symbol' do it 'returns a classified string from symbol' do
Lotus::Utils::String.new(:lotus).classify.must_equal('Lotus') Hanami::Utils::String.new(:hanami).classify.must_equal('Hanami')
Lotus::Utils::String.new(:lotus_router).classify.must_equal('LotusRouter') Hanami::Utils::String.new(:hanami_router).classify.must_equal('HanamiRouter')
Lotus::Utils::String.new(:'lotus-router').classify.must_equal('Lotus::Router') Hanami::Utils::String.new(:'hanami-router').classify.must_equal('Hanami::Router')
Lotus::Utils::String.new(:'lotus/router').classify.must_equal('Lotus::Router') Hanami::Utils::String.new(:'hanami/router').classify.must_equal('Hanami::Router')
Lotus::Utils::String.new(:'lotus::router').classify.must_equal('Lotus::Router') Hanami::Utils::String.new(:'hanami::router').classify.must_equal('Hanami::Router')
end end
end end
describe '#underscore' do describe '#underscore' do
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
Lotus::Utils::String.new('Lotus').underscore.must_be_kind_of(Lotus::Utils::String) Hanami::Utils::String.new('Hanami').underscore.must_be_kind_of(Hanami::Utils::String)
end end
it "doesn't mutate self" do it "doesn't mutate self" do
string = Lotus::Utils::String.new('Lotus') string = Hanami::Utils::String.new('Hanami')
string.underscore string.underscore
string.must_equal 'Lotus' string.must_equal 'Hanami'
end end
it 'removes all the upcase characters' do it 'removes all the upcase characters' do
string = Lotus::Utils::String.new('Lotus') string = Hanami::Utils::String.new('Hanami')
string.underscore.must_equal 'lotus' string.underscore.must_equal 'hanami'
end end
it 'transforms camel case class names' do it 'transforms camel case class names' do
string = Lotus::Utils::String.new('LotusView') string = Hanami::Utils::String.new('HanamiView')
string.underscore.must_equal 'lotus_view' string.underscore.must_equal 'hanami_view'
end end
it 'substitutes double colons with path separators' do it 'substitutes double colons with path separators' do
string = Lotus::Utils::String.new('Lotus::Utils::String') string = Hanami::Utils::String.new('Hanami::Utils::String')
string.underscore.must_equal 'lotus/utils/string' string.underscore.must_equal 'hanami/utils/string'
end end
it 'handles acronyms' do it 'handles acronyms' do
string = Lotus::Utils::String.new('APIDoc') string = Hanami::Utils::String.new('APIDoc')
string.underscore.must_equal 'api_doc' string.underscore.must_equal 'api_doc'
end end
it 'handles numbers' do it 'handles numbers' do
string = Lotus::Utils::String.new('Lucky23Action') string = Hanami::Utils::String.new('Lucky23Action')
string.underscore.must_equal 'lucky23_action' string.underscore.must_equal 'lucky23_action'
end end
it 'handles dashes' do it 'handles dashes' do
string = Lotus::Utils::String.new('lotus-utils') string = Hanami::Utils::String.new('hanami-utils')
string.underscore.must_equal 'lotus_utils' string.underscore.must_equal 'hanami_utils'
end end
it 'handles spaces' do it 'handles spaces' do
string = Lotus::Utils::String.new('Lotus Utils') string = Hanami::Utils::String.new('Hanami Utils')
string.underscore.must_equal 'lotus_utils' string.underscore.must_equal 'hanami_utils'
end end
it 'handles accented letters' do it 'handles accented letters' do
string = Lotus::Utils::String.new('è vero') string = Hanami::Utils::String.new('è vero')
string.underscore.must_equal 'è_vero' string.underscore.must_equal 'è_vero'
end end
end end
describe '#dasherize' do describe '#dasherize' do
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
Lotus::Utils::String.new('Lotus').dasherize.must_be_kind_of(Lotus::Utils::String) Hanami::Utils::String.new('Hanami').dasherize.must_be_kind_of(Hanami::Utils::String)
end end
it "doesn't mutate self" do it "doesn't mutate self" do
string = Lotus::Utils::String.new('Lotus') string = Hanami::Utils::String.new('Hanami')
string.dasherize string.dasherize
string.must_equal 'Lotus' string.must_equal 'Hanami'
end end
it 'removes all the upcase characters' do it 'removes all the upcase characters' do
string = Lotus::Utils::String.new('Lotus') string = Hanami::Utils::String.new('Hanami')
string.dasherize.must_equal 'lotus' string.dasherize.must_equal 'hanami'
end end
it 'transforms camel case class names' do it 'transforms camel case class names' do
string = Lotus::Utils::String.new('LotusView') string = Hanami::Utils::String.new('HanamiView')
string.dasherize.must_equal 'lotus-view' string.dasherize.must_equal 'hanami-view'
end end
it 'handles acronyms' do it 'handles acronyms' do
string = Lotus::Utils::String.new('APIDoc') string = Hanami::Utils::String.new('APIDoc')
string.dasherize.must_equal 'api-doc' string.dasherize.must_equal 'api-doc'
end end
it 'handles numbers' do it 'handles numbers' do
string = Lotus::Utils::String.new('Lucky23Action') string = Hanami::Utils::String.new('Lucky23Action')
string.dasherize.must_equal 'lucky23-action' string.dasherize.must_equal 'lucky23-action'
end end
it 'handles underscores' do it 'handles underscores' do
string = Lotus::Utils::String.new('lotus_utils') string = Hanami::Utils::String.new('hanami_utils')
string.dasherize.must_equal 'lotus-utils' string.dasherize.must_equal 'hanami-utils'
end end
it 'handles spaces' do it 'handles spaces' do
string = Lotus::Utils::String.new('Lotus Utils') string = Hanami::Utils::String.new('Hanami Utils')
string.dasherize.must_equal 'lotus-utils' string.dasherize.must_equal 'hanami-utils'
end end
it 'handles accented letters' do it 'handles accented letters' do
string = Lotus::Utils::String.new('è vero') string = Hanami::Utils::String.new('è vero')
string.dasherize.must_equal 'è-vero' string.dasherize.must_equal 'è-vero'
end end
end end
describe '#demodulize' do describe '#demodulize' do
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
Lotus::Utils::String.new('Lotus').demodulize.must_be_kind_of(Lotus::Utils::String) Hanami::Utils::String.new('Hanami').demodulize.must_be_kind_of(Hanami::Utils::String)
end end
it 'returns the class name without the namespace' do it 'returns the class name without the namespace' do
Lotus::Utils::String.new('String').demodulize.must_equal('String') Hanami::Utils::String.new('String').demodulize.must_equal('String')
Lotus::Utils::String.new('Lotus::Utils::String').demodulize.must_equal('String') Hanami::Utils::String.new('Hanami::Utils::String').demodulize.must_equal('String')
end end
end end
describe '#namespace' do describe '#namespace' do
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
Lotus::Utils::String.new('Lotus').namespace.must_be_kind_of(Lotus::Utils::String) Hanami::Utils::String.new('Hanami').namespace.must_be_kind_of(Hanami::Utils::String)
end end
it 'returns the top level module name' do it 'returns the top level module name' do
Lotus::Utils::String.new('String').namespace.must_equal('String') Hanami::Utils::String.new('String').namespace.must_equal('String')
Lotus::Utils::String.new('Lotus::Utils::String').namespace.must_equal('Lotus') Hanami::Utils::String.new('Hanami::Utils::String').namespace.must_equal('Hanami')
end end
end end
@ -211,37 +211,37 @@ describe Lotus::Utils::String do
@logger = [] @logger = []
end end
it 'returns an instance of Lotus::Utils::String' do it 'returns an instance of Hanami::Utils::String' do
string = Lotus::Utils::String.new('Lotus::(Utils|App)') string = Hanami::Utils::String.new('Hanami::(Utils|App)')
string.tokenize do |token| string.tokenize do |token|
@logger.push token @logger.push token
end end
@logger.each do |token| @logger.each do |token|
token.must_be_kind_of(Lotus::Utils::String) token.must_be_kind_of(Hanami::Utils::String)
end end
end end
it 'calls the given block for each token occurrence' do it 'calls the given block for each token occurrence' do
string = Lotus::Utils::String.new('Lotus::(Utils|App)') string = Hanami::Utils::String.new('Hanami::(Utils|App)')
string.tokenize do |token| string.tokenize do |token|
@logger.push token @logger.push token
end end
@logger.must_equal(['Lotus::Utils', 'Lotus::App']) @logger.must_equal(['Hanami::Utils', 'Hanami::App'])
end end
it "guarantees the block to be called even when the token conditions aren't met" do it "guarantees the block to be called even when the token conditions aren't met" do
string = Lotus::Utils::String.new('Lotus') string = Hanami::Utils::String.new('Hanami')
string.tokenize do |token| string.tokenize do |token|
@logger.push token @logger.push token
end end
@logger.must_equal(['Lotus']) @logger.must_equal(['Hanami'])
end end
it 'returns nil' do it 'returns nil' do
result = Lotus::Utils::String.new('Lotus::(Utils|App)').tokenize { } result = Hanami::Utils::String.new('Hanami::(Utils|App)').tokenize { }
result.must_be_nil result.must_be_nil
end end
end end
@ -251,18 +251,18 @@ describe Lotus::Utils::String do
@singular, @plural = *TEST_PLURALS.to_a.sample @singular, @plural = *TEST_PLURALS.to_a.sample
end end
it 'returns a Lotus::Utils::String instance' do it 'returns a Hanami::Utils::String instance' do
result = Lotus::Utils::String.new(@singular).pluralize result = Hanami::Utils::String.new(@singular).pluralize
result.must_be_kind_of(Lotus::Utils::String) result.must_be_kind_of(Hanami::Utils::String)
end end
it 'pluralizes string' do it 'pluralizes string' do
result = Lotus::Utils::String.new(@singular).pluralize result = Hanami::Utils::String.new(@singular).pluralize
result.must_equal(@plural) result.must_equal(@plural)
end end
it "doesn't modify the original string" do it "doesn't modify the original string" do
string = Lotus::Utils::String.new(@singular) string = Hanami::Utils::String.new(@singular)
string.pluralize.must_equal(@plural) string.pluralize.must_equal(@plural)
string.must_equal(@singular) string.must_equal(@singular)
@ -270,55 +270,55 @@ describe Lotus::Utils::String do
end end
describe "#rsub" do describe "#rsub" do
it 'returns a Lotus::Utils::String instance' do it 'returns a Hanami::Utils::String instance' do
result = Lotus::Utils::String.new('authors/books/index').rsub(//, '') result = Hanami::Utils::String.new('authors/books/index').rsub(//, '')
result.must_be_kind_of(Lotus::Utils::String) result.must_be_kind_of(Hanami::Utils::String)
end end
it "doesn't mutate original string" do it "doesn't mutate original string" do
string = Lotus::Utils::String.new('authors/books/index') string = Hanami::Utils::String.new('authors/books/index')
string.rsub(/\//, '#') string.rsub(/\//, '#')
string.must_equal('authors/books/index') string.must_equal('authors/books/index')
end end
it 'replaces rightmost instance (regexp)' do it 'replaces rightmost instance (regexp)' do
result = Lotus::Utils::String.new('authors/books/index').rsub(/\//, '#') result = Hanami::Utils::String.new('authors/books/index').rsub(/\//, '#')
result.must_equal('authors/books#index') result.must_equal('authors/books#index')
end end
it 'replaces rightmost instance (string)' do it 'replaces rightmost instance (string)' do
result = Lotus::Utils::String.new('authors/books/index').rsub('/', '#') result = Hanami::Utils::String.new('authors/books/index').rsub('/', '#')
result.must_equal('authors/books#index') result.must_equal('authors/books#index')
end end
it 'accepts Lotus::Utils::String as replacement' do it 'accepts Hanami::Utils::String as replacement' do
replacement = Lotus::Utils::String.new('#') replacement = Hanami::Utils::String.new('#')
result = Lotus::Utils::String.new('authors/books/index').rsub(/\//, replacement) result = Hanami::Utils::String.new('authors/books/index').rsub(/\//, replacement)
result.must_equal('authors/books#index') result.must_equal('authors/books#index')
end end
it 'returns the initial string no match' do it 'returns the initial string no match' do
result = Lotus::Utils::String.new('index').rsub(/\//, '#') result = Hanami::Utils::String.new('index').rsub(/\//, '#')
result.must_equal('index') result.must_equal('index')
end end
end end
describe 'string interface' do describe 'string interface' do
it 'responds to ::String methods and returns a new Lotus::Utils::String' do it 'responds to ::String methods and returns a new Hanami::Utils::String' do
string = Lotus::Utils::String.new("Lotus\n").chomp string = Hanami::Utils::String.new("Hanami\n").chomp
string.must_equal 'Lotus' string.must_equal 'Hanami'
string.must_be_kind_of Lotus::Utils::String string.must_be_kind_of Hanami::Utils::String
end end
it 'responds to ::String methods and only returns a new Lotus::Utils::String when the return value is a string' do it 'responds to ::String methods and only returns a new Hanami::Utils::String when the return value is a string' do
string = Lotus::Utils::String.new('abcdef') string = Hanami::Utils::String.new('abcdef')
string.casecmp('abcde').must_equal 1 string.casecmp('abcde').must_equal 1
end end
it 'responds to whatever ::String responds to' do it 'responds to whatever ::String responds to' do
string = Lotus::Utils::String.new('abcdef') string = Hanami::Utils::String.new('abcdef')
string.must_respond_to :reverse string.must_respond_to :reverse
string.wont_respond_to :unknown_method string.wont_respond_to :unknown_method
@ -326,60 +326,60 @@ describe Lotus::Utils::String do
describe 'equality' do describe 'equality' do
it 'has a working equality' do it 'has a working equality' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
other = Lotus::Utils::String.new('lotus') other = Hanami::Utils::String.new('hanami')
assert string == other assert string == other
end end
it 'has a working equality with raw strings' do it 'has a working equality with raw strings' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
assert string == 'lotus' assert string == 'hanami'
end end
end end
describe 'case equality' do describe 'case equality' do
it 'has a working case equality' do it 'has a working case equality' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
other = Lotus::Utils::String.new('lotus') other = Hanami::Utils::String.new('hanami')
assert string === other assert string === other
end end
it 'has a working case equality with raw strings' do it 'has a working case equality with raw strings' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
assert string === 'lotus' assert string === 'hanami'
end end
end end
describe 'value equality' do describe 'value equality' do
it 'has a working value equality' do it 'has a working value equality' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
other = Lotus::Utils::String.new('lotus') other = Hanami::Utils::String.new('hanami')
assert string.eql?(other) assert string.eql?(other)
end end
it 'has a working value equality with raw strings' do it 'has a working value equality with raw strings' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
assert string.eql?('lotus') assert string.eql?('hanami')
end end
end end
describe 'identity equality' do describe 'identity equality' do
it 'has a working identity equality' do it 'has a working identity equality' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
assert string.equal?(string) assert string.equal?(string)
end end
it 'has a working identity equality with raw strings' do it 'has a working identity equality with raw strings' do
string = Lotus::Utils::String.new('lotus') string = Hanami::Utils::String.new('hanami')
assert !string.equal?('lotus') assert !string.equal?('hanami')
end end
end end
describe '#hash' do describe '#hash' do
it 'returns the same hash result of ::String' do it 'returns the same hash result of ::String' do
expected = 'hello'.hash expected = 'hello'.hash
actual = Lotus::Utils::String.new('hello').hash actual = Hanami::Utils::String.new('hello').hash
actual.must_equal expected actual.must_equal expected
end end
@ -389,16 +389,16 @@ describe Lotus::Utils::String do
describe 'unknown method' do describe 'unknown method' do
it 'raises error' do it 'raises error' do
begin begin
Lotus::Utils::String.new('one').yay! Hanami::Utils::String.new('one').yay!
rescue NoMethodError => e rescue NoMethodError => e
e.message.must_equal %(undefined method `yay!' for "one":Lotus::Utils::String) e.message.must_equal %(undefined method `yay!' for "one":Hanami::Utils::String)
end end
end end
# See: https://github.com/lotus/utils/issues/48 # See: https://github.com/hanami/utils/issues/48
it 'returns the correct object when a NoMethodError is raised' do it 'returns the correct object when a NoMethodError is raised' do
string = Lotus::Utils::String.new('/path/to/something') string = Hanami::Utils::String.new('/path/to/something')
exception_message = if Lotus::Utils.rubinius? exception_message = if Hanami::Utils.rubinius?
%(undefined method `boom' on an instance of String.) %(undefined method `boom' on an instance of String.)
else # MRI else # MRI
%(undefined method `boom' for "/":String) %(undefined method `boom' for "/":String)

View File

@ -1,13 +1,13 @@
require 'test_helper' require 'test_helper'
require 'lotus/utils' require 'hanami/utils'
describe Lotus::Utils do describe Hanami::Utils do
describe '.jruby?' do describe '.jruby?' do
it 'introspects the current platform' do it 'introspects the current platform' do
if RUBY_PLATFORM == 'java' if RUBY_PLATFORM == 'java'
assert Lotus::Utils.jruby?, 'expected JRuby platform' assert Hanami::Utils.jruby?, 'expected JRuby platform'
else else
assert !Lotus::Utils.jruby?, 'expected non JRuby platform' assert !Hanami::Utils.jruby?, 'expected non JRuby platform'
end end
end end
end end
@ -15,9 +15,9 @@ describe Lotus::Utils do
describe '.rubinius?' do describe '.rubinius?' do
it 'introspects the current platform' do it 'introspects the current platform' do
if RUBY_ENGINE == 'rbx' if RUBY_ENGINE == 'rbx'
assert Lotus::Utils.rubinius?, 'expected Rubinius platform' assert Hanami::Utils.rubinius?, 'expected Rubinius platform'
else else
assert !Lotus::Utils.rubinius?, 'expected non Rubinius platform' assert !Hanami::Utils.rubinius?, 'expected non Rubinius platform'
end end
end end
end end

View File

@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
describe Lotus::Utils::VERSION do describe Hanami::Utils::VERSION do
it 'exposes version' do it 'exposes version' do
Lotus::Utils::VERSION.must_equal '0.6.1' Hanami::Utils::VERSION.must_equal '0.7.0'
end end
end end