Lotus => Hanami
This commit is contained in:
parent
85d16fe52b
commit
404f01fa4e
19
.travis.yml
19
.travis.yml
|
@ -3,24 +3,9 @@ sudo: false
|
|||
cache: bundler
|
||||
script: 'bundle exec rake test:coverage --trace'
|
||||
rvm:
|
||||
- 2.0.0
|
||||
- 2.1.0
|
||||
- 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
|
||||
- 2.2
|
||||
- 2.3
|
||||
- jruby-9000
|
||||
- rbx-2
|
||||
- ruby-head
|
||||
- jruby-head
|
||||
|
||||
|
|
106
CHANGELOG.md
106
CHANGELOG.md
|
@ -1,76 +1,76 @@
|
|||
# Lotus::Utils
|
||||
Ruby core extentions and class utilities for Lotus
|
||||
# Hanami::Utils
|
||||
Ruby core extentions and class utilities for Hanami
|
||||
|
||||
## v0.6.1 - 2016-01-19
|
||||
### 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
|
||||
### Added
|
||||
- [Luca Guidi] Official support for Ruby 2.3
|
||||
- [Luca Guidi] Custom inflections
|
||||
- [Luca Guidi] Introduced `Lotus::Utils::Duplicable` as a safe dup logic for Ruby types
|
||||
- [Luca Guidi] Added `Lotus::Utils::String#rsub` replace rightmost occurrence
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::Duplicable` as a safe dup logic for Ruby types
|
||||
- [Luca Guidi] Added `Hanami::Utils::String#rsub` replace rightmost occurrence
|
||||
|
||||
### Fixed
|
||||
- [Luca Guidi] Fix `Lotus::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`
|
||||
- [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 `Hanami::Utils::Escape.encode`
|
||||
|
||||
### Changed
|
||||
- [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)`)
|
||||
|
||||
## v0.5.2 - 2015-09-30
|
||||
### Added
|
||||
- [Luca Guidi] Added `Lotus::Utils::String#capitalize`
|
||||
- [Luca Guidi] Added `Hanami::Utils::String#capitalize`
|
||||
- [Trung Lê] Official support for JRuby 9k+
|
||||
|
||||
## v0.5.1 - 2015-07-10
|
||||
### 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
|
||||
### Added
|
||||
- [Luca Guidi] Extracted `Lotus::Logger` from `lotusrb`
|
||||
- [Luca Guidi] Extracted `Hanami::Logger` from `hanamirb`
|
||||
|
||||
### 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
|
||||
### 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
|
||||
### 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
|
||||
### 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
|
||||
- [Luca Guidi] Ensure `Lotus::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] Ensure `Hanami::Utils::Attributes#to_h` to safely return nested `::Hash` instances for complex data structures.
|
||||
- [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
|
||||
### Added
|
||||
- [Luca Guidi] Introduced `Lotus::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 `Lotus::Utils::String#titleize`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::Escape`. It implements OWASP/ESAPI suggestions for HTML, HTML attribute and URL escape utilities.
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::String#dasherize`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::String#titleize`
|
||||
|
||||
## v0.3.5 - 2015-03-12
|
||||
### Added
|
||||
- [Luca Guidi] Introduced `Lotus::Interactor`
|
||||
- [Luca Guidi] Introduced `Lotus::Utils::BasicObject`
|
||||
- [Luca Guidi] Introduced `Hanami::Interactor`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::BasicObject`
|
||||
|
||||
## v0.3.4 - 2015-01-30
|
||||
### Added
|
||||
- [Alfonso Uceda Pompa] Aliased `Lotus::Utils::Attributes#get` with `#[]`
|
||||
- [Simone Carletti] Introduced `Lotus::Utils::Callbacks::Chain#prepend` and `#append`
|
||||
- [Alfonso Uceda Pompa] Aliased `Hanami::Utils::Attributes#get` with `#[]`
|
||||
- [Simone Carletti] Introduced `Hanami::Utils::Callbacks::Chain#prepend` and `#append`
|
||||
|
||||
### 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
|
||||
### Fixed
|
||||
|
@ -106,37 +106,37 @@ Ruby core extentions and class utilities for Lotus
|
|||
|
||||
## v0.3.0 - 2014-10-23
|
||||
### 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] Use composition over inheritance for `Lotus::Utils::PathPrefix`
|
||||
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::Hash`
|
||||
- [Luca Guidi] Use composition over inheritance for `Lotus::Utils::String`
|
||||
- [Luca Guidi] Use composition over inheritance for `Hanami::Utils::PathPrefix`
|
||||
- [Luca Guidi] Use composition over inheritance for `Hanami::Utils::Hash`
|
||||
- [Luca Guidi] Use composition over inheritance for `Hanami::Utils::String`
|
||||
|
||||
### Fixed
|
||||
- [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!`
|
||||
- [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`
|
||||
- [Peter Suschlik] Define `Lotus::Utils::Hash#respond_to_missing?`
|
||||
- [Peter Suschlik] Define `Lotus::Utils::String#responds_to_missing?`
|
||||
- [Peter Suschlik] Define `Hanami::Utils::Hash#respond_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`
|
||||
|
||||
## v0.2.0 - 2014-06-23
|
||||
### 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] Implemented `Lotus::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] Use composition over inheritance for `Lotus::Utils::LoadPaths`
|
||||
- [Luca Guidi] Introduced `Lotus::Utils::LoadPaths`
|
||||
- [Luca Guidi] Introduced `Lotus::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::LoadPaths#freeze` in order to prevent modification after the object has been frozen
|
||||
- [Luca Guidi] Implemented Hanami::Utils::LoadPaths#push, also aliased as #<<
|
||||
- [Luca Guidi] Use composition over inheritance for `Hanami::Utils::LoadPaths`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::LoadPaths`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::String#namespace`, in order to return the top level Ruby namespace for the given string
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Pathname`
|
||||
|
||||
### 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
|
||||
- [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] 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
|
||||
|
@ -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.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] 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
|
||||
### Added
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Time`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.DateTime`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Date`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Float`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Boolean`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Hash`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Set`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.String`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Integer`
|
||||
- [Luca Guidi] Implemented `Lotus::Utils::Kernel.Array`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Time`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.DateTime`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Date`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Float`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Boolean`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Hash`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Set`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.String`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Integer`
|
||||
- [Luca Guidi] Implemented `Hanami::Utils::Kernel.Array`
|
||||
|
||||
### Fixed
|
||||
- [Christopher Keele] Add missing stdlib `Set` require to `Utils::ClassAttribute`
|
||||
|
||||
## v0.1.0 - 2014-01-23
|
||||
### Added
|
||||
- [Luca Guidi] Introduced `Lotus::Utils::String#demodulize`
|
||||
- [Luca Guidi] Introduced `Lotus::Utils::IO.silence_warnings`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::String#demodulize`
|
||||
- [Luca Guidi] Introduced `Hanami::Utils::IO.silence_warnings`
|
||||
- [Luca Guidi] Introduced class loading mechanism from a string: `Utils::Class.load!`
|
||||
- [Luca Guidi] Introduced callbacks support for classes
|
||||
- [Luca Guidi] Introduced inheritable class level attributes
|
||||
|
|
|
@ -17,7 +17,7 @@ Here are some ways *you* can contribute:
|
|||
* by closing [issues][]
|
||||
* by reviewing patches
|
||||
|
||||
[issues]: https://github.com/lotus/utils/issues
|
||||
[issues]: https://github.com/hanami/utils/issues
|
||||
|
||||
## Submitting an Issue
|
||||
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
||||
|
|
110
README.md
110
README.md
|
@ -1,36 +1,35 @@
|
|||
# Hanami::Utils
|
||||
|
||||
# Lotus::Utils
|
||||
|
||||
Ruby core extentions and class utilities for [Lotus](http://lotusrb.org)
|
||||
Ruby core extentions and class utilities for [Hanami](http://hanamirb.org)
|
||||
|
||||
## Status
|
||||
|
||||
[![Gem Version](http://img.shields.io/gem/v/lotus-utils.svg)](https://badge.fury.io/rb/lotus-utils)
|
||||
[![Build Status](http://img.shields.io/travis/lotus/utils/master.svg)](https://travis-ci.org/lotus/utils?branch=master)
|
||||
[![Coverage](http://img.shields.io/coveralls/lotus/utils/master.svg)](https://coveralls.io/r/lotus/utils)
|
||||
[![Code Climate](http://img.shields.io/codeclimate/github/lotus/utils.svg)](https://codeclimate.com/github/lotus/utils)
|
||||
[![Dependencies](http://img.shields.io/gemnasium/lotus/utils.svg)](https://gemnasium.com/lotus/utils)
|
||||
[![Inline Docs](http://inch-ci.org/github/lotus/utils.svg)](http://inch-ci.org/github/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/hanami/utils/master.svg)](https://travis-ci.org/hanami/utils?branch=master)
|
||||
[![Coverage](http://img.shields.io/coveralls/hanami/utils/master.svg)](https://coveralls.io/r/hanami/utils)
|
||||
[![Code Climate](http://img.shields.io/codeclimate/github/hanami/utils.svg)](https://codeclimate.com/github/hanami/utils)
|
||||
[![Dependencies](http://img.shields.io/gemnasium/hanami/utils.svg)](https://gemnasium.com/hanami/utils)
|
||||
[![Inline Docs](http://inch-ci.org/github/hanami/utils.svg)](http://inch-ci.org/github/hanami/utils)
|
||||
|
||||
## Contact
|
||||
|
||||
* Home page: http://lotusrb.org
|
||||
* Mailing List: http://lotusrb.org/mailing-list
|
||||
* API Doc: http://rdoc.info/gems/lotus-utils
|
||||
* Bugs/Issues: https://github.com/lotus/utils/issues
|
||||
* Support: http://stackoverflow.com/questions/tagged/lotus-ruby
|
||||
* Chat: https://gitter.im/lotus/chat
|
||||
* Home page: http://hanamirb.org
|
||||
* Mailing List: http://hanamirb.org/mailing-list
|
||||
* API Doc: http://rdoc.info/gems/hanami-utils
|
||||
* Bugs/Issues: https://github.com/hanami/utils/issues
|
||||
* Support: http://stackoverflow.com/questions/tagged/hanami
|
||||
* Chat: http://chat.hanamirb.org
|
||||
|
||||
## Rubies
|
||||
|
||||
__Lotus::Utils__ supports Ruby (MRI) 2+, JRuby 9k+ & Rubinius 2.3+
|
||||
__Hanami::Utils__ supports Ruby (MRI) 2+, JRuby 9k+ & Rubinius 2.3+
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'lotus-utils'
|
||||
gem 'hanami-utils'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
|
@ -39,91 +38,91 @@ And then execute:
|
|||
|
||||
Or install it yourself as:
|
||||
|
||||
$ gem install lotus-utils
|
||||
$ gem install hanami-utils
|
||||
|
||||
## 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.**
|
||||
|
||||
## 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
|
||||
|
||||
__Lotus::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
||||
__Hanami::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
||||
|
||||
## 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`)
|
||||
3. Commit your changes (`git commit -am 'Add some 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 © 2014-2016 Luca Guidi – Released under MIT License
|
||||
This project was formerly known as Lotus (`lotus-utils`).
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'lotus/utils/version'
|
||||
require 'hanami/utils/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = 'lotus-utils'
|
||||
spec.version = Lotus::Utils::VERSION
|
||||
spec.name = 'hanami-utils'
|
||||
spec.version = Hanami::Utils::VERSION
|
||||
spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda']
|
||||
spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com']
|
||||
spec.description = %q{Lotus utilities}
|
||||
spec.summary = %q{Ruby core extentions and Lotus utilities}
|
||||
spec.homepage = 'http://lotusrb.org'
|
||||
spec.description = %q{Hanami utilities}
|
||||
spec.summary = %q{Ruby core extentions and Hanami utilities}
|
||||
spec.homepage = 'http://hanamirb.org'
|
||||
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.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||
spec.require_paths = ['lib']
|
|
@ -0,0 +1 @@
|
|||
require 'hanami/utils'
|
|
@ -1,9 +1,9 @@
|
|||
require 'lotus/utils/basic_object'
|
||||
require 'lotus/utils/class_attribute'
|
||||
require 'lotus/utils/hash'
|
||||
require 'hanami/utils/basic_object'
|
||||
require 'hanami/utils/class_attribute'
|
||||
require 'hanami/utils/hash'
|
||||
|
||||
module Lotus
|
||||
# Lotus Interactor
|
||||
module Hanami
|
||||
# Hanami Interactor
|
||||
#
|
||||
# @since 0.3.5
|
||||
module Interactor
|
||||
|
@ -16,14 +16,14 @@ module Lotus
|
|||
# @since 0.3.5
|
||||
# @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
|
||||
|
||||
# Initialize a new result
|
||||
#
|
||||
# @param payload [Hash] a payload to carry on
|
||||
#
|
||||
# @return [Lotus::Interactor::Result]
|
||||
# @return [Hanami::Interactor::Result]
|
||||
#
|
||||
# @since 0.3.5
|
||||
# @api private
|
||||
|
@ -55,10 +55,10 @@ module Lotus
|
|||
#
|
||||
# @since 0.3.5
|
||||
#
|
||||
# @see Lotus::Interactor::Result#error
|
||||
# @see Lotus::Interactor#call
|
||||
# @see Lotus::Interactor#error
|
||||
# @see Lotus::Interactor#error!
|
||||
# @see Hanami::Interactor::Result#error
|
||||
# @see Hanami::Interactor#call
|
||||
# @see Hanami::Interactor#error
|
||||
# @see Hanami::Interactor#error!
|
||||
def errors
|
||||
@errors.dup
|
||||
end
|
||||
|
@ -77,10 +77,10 @@ module Lotus
|
|||
#
|
||||
# @since 0.3.5
|
||||
#
|
||||
# @see Lotus::Interactor::Result#errors
|
||||
# @see Lotus::Interactor#call
|
||||
# @see Lotus::Interactor#error
|
||||
# @see Lotus::Interactor#error!
|
||||
# @see Hanami::Interactor::Result#errors
|
||||
# @see Hanami::Interactor#call
|
||||
# @see Hanami::Interactor#error
|
||||
# @see Hanami::Interactor#error!
|
||||
def error
|
||||
errors.first
|
||||
end
|
||||
|
@ -147,15 +147,15 @@ module Lotus
|
|||
#
|
||||
# @param args [Array<Object>] arbitrary number of arguments
|
||||
#
|
||||
# @return [Lotus::Interactor] the interactor
|
||||
# @return [Hanami::Interactor] the interactor
|
||||
#
|
||||
# @since 0.3.5
|
||||
#
|
||||
# @example Override #initialize
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class UpdateProfile
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
#
|
||||
# def initialize(user, params)
|
||||
# @user = user
|
||||
|
@ -169,7 +169,7 @@ module Lotus
|
|||
def initialize(*args)
|
||||
super
|
||||
ensure
|
||||
@__result = ::Lotus::Interactor::Result.new
|
||||
@__result = ::Hanami::Interactor::Result.new
|
||||
end
|
||||
|
||||
# Triggers the operation and return a result.
|
||||
|
@ -178,15 +178,15 @@ module Lotus
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
# @example Expose instance variables in result payload
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class Signup
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
# expose :user, :params
|
||||
#
|
||||
# def initialize(params)
|
||||
|
@ -208,10 +208,10 @@ module Lotus
|
|||
# result.foo # => raises NoMethodError
|
||||
#
|
||||
# @example Failed precondition
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class Signup
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
# expose :user
|
||||
#
|
||||
# def initialize(params)
|
||||
|
@ -236,10 +236,10 @@ module Lotus
|
|||
# result.user # => #<User:0x007fa311105778 @id=nil @name="Luca">
|
||||
#
|
||||
# @example Bad usage
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class Signup
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
#
|
||||
# # Method #call is not defined
|
||||
# end
|
||||
|
@ -268,10 +268,10 @@ module Lotus
|
|||
# @since 0.3.5
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class CreateEmailTest
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
#
|
||||
# def initialize(params)
|
||||
# @params = params
|
||||
|
@ -313,13 +313,13 @@ module Lotus
|
|||
#
|
||||
# @since 0.3.5
|
||||
#
|
||||
# @see Lotus::Interactor#error!
|
||||
# @see Hanami::Interactor#error!
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class CreateRecord
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
# expose :logger
|
||||
#
|
||||
# def initialize
|
||||
|
@ -366,13 +366,13 @@ module Lotus
|
|||
#
|
||||
# @since 0.3.5
|
||||
#
|
||||
# @see Lotus::Interactor#error
|
||||
# @see Hanami::Interactor#error
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/interactor'
|
||||
# require 'hanami/interactor'
|
||||
#
|
||||
# class CreateRecord
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
# expose :logger
|
||||
#
|
||||
# def initialize
|
||||
|
@ -466,12 +466,12 @@ module Lotus
|
|||
#
|
||||
# @since 0.5.0
|
||||
#
|
||||
# @see Lotus::Interactor::Result
|
||||
# @see Hanami::Interactor::Result
|
||||
#
|
||||
# @example Expose instance variable
|
||||
#
|
||||
# class Signup
|
||||
# include Lotus::Interactor
|
||||
# include Hanami::Interactor
|
||||
# expose :user
|
||||
#
|
||||
# def initialize(params)
|
|
@ -1,20 +1,20 @@
|
|||
require 'logger'
|
||||
require 'lotus/utils/string'
|
||||
require 'hanami/utils/string'
|
||||
|
||||
module Lotus
|
||||
# Lotus logger
|
||||
module Hanami
|
||||
# Hanami logger
|
||||
#
|
||||
# Implement with the same interface of Ruby std lib `Logger`.
|
||||
# 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.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# @example Basic usage
|
||||
# require 'lotus'
|
||||
# require 'hanami'
|
||||
#
|
||||
# module Bookshelf
|
||||
# class Application < Lotus::Application
|
||||
# class Application < Hanami::Application
|
||||
# end
|
||||
# end
|
||||
#
|
||||
|
@ -54,21 +54,21 @@ module Lotus
|
|||
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Bookshelf] : Hello
|
||||
#
|
||||
# @example Standalone usage
|
||||
# require 'lotus'
|
||||
# require 'hanami'
|
||||
#
|
||||
# Lotus::Logger.info('Hello')
|
||||
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Lotus] : Hello
|
||||
# Hanami::Logger.info('Hello')
|
||||
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Hanami] : Hello
|
||||
#
|
||||
# Lotus::Logger.new.info('Hello')
|
||||
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Lotus] : Hello
|
||||
# Hanami::Logger.new.info('Hello')
|
||||
# # => I, [2015-01-10T21:55:12.727259 #80487] INFO -- [Hanami] : Hello
|
||||
#
|
||||
# @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
|
||||
class Logger < ::Logger
|
||||
# Lotus::Logger default formatter
|
||||
# Hanami::Logger default formatter
|
||||
#
|
||||
# @since 0.5.0
|
||||
# @api private
|
||||
|
@ -94,7 +94,7 @@ module Lotus
|
|||
#
|
||||
# @since 0.5.0
|
||||
# @api private
|
||||
DEFAULT_APPLICATION_NAME = 'Lotus'.freeze
|
||||
DEFAULT_APPLICATION_NAME = 'Hanami'.freeze
|
||||
|
||||
# @since 0.5.0
|
||||
# @api private
|
||||
|
@ -110,7 +110,7 @@ module Lotus
|
|||
super(STDOUT)
|
||||
|
||||
@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
|
||||
|
||||
# Returns the current application name, this is used for tagging purposes
|
|
@ -1,17 +1,17 @@
|
|||
require 'lotus/utils/version'
|
||||
require 'hanami/utils/version'
|
||||
|
||||
module Lotus
|
||||
# Ruby core extentions and Lotus utilities
|
||||
module Hanami
|
||||
# Ruby core extentions and Hanami utilities
|
||||
#
|
||||
# @since 0.1.0
|
||||
module Utils
|
||||
# @since 0.3.1
|
||||
# @api private
|
||||
LOTUS_JRUBY = 'java'.freeze
|
||||
HANAMI_JRUBY = 'java'.freeze
|
||||
|
||||
# @since 0.3.1
|
||||
# @api private
|
||||
LOTUS_RUBINIUS = 'rbx'.freeze
|
||||
HANAMI_RUBINIUS = 'rbx'.freeze
|
||||
|
||||
# Checks if the current VM is JRuby
|
||||
#
|
||||
|
@ -20,7 +20,7 @@ module Lotus
|
|||
# @since 0.3.1
|
||||
# @api private
|
||||
def self.jruby?
|
||||
RUBY_PLATFORM == LOTUS_JRUBY
|
||||
RUBY_PLATFORM == HANAMI_JRUBY
|
||||
end
|
||||
|
||||
# Checks if the current VM is Rubinius
|
||||
|
@ -30,7 +30,7 @@ module Lotus
|
|||
# @since 0.3.1
|
||||
# @api private
|
||||
def self.rubinius?
|
||||
RUBY_ENGINE == LOTUS_RUBINIUS
|
||||
RUBY_ENGINE == HANAMI_RUBINIUS
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/hash'
|
||||
require 'hanami/utils/hash'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# A set of attributes.
|
||||
#
|
||||
|
@ -20,14 +20,14 @@ module Lotus
|
|||
#
|
||||
# @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
|
||||
#
|
||||
# @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] } }
|
||||
def initialize(hash = {})
|
||||
@attributes = Utils::Hash.new(hash, &nil).stringify!
|
||||
|
@ -42,9 +42,9 @@ module Lotus
|
|||
# @since 0.3.2
|
||||
#
|
||||
# @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
|
||||
|
@ -82,9 +82,9 @@ module Lotus
|
|||
# @since 0.3.2
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/attributes'
|
||||
# require 'hanami/utils/attributes'
|
||||
#
|
||||
# attributes = Lotus::Utils::Attributes.new
|
||||
# attributes = Hanami::Utils::Attributes.new
|
||||
#
|
||||
# attributes.set(:a, 1)
|
||||
# attributes.get(:a) # => 1
|
||||
|
@ -121,7 +121,7 @@ module Lotus
|
|||
# @api private
|
||||
def _read_value(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
|
||||
else
|
||||
val
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# BasicObject
|
||||
#
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Before and After callbacks
|
||||
#
|
||||
|
@ -12,7 +12,7 @@ module Lotus
|
|||
class Chain
|
||||
# Return a new chain
|
||||
#
|
||||
# @return [Lotus::Utils::Callbacks::Chain]
|
||||
# @return [Hanami::Utils::Callbacks::Chain]
|
||||
#
|
||||
# @since 0.2.0
|
||||
def initialize
|
||||
|
@ -30,16 +30,16 @@ module Lotus
|
|||
#
|
||||
# @see #prepend
|
||||
# @see #run
|
||||
# @see Lotus::Utils::Callbacks::Callback
|
||||
# @see Lotus::Utils::Callbacks::MethodCallback
|
||||
# @see Lotus::Utils::Callbacks::Chain#freeze
|
||||
# @see Hanami::Utils::Callbacks::Callback
|
||||
# @see Hanami::Utils::Callbacks::MethodCallback
|
||||
# @see Hanami::Utils::Callbacks::Chain#freeze
|
||||
#
|
||||
# @since 0.3.4
|
||||
#
|
||||
# @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`
|
||||
# # The optional argument(s) correspond to the one passed when invoked the chain with `run`.
|
||||
|
@ -69,16 +69,16 @@ module Lotus
|
|||
#
|
||||
# @see #append
|
||||
# @see #run
|
||||
# @see Lotus::Utils::Callbacks::Callback
|
||||
# @see Lotus::Utils::Callbacks::MethodCallback
|
||||
# @see Lotus::Utils::Callbacks::Chain#freeze
|
||||
# @see Hanami::Utils::Callbacks::Callback
|
||||
# @see Hanami::Utils::Callbacks::MethodCallback
|
||||
# @see Hanami::Utils::Callbacks::Chain#freeze
|
||||
#
|
||||
# @since 0.3.4
|
||||
#
|
||||
# @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`
|
||||
# # 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
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/callbacks'
|
||||
# require 'hanami/utils/callbacks'
|
||||
#
|
||||
# class Action
|
||||
# private
|
||||
|
@ -120,7 +120,7 @@ module Lotus
|
|||
# action = Action.new
|
||||
# params = Hash[id: 23]
|
||||
#
|
||||
# chain = Lotus::Utils::Callbacks::Chain.new
|
||||
# chain = Hanami::Utils::Callbacks::Chain.new
|
||||
# chain.append :authenticate!, :set_article
|
||||
#
|
||||
# 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
|
||||
# # some authentication logic
|
||||
|
@ -155,9 +155,9 @@ module Lotus
|
|||
# @see http://ruby-doc.org/core/Object.html#method-i-freeze
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/callbacks'
|
||||
# require 'hanami/utils/callbacks'
|
||||
#
|
||||
# chain = Lotus::Utils::Callbacks::Chain.new
|
||||
# chain = Hanami::Utils::Callbacks::Chain.new
|
||||
# chain.freeze
|
||||
#
|
||||
# chain.frozen? # => true
|
||||
|
@ -192,16 +192,16 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/callbacks'
|
||||
# require 'hanami/utils/callbacks'
|
||||
#
|
||||
# callable = Proc.new{} # it responds to #call
|
||||
# method = :upcase # it doesn't responds to #call
|
||||
#
|
||||
# Lotus::Utils::Callbacks::Factory.fabricate(callable).class
|
||||
# # => Lotus::Utils::Callbacks::Callback
|
||||
# Hanami::Utils::Callbacks::Factory.fabricate(callable).class
|
||||
# # => Hanami::Utils::Callbacks::Callback
|
||||
#
|
||||
# Lotus::Utils::Callbacks::Factory.fabricate(method).class
|
||||
# # => Lotus::Utils::Callbacks::MethodCallback
|
||||
# Hanami::Utils::Callbacks::Factory.fabricate(method).class
|
||||
# # => Hanami::Utils::Callbacks::MethodCallback
|
||||
def self.fabricate(callback)
|
||||
if callback.respond_to?(:call)
|
||||
Callback.new(callback)
|
||||
|
@ -240,7 +240,7 @@ module Lotus
|
|||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Utils::Callbacks::Chain#run
|
||||
# @see Hanami::Utils::Callbacks::Chain#run
|
||||
def call(context, *args)
|
||||
context.instance_exec(*args, &callback)
|
||||
end
|
||||
|
@ -262,7 +262,7 @@ module Lotus
|
|||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Utils::Callbacks::Chain#run
|
||||
# @see Hanami::Utils::Callbacks::Chain#run
|
||||
def call(context, *args)
|
||||
method = context.method(callback)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/string'
|
||||
require 'hanami/utils/string'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Class utilities
|
||||
# @since 0.1.0
|
||||
|
@ -16,7 +16,7 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/class'
|
||||
# require 'hanami/utils/class'
|
||||
#
|
||||
# module App
|
||||
# module Service
|
||||
|
@ -29,14 +29,14 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# # basic usage
|
||||
# Lotus::Utils::Class.load!('App::Service') # => App::Service
|
||||
# Lotus::Utils::Class.load!(App::Service) # => App::Service
|
||||
# Hanami::Utils::Class.load!('App::Service') # => App::Service
|
||||
# Hanami::Utils::Class.load!(App::Service) # => App::Service
|
||||
#
|
||||
# # with explicit namespace
|
||||
# Lotus::Utils::Class.load!('Service', App) # => App::Service
|
||||
# Hanami::Utils::Class.load!('Service', App) # => App::Service
|
||||
#
|
||||
# # with missing constant
|
||||
# Lotus::Utils::Class.load!('Unknown') # => raises NameError
|
||||
# Hanami::Utils::Class.load!('Unknown') # => raises NameError
|
||||
def self.load!(name, namespace = Object)
|
||||
namespace.const_get(name.to_s)
|
||||
end
|
||||
|
@ -51,10 +51,10 @@ module Lotus
|
|||
#
|
||||
# @since 0.3.1
|
||||
#
|
||||
# @see Lotus::Utils::String#tokenize
|
||||
# @see Hanami::Utils::String#tokenize
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/class'
|
||||
# require 'hanami/utils/class'
|
||||
#
|
||||
# module App
|
||||
# module Service
|
||||
|
@ -67,17 +67,17 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# # 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
|
||||
# Lotus::Utils::Class.load_from_pattern!('Service', App) # => App::Service
|
||||
# Hanami::Utils::Class.load_from_pattern!('Service', App) # => App::Service
|
||||
#
|
||||
# # with pattern
|
||||
# Lotus::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::Service::Endpoint
|
||||
# Hanami::Utils::Class.load_from_pattern!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint
|
||||
#
|
||||
# # 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)
|
||||
String.new(pattern).tokenize do |token|
|
||||
begin
|
|
@ -1,12 +1,12 @@
|
|||
require 'set'
|
||||
require 'lotus/utils/duplicable'
|
||||
require 'hanami/utils/duplicable'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Inheritable class level variable accessors.
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Utils::ClassAttribute::ClassMethods
|
||||
# @see Hanami::Utils::ClassAttribute::ClassMethods
|
||||
module ClassAttribute
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
|
@ -26,10 +26,10 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/class_attribute'
|
||||
# require 'hanami/utils/class_attribute'
|
||||
#
|
||||
# class Vehicle
|
||||
# include Lotus::Utils::ClassAttribute
|
||||
# include Hanami::Utils::ClassAttribute
|
||||
# class_attribute :engines, :wheels
|
||||
#
|
||||
# self.engines = 0
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils'
|
||||
require 'hanami/utils'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Prints a deprecation warning when initialized
|
||||
#
|
||||
|
@ -13,11 +13,11 @@ module Lotus
|
|||
# @since 0.3.1
|
||||
#
|
||||
# @example Direct usage
|
||||
# require 'lotus/utils/deprecation'
|
||||
# require 'hanami/utils/deprecation'
|
||||
#
|
||||
# class Engine
|
||||
# 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
|
||||
# end
|
||||
#
|
||||
|
@ -31,11 +31,11 @@ module Lotus
|
|||
# # => started
|
||||
#
|
||||
# @example Indirect usage
|
||||
# require 'lotus/utils/deprecation'
|
||||
# require 'hanami/utils/deprecation'
|
||||
#
|
||||
# class Engine
|
||||
# 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
|
||||
# end
|
||||
#
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Safe dup logic
|
||||
#
|
||||
|
@ -26,40 +26,40 @@ module Lotus
|
|||
# @since 0.6.0
|
||||
#
|
||||
# @example Basic Usage With Types That Can't Be Duped
|
||||
# require 'lotus/utils/duplicable'
|
||||
# require 'hanami/utils/duplicable'
|
||||
#
|
||||
# object = 23
|
||||
# puts object.object_id # => 47
|
||||
#
|
||||
# result = Lotus::Utils::Duplicable.dup(object)
|
||||
# result = Hanami::Utils::Duplicable.dup(object)
|
||||
#
|
||||
# puts result # => 23
|
||||
# puts result.object_id # => 47 - Same object, because numbers can't be duped
|
||||
#
|
||||
# @example Basic Usage With Types That Can Be Duped
|
||||
# require 'lotus/utils/duplicable'
|
||||
# require 'hanami/utils/duplicable'
|
||||
#
|
||||
# object = "hello"
|
||||
# puts object.object_id # => 70172661782360
|
||||
#
|
||||
# result = Lotus::Utils::Duplicable.dup(object)
|
||||
# result = Hanami::Utils::Duplicable.dup(object)
|
||||
#
|
||||
# puts result # => "hello"
|
||||
# puts result.object_id # => 70172671467020 – Different object
|
||||
#
|
||||
# @example Custom Logic
|
||||
# require 'lotus/utils/duplicable'
|
||||
# require 'lotus/utils/hash'
|
||||
# require 'hanami/utils/duplicable'
|
||||
# require 'hanami/utils/hash'
|
||||
#
|
||||
# hash = { a: 1 }
|
||||
# puts hash.object_id # => 70207105061680
|
||||
#
|
||||
# result = Lotus::Utils::Duplicable.dup(hash) do |value|
|
||||
# result = Hanami::Utils::Duplicable.dup(hash) do |value|
|
||||
# case value
|
||||
# when Lotus::Utils::Hash
|
||||
# when Hanami::Utils::Hash
|
||||
# value.deep_dup
|
||||
# when ::Hash
|
||||
# Lotus::Utils::Hash.new(value).deep_dup.to_h
|
||||
# Hanami::Utils::Hash.new(value).deep_dup.to_h
|
||||
# end
|
||||
# end
|
||||
#
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# HTML escape utilities
|
||||
#
|
||||
|
@ -72,7 +72,7 @@ module Lotus
|
|||
# @since 0.4.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Utils::Escape.html
|
||||
# @see Hanami::Utils::Escape.html
|
||||
HTML_CHARS = {
|
||||
'&' => '&',
|
||||
'<' => '<',
|
||||
|
@ -100,7 +100,7 @@ module Lotus
|
|||
# @since 0.4.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Utils::Escape.html_attribute
|
||||
# @see Hanami::Utils::Escape.html_attribute
|
||||
HTML_ENTITIES = {
|
||||
34 => 'quot', # quotation mark
|
||||
38 => 'amp', # ampersand
|
||||
|
@ -361,15 +361,15 @@ module Lotus
|
|||
# @since 0.4.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Utils::Escape.url
|
||||
# @see Hanami::Utils::Escape.url
|
||||
DEFAULT_URL_SCHEMES = ['http', 'https', 'mailto'].freeze
|
||||
|
||||
# The output of an escape.
|
||||
#
|
||||
# It's marked with this special class for two reasons:
|
||||
#
|
||||
# * Don't double escape the same string (this is for `Lotus::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`)
|
||||
# * 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 `Hanami::View` or `Hanami::Helpers`)
|
||||
#
|
||||
# @since 0.4.0
|
||||
# @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
|
||||
#
|
||||
# @example Good practice
|
||||
# <div><%= Lotus::Utils::Escape.html('<script>alert(1);</script>') %></div>
|
||||
# <div><%= Hanami::Utils::Escape.html('<script>alert(1);</script>') %></div>
|
||||
# <div><script>alert(1);</script></div>
|
||||
#
|
||||
# @example Bad practice
|
||||
# # 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)
|
||||
input = encode(input)
|
||||
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
|
||||
#
|
||||
# @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
|
||||
# # 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)
|
||||
input = encode(input)
|
||||
return input if input.is_a?(SafeString)
|
||||
|
@ -478,16 +478,16 @@ module Lotus
|
|||
#
|
||||
# @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
|
||||
#
|
||||
# @example Basic usage
|
||||
# <%
|
||||
# good_input = "http://lotusrb.org"
|
||||
# good_input = "http://hanamirb.org"
|
||||
# evil_input = "javascript:alert('xss')"
|
||||
#
|
||||
# escaped_good_input = Lotus::Utils::Escape.url(good_input) # => "http://lotusrb.org"
|
||||
# escaped_evil_input = Lotus::Utils::Escape.url(evil_input) # => ""
|
||||
# escaped_good_input = Hanami::Utils::Escape.url(good_input) # => "http://hanamirb.org"
|
||||
# escaped_evil_input = Hanami::Utils::Escape.url(evil_input) # => ""
|
||||
# %>
|
||||
#
|
||||
# <a href="<%= escaped_good_input %>">personal website</a>
|
||||
|
@ -500,8 +500,8 @@ module Lotus
|
|||
# accepted = "ftps://ftp.example.org"
|
||||
# rejected = "http://www.example.org"
|
||||
#
|
||||
# escaped_accepted = Lotus::Utils::Escape.url(accepted) # => "ftps://ftp.example.org"
|
||||
# escaped_rejected = Lotus::Utils::Escape.url(rejected) # => ""
|
||||
# escaped_accepted = Hanami::Utils::Escape.url(accepted) # => "ftps://ftp.example.org"
|
||||
# escaped_rejected = Hanami::Utils::Escape.url(rejected) # => ""
|
||||
# %>
|
||||
#
|
||||
# <a href="<%= escaped_accepted %>">FTP</a>
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/duplicable'
|
||||
require 'hanami/utils/duplicable'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Hash on steroids
|
||||
# @since 0.1.0
|
||||
|
@ -8,8 +8,8 @@ module Lotus
|
|||
# @since 0.6.0
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Utils::Hash#deep_dup
|
||||
# @see Lotus::Utils::Duplicable
|
||||
# @see Hanami::Utils::Hash#deep_dup
|
||||
# @see Hanami::Utils::Duplicable
|
||||
DUPLICATE_LOGIC = Proc.new do |value|
|
||||
case value
|
||||
when Hash
|
||||
|
@ -24,22 +24,22 @@ module Lotus
|
|||
# @param hash [#to_h] the value we want to use to initialize this instance
|
||||
# @param blk [Proc] define the default value
|
||||
#
|
||||
# @return [Lotus::Utils::Hash] self
|
||||
# @return [Hanami::Utils::Hash] self
|
||||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see http://www.ruby-doc.org/core/Hash.html#method-c-5B-5D
|
||||
#
|
||||
# @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
|
||||
#
|
||||
# @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.to_h # => { 'foo' => ['bar'] }
|
||||
|
@ -55,9 +55,9 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @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.keys # => [:a, :b]
|
||||
|
@ -80,9 +80,9 @@ module Lotus
|
|||
# @since 0.3.2
|
||||
#
|
||||
# @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.keys # => [:a, :b]
|
||||
|
@ -98,16 +98,16 @@ module Lotus
|
|||
self
|
||||
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
|
||||
#
|
||||
# @since 0.3.1
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/hash'
|
||||
# require 'hanami/utils/hash'
|
||||
#
|
||||
# hash = Lotus::Utils::Hash.new(
|
||||
# hash = Hanami::Utils::Hash.new(
|
||||
# 'nil' => nil,
|
||||
# 'false' => false,
|
||||
# 'true' => true,
|
||||
|
@ -120,13 +120,13 @@ module Lotus
|
|||
# 'rational' => Rational(0.3),
|
||||
# 'string' => 'foo bar',
|
||||
# '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
|
||||
#
|
||||
# hash.class # => Lotus::Utils::Hash
|
||||
# duped.class # => Lotus::Utils::Hash
|
||||
# hash.class # => Hanami::Utils::Hash
|
||||
# duped.class # => Hanami::Utils::Hash
|
||||
#
|
||||
# hash.object_id # => 70147385937100
|
||||
# duped.object_id # => 70147385950620
|
||||
|
@ -157,8 +157,8 @@ module Lotus
|
|||
# duped['hash'][:b] # => "TWO"
|
||||
# hash['hash'][:b] # => "two"
|
||||
#
|
||||
# # it deeply duplicates Lotus::Utils::Hash, by preserving the class
|
||||
# duped['u_hash'].class # => Lotus::Utils::Hash
|
||||
# # it deeply duplicates Hanami::Utils::Hash, by preserving the class
|
||||
# duped['u_hash'].class # => Hanami::Utils::Hash
|
||||
def deep_dup
|
||||
Hash.new.tap do |result|
|
||||
@hash.each {|k, v| result[k] = Duplicable.dup(v, &DUPLICATE_LOGIC) }
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/class_attribute'
|
||||
require 'hanami/utils/class_attribute'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# String inflector
|
||||
#
|
||||
|
@ -270,13 +270,13 @@ module Lotus
|
|||
#
|
||||
# @since 0.6.0
|
||||
#
|
||||
# @see Lotus::Utils::Inflector.exception
|
||||
# @see Lotus::Utils::Inflector.uncountable
|
||||
# @see Hanami::Utils::Inflector.exception
|
||||
# @see Hanami::Utils::Inflector.uncountable
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/inflector'
|
||||
# require 'hanami/utils/inflector'
|
||||
#
|
||||
# Lotus::Utils::Inflector.inflections do
|
||||
# Hanami::Utils::Inflector.inflections do
|
||||
# exception 'analysis', 'analyses'
|
||||
# exception 'alga', 'algae'
|
||||
# uncountable 'music', 'butter'
|
||||
|
@ -292,13 +292,13 @@ module Lotus
|
|||
#
|
||||
# @since 0.6.0
|
||||
#
|
||||
# @see Lotus::Utils::Inflector.inflections
|
||||
# @see Lotus::Utils::Inflector.uncountable
|
||||
# @see Hanami::Utils::Inflector.inflections
|
||||
# @see Hanami::Utils::Inflector.uncountable
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/inflector'
|
||||
# require 'hanami/utils/inflector'
|
||||
#
|
||||
# Lotus::Utils::Inflector.inflections do
|
||||
# Hanami::Utils::Inflector.inflections do
|
||||
# exception 'alga', 'algae'
|
||||
# end
|
||||
def self.exception(singular, plural)
|
||||
|
@ -312,13 +312,13 @@ module Lotus
|
|||
#
|
||||
# @since 0.6.0
|
||||
#
|
||||
# @see Lotus::Utils::Inflector.inflections
|
||||
# @see Lotus::Utils::Inflector.exception
|
||||
# @see Hanami::Utils::Inflector.inflections
|
||||
# @see Hanami::Utils::Inflector.exception
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/inflector'
|
||||
# require 'hanami/utils/inflector'
|
||||
#
|
||||
# Lotus::Utils::Inflector.inflections do
|
||||
# Hanami::Utils::Inflector.inflections do
|
||||
# uncountable 'music', 'art'
|
||||
# end
|
||||
def self.uncountable(*words)
|
|
@ -1,4 +1,4 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# IO utils
|
||||
#
|
||||
|
@ -16,13 +16,13 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/io'
|
||||
# require 'hanami/utils/io'
|
||||
#
|
||||
# class Test
|
||||
# TEST_VALUE = 'initial'
|
||||
# end
|
||||
#
|
||||
# Lotus::Utils::IO.silence_warnings do
|
||||
# Hanami::Utils::IO.silence_warnings do
|
||||
# Test::TEST_VALUE = 'redefined'
|
||||
# end
|
||||
def self.silence_warnings
|
|
@ -3,7 +3,7 @@ require 'date'
|
|||
require 'time'
|
||||
require 'pathname'
|
||||
require 'bigdecimal'
|
||||
require 'lotus/utils'
|
||||
require 'hanami/utils'
|
||||
|
||||
# Define top level constant Boolean, so it can be easily used by other libraries
|
||||
# in coercions DSLs
|
||||
|
@ -12,7 +12,7 @@ require 'lotus/utils'
|
|||
class Boolean
|
||||
end unless defined?(Boolean)
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Kernel utilities
|
||||
# @since 0.1.1
|
||||
|
@ -22,7 +22,7 @@ module Lotus
|
|||
# @since 0.3.3
|
||||
# @api private
|
||||
#
|
||||
# @see Lotus::Utils::Kernel.Integer
|
||||
# @see Hanami::Utils::Kernel.Integer
|
||||
NUMERIC_MATCHER = /\A([\d\/\.\+iE]+|NaN|Infinity)\z/.freeze
|
||||
|
||||
# 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
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Array(nil) # => []
|
||||
# Lotus::Utils::Kernel.Array(true) # => [true]
|
||||
# Lotus::Utils::Kernel.Array(false) # => [false]
|
||||
# Lotus::Utils::Kernel.Array(1) # => [1]
|
||||
# Lotus::Utils::Kernel.Array([1]) # => [1]
|
||||
# Lotus::Utils::Kernel.Array([1, [2]]) # => [1,2]
|
||||
# Lotus::Utils::Kernel.Array([1, [2, nil]]) # => [1,2]
|
||||
# Lotus::Utils::Kernel.Array([1, [2, nil, 1]]) # => [1,2]
|
||||
# Hanami::Utils::Kernel.Array(nil) # => []
|
||||
# Hanami::Utils::Kernel.Array(true) # => [true]
|
||||
# Hanami::Utils::Kernel.Array(false) # => [false]
|
||||
# Hanami::Utils::Kernel.Array(1) # => [1]
|
||||
# Hanami::Utils::Kernel.Array([1]) # => [1]
|
||||
# Hanami::Utils::Kernel.Array([1, [2]]) # => [1,2]
|
||||
# Hanami::Utils::Kernel.Array([1, [2, nil]]) # => [1,2]
|
||||
# Hanami::Utils::Kernel.Array([1, [2, nil, 1]]) # => [1,2]
|
||||
#
|
||||
# @example Array Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# ResultSet = Struct.new(:records) do
|
||||
# def to_a
|
||||
|
@ -74,10 +74,10 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# 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')
|
||||
# Lotus::Utils::Kernel.Array(response) # => [200, {}, "hello"]
|
||||
# Hanami::Utils::Kernel.Array(response) # => [200, {}, "hello"]
|
||||
def self.Array(arg)
|
||||
super(arg).dup.tap do |a|
|
||||
a.flatten!
|
||||
|
@ -97,21 +97,21 @@ module Lotus
|
|||
# @since 0.1.1
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Set(nil) # => #<Set: {}>
|
||||
# Lotus::Utils::Kernel.Set(true) # => #<Set: {true}>
|
||||
# Lotus::Utils::Kernel.Set(false) # => #<Set: {false}>
|
||||
# Lotus::Utils::Kernel.Set(1) # => #<Set: {1}>
|
||||
# Lotus::Utils::Kernel.Set([1]) # => #<Set: {1}>
|
||||
# Lotus::Utils::Kernel.Set([1, 1]) # => #<Set: {1}>
|
||||
# Lotus::Utils::Kernel.Set([1, [2]]) # => #<Set: {1, [2]}>
|
||||
# Lotus::Utils::Kernel.Set([1, [2, nil]]) # => #<Set: {1, [2, nil]}>
|
||||
# Lotus::Utils::Kernel.Set({a: 1}) # => #<Set: {[:a, 1]}>
|
||||
# Hanami::Utils::Kernel.Set(nil) # => #<Set: {}>
|
||||
# Hanami::Utils::Kernel.Set(true) # => #<Set: {true}>
|
||||
# Hanami::Utils::Kernel.Set(false) # => #<Set: {false}>
|
||||
# Hanami::Utils::Kernel.Set(1) # => #<Set: {1}>
|
||||
# Hanami::Utils::Kernel.Set([1]) # => #<Set: {1}>
|
||||
# Hanami::Utils::Kernel.Set([1, 1]) # => #<Set: {1}>
|
||||
# Hanami::Utils::Kernel.Set([1, [2]]) # => #<Set: {1, [2]}>
|
||||
# Hanami::Utils::Kernel.Set([1, [2, nil]]) # => #<Set: {1, [2, nil]}>
|
||||
# Hanami::Utils::Kernel.Set({a: 1}) # => #<Set: {[:a, 1]}>
|
||||
#
|
||||
# @example Set Interface
|
||||
# require 'securerandom'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# UuidSet = Class.new do
|
||||
# def initialize(*uuids)
|
||||
|
@ -126,13 +126,13 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# uuids = UuidSet.new(SecureRandom.uuid)
|
||||
# Lotus::Utils::Kernel.Set(uuids)
|
||||
# Hanami::Utils::Kernel.Set(uuids)
|
||||
# # => #<Set: {"daa798b4-630c-4e11-b29d-92f0b1c7d075"}>
|
||||
#
|
||||
# @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)
|
||||
if arg.respond_to?(:to_set)
|
||||
arg.to_set
|
||||
|
@ -156,15 +156,15 @@ module Lotus
|
|||
# @see http://www.ruby-doc.org/core/Kernel.html#method-i-Hash
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Hash(nil) # => {}
|
||||
# Lotus::Utils::Kernel.Hash({a: 1}) # => { :a => 1 }
|
||||
# Lotus::Utils::Kernel.Hash([[:a, 1]]) # => { :a => 1 }
|
||||
# Lotus::Utils::Kernel.Hash(Set.new([[:a, 1]])) # => { :a => 1 }
|
||||
# Hanami::Utils::Kernel.Hash(nil) # => {}
|
||||
# Hanami::Utils::Kernel.Hash({a: 1}) # => { :a => 1 }
|
||||
# Hanami::Utils::Kernel.Hash([[:a, 1]]) # => { :a => 1 }
|
||||
# Hanami::Utils::Kernel.Hash(Set.new([[:a, 1]])) # => { :a => 1 }
|
||||
#
|
||||
# @example Hash Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Room = Class.new do
|
||||
# def initialize(*args)
|
||||
|
@ -187,16 +187,16 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# room = Room.new(:key, 123456)
|
||||
# Lotus::Utils::Kernel.Hash(room) # => { :key => 123456 }
|
||||
# Hanami::Utils::Kernel.Hash(room) # => { :key => 123456 }
|
||||
#
|
||||
# record = Record.new(name: 'L')
|
||||
# Lotus::Utils::Kernel.Hash(record) # => { :name => "L" }
|
||||
# Hanami::Utils::Kernel.Hash(record) # => { :name => "L" }
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Hash(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Hash(input) # => TypeError
|
||||
if RUBY_VERSION >= '2.1'
|
||||
def self.Hash(arg)
|
||||
if arg.respond_to?(:to_h)
|
||||
|
@ -238,23 +238,23 @@ module Lotus
|
|||
#
|
||||
# @example Basic Usage
|
||||
# require 'bigdecimal'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Integer(1) # => 1
|
||||
# Lotus::Utils::Kernel.Integer(1.2) # => 1
|
||||
# Lotus::Utils::Kernel.Integer(011) # => 9
|
||||
# Lotus::Utils::Kernel.Integer(0xf5) # => 245
|
||||
# Lotus::Utils::Kernel.Integer("1") # => 1
|
||||
# Lotus::Utils::Kernel.Integer(Rational(0.3)) # => 0
|
||||
# Lotus::Utils::Kernel.Integer(Complex(0.3)) # => 0
|
||||
# Lotus::Utils::Kernel.Integer(BigDecimal.new(12.00001)) # => 12
|
||||
# Lotus::Utils::Kernel.Integer(176605528590345446089)
|
||||
# Hanami::Utils::Kernel.Integer(1) # => 1
|
||||
# Hanami::Utils::Kernel.Integer(1.2) # => 1
|
||||
# Hanami::Utils::Kernel.Integer(011) # => 9
|
||||
# Hanami::Utils::Kernel.Integer(0xf5) # => 245
|
||||
# Hanami::Utils::Kernel.Integer("1") # => 1
|
||||
# Hanami::Utils::Kernel.Integer(Rational(0.3)) # => 0
|
||||
# Hanami::Utils::Kernel.Integer(Complex(0.3)) # => 0
|
||||
# Hanami::Utils::Kernel.Integer(BigDecimal.new(12.00001)) # => 12
|
||||
# Hanami::Utils::Kernel.Integer(176605528590345446089)
|
||||
# # => 176605528590345446089
|
||||
#
|
||||
# Lotus::Utils::Kernel.Integer(Time.now) # => 1396947161
|
||||
# Hanami::Utils::Kernel.Integer(Time.now) # => 1396947161
|
||||
#
|
||||
# @example Integer Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# UltimateAnswer = Struct.new(:question) do
|
||||
# def to_int
|
||||
|
@ -263,71 +263,71 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# answer = UltimateAnswer.new('The Ultimate Question of Life')
|
||||
# Lotus::Utils::Kernel.Integer(answer) # => 42
|
||||
# Hanami::Utils::Kernel.Integer(answer) # => 42
|
||||
#
|
||||
# @example Error Handling
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # nil
|
||||
# Kernel.Integer(nil) # => TypeError
|
||||
# Lotus::Utils::Kernel.Integer(nil) # => 0
|
||||
# Hanami::Utils::Kernel.Integer(nil) # => 0
|
||||
#
|
||||
# # float represented as a string
|
||||
# Kernel.Integer("23.4") # => TypeError
|
||||
# Lotus::Utils::Kernel.Integer("23.4") # => 23
|
||||
# Hanami::Utils::Kernel.Integer("23.4") # => 23
|
||||
#
|
||||
# # rational represented as a string
|
||||
# Kernel.Integer("2/3") # => TypeError
|
||||
# Lotus::Utils::Kernel.Integer("2/3") # => 2
|
||||
# Hanami::Utils::Kernel.Integer("2/3") # => 2
|
||||
#
|
||||
# # complex represented as a string
|
||||
# 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
|
||||
# require 'date'
|
||||
# require 'bigdecimal'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # Missing #to_int and #to_i
|
||||
# input = OpenStruct.new(color: 'purple')
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # String that doesn't represent an integer
|
||||
# input = 'hello'
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # When true
|
||||
# input = true
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # When false
|
||||
# input = false
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # When Date
|
||||
# input = Date.today
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # When DateTime
|
||||
# input = DateTime.now
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # bigdecimal infinity
|
||||
# input = BigDecimal.new("Infinity")
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # bigdecimal NaN
|
||||
# input = BigDecimal.new("NaN")
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # big rational
|
||||
# input = Rational(-8) ** Rational(1, 3)
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
#
|
||||
# # big complex represented as a string
|
||||
# input = Complex(2, 3)
|
||||
# Lotus::Utils::Kernel.Integer(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Integer(input) # => TypeError
|
||||
def self.Integer(arg)
|
||||
super(arg)
|
||||
rescue ArgumentError, TypeError, NoMethodError
|
||||
|
@ -358,21 +358,21 @@ module Lotus
|
|||
# @see http://www.ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/BigDecimal.html
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.BigDecimal(1) # => 1
|
||||
# Lotus::Utils::Kernel.BigDecimal(1.2) # => 1
|
||||
# Lotus::Utils::Kernel.BigDecimal(011) # => 9
|
||||
# Lotus::Utils::Kernel.BigDecimal(0xf5) # => 245
|
||||
# Lotus::Utils::Kernel.BigDecimal("1") # => 1
|
||||
# Lotus::Utils::Kernel.BigDecimal(Rational(0.3)) # => 0.3
|
||||
# Lotus::Utils::Kernel.BigDecimal(Complex(0.3)) # => 0.3
|
||||
# Lotus::Utils::Kernel.BigDecimal(BigDecimal.new(12.00001)) # => 12.00001
|
||||
# Lotus::Utils::Kernel.BigDecimal(176605528590345446089)
|
||||
# Hanami::Utils::Kernel.BigDecimal(1) # => 1
|
||||
# Hanami::Utils::Kernel.BigDecimal(1.2) # => 1
|
||||
# Hanami::Utils::Kernel.BigDecimal(011) # => 9
|
||||
# Hanami::Utils::Kernel.BigDecimal(0xf5) # => 245
|
||||
# Hanami::Utils::Kernel.BigDecimal("1") # => 1
|
||||
# Hanami::Utils::Kernel.BigDecimal(Rational(0.3)) # => 0.3
|
||||
# Hanami::Utils::Kernel.BigDecimal(Complex(0.3)) # => 0.3
|
||||
# Hanami::Utils::Kernel.BigDecimal(BigDecimal.new(12.00001)) # => 12.00001
|
||||
# Hanami::Utils::Kernel.BigDecimal(176605528590345446089)
|
||||
# # => 176605528590345446089
|
||||
#
|
||||
# @example BigDecimal Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# UltimateAnswer = Struct.new(:question) do
|
||||
# def to_d
|
||||
|
@ -381,43 +381,43 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# answer = UltimateAnswer.new('The Ultimate Question of Life')
|
||||
# Lotus::Utils::Kernel.BigDecimal(answer)
|
||||
# Hanami::Utils::Kernel.BigDecimal(answer)
|
||||
# # => #<BigDecimal:7fabfd148588,'0.42E2',9(27)>
|
||||
#
|
||||
# @example Unchecked exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # When nil
|
||||
# input = nil
|
||||
# Lotus::Utils::Kernel.BigDecimal(nil) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(nil) # => TypeError
|
||||
#
|
||||
# # When true
|
||||
# input = true
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
#
|
||||
# # When false
|
||||
# input = false
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
#
|
||||
# # When Date
|
||||
# input = Date.today
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
#
|
||||
# # When DateTime
|
||||
# input = DateTime.now
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
#
|
||||
# # When Time
|
||||
# input = Time.now
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
#
|
||||
# # String that doesn't represent a big decimal
|
||||
# input = 'hello'
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
|
||||
def self.BigDecimal(arg)
|
||||
case arg
|
||||
when ->(a) { a.respond_to?(:to_d) } then arg.to_d
|
||||
|
@ -449,23 +449,23 @@ module Lotus
|
|||
#
|
||||
# @example Basic Usage
|
||||
# require 'bigdecimal'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Float(1) # => 1.0
|
||||
# Lotus::Utils::Kernel.Float(1.2) # => 1.2
|
||||
# Lotus::Utils::Kernel.Float(011) # => 9.0
|
||||
# Lotus::Utils::Kernel.Float(0xf5) # => 245.0
|
||||
# Lotus::Utils::Kernel.Float("1") # => 1.0
|
||||
# Lotus::Utils::Kernel.Float(Rational(0.3)) # => 0.3
|
||||
# Lotus::Utils::Kernel.Float(Complex(0.3)) # => 0.3
|
||||
# Lotus::Utils::Kernel.Float(BigDecimal.new(12.00001)) # => 12.00001
|
||||
# Lotus::Utils::Kernel.Float(176605528590345446089)
|
||||
# Hanami::Utils::Kernel.Float(1) # => 1.0
|
||||
# Hanami::Utils::Kernel.Float(1.2) # => 1.2
|
||||
# Hanami::Utils::Kernel.Float(011) # => 9.0
|
||||
# Hanami::Utils::Kernel.Float(0xf5) # => 245.0
|
||||
# Hanami::Utils::Kernel.Float("1") # => 1.0
|
||||
# Hanami::Utils::Kernel.Float(Rational(0.3)) # => 0.3
|
||||
# Hanami::Utils::Kernel.Float(Complex(0.3)) # => 0.3
|
||||
# Hanami::Utils::Kernel.Float(BigDecimal.new(12.00001)) # => 12.00001
|
||||
# Hanami::Utils::Kernel.Float(176605528590345446089)
|
||||
# # => 176605528590345446089.0
|
||||
#
|
||||
# Lotus::Utils::Kernel.Float(Time.now) # => 397750945.515169
|
||||
# Hanami::Utils::Kernel.Float(Time.now) # => 397750945.515169
|
||||
#
|
||||
# @example Float Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class Pi
|
||||
# def to_f
|
||||
|
@ -474,76 +474,76 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# pi = Pi.new
|
||||
# Lotus::Utils::Kernel.Float(pi) # => 3.14
|
||||
# Hanami::Utils::Kernel.Float(pi) # => 3.14
|
||||
#
|
||||
# @example Error Handling
|
||||
# require 'bigdecimal'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # nil
|
||||
# Kernel.Float(nil) # => TypeError
|
||||
# Lotus::Utils::Kernel.Float(nil) # => 0.0
|
||||
# Hanami::Utils::Kernel.Float(nil) # => 0.0
|
||||
#
|
||||
# # float represented as a string
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# input = BigDecimal.new("Infinity")
|
||||
# Lotus::Utils::Kernel.Float(input) # => Infinity
|
||||
# Hanami::Utils::Kernel.Float(input) # => Infinity
|
||||
#
|
||||
# # bigdecimal NaN
|
||||
# input = BigDecimal.new("NaN")
|
||||
# Lotus::Utils::Kernel.Float(input) # => NaN
|
||||
# Hanami::Utils::Kernel.Float(input) # => NaN
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'date'
|
||||
# require 'bigdecimal'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # Missing #to_f
|
||||
# input = OpenStruct.new(color: 'purple')
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # When true
|
||||
# input = true
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # When false
|
||||
# input = false
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # When Date
|
||||
# input = Date.today
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # When DateTime
|
||||
# input = DateTime.now
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # Missing #nil?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # String that doesn't represent a float
|
||||
# input = 'hello'
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # big rational
|
||||
# input = Rational(-8) ** Rational(1, 3)
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
#
|
||||
# # big complex represented as a string
|
||||
# input = Complex(2, 3)
|
||||
# Lotus::Utils::Kernel.Float(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Float(input) # => TypeError
|
||||
def self.Float(arg)
|
||||
super(arg)
|
||||
rescue ArgumentError, TypeError
|
||||
|
@ -579,43 +579,43 @@ module Lotus
|
|||
# @example Basic Usage
|
||||
# require 'date'
|
||||
# require 'bigdecimal'
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.String('') # => ""
|
||||
# Lotus::Utils::Kernel.String('ciao') # => "ciao"
|
||||
# Hanami::Utils::Kernel.String('') # => ""
|
||||
# Hanami::Utils::Kernel.String('ciao') # => "ciao"
|
||||
#
|
||||
# Lotus::Utils::Kernel.String(true) # => "true"
|
||||
# Lotus::Utils::Kernel.String(false) # => "false"
|
||||
# Hanami::Utils::Kernel.String(true) # => "true"
|
||||
# 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
|
||||
# Lotus::Utils::Kernel.String(Lotus) # => "Lotus" # module
|
||||
# Hanami::Utils::Kernel.String(Picture) # => "Picture" # class
|
||||
# Hanami::Utils::Kernel.String(Hanami) # => "Hanami" # module
|
||||
#
|
||||
# Lotus::Utils::Kernel.String([]) # => "[]"
|
||||
# Lotus::Utils::Kernel.String([1,2,3]) # => "[1, 2, 3]"
|
||||
# Lotus::Utils::Kernel.String(%w[a b c]) # => "[\"a\", \"b\", \"c\"]"
|
||||
# Hanami::Utils::Kernel.String([]) # => "[]"
|
||||
# Hanami::Utils::Kernel.String([1,2,3]) # => "[1, 2, 3]"
|
||||
# Hanami::Utils::Kernel.String(%w[a b c]) # => "[\"a\", \"b\", \"c\"]"
|
||||
#
|
||||
# Lotus::Utils::Kernel.String({}) # => "{}"
|
||||
# Lotus::Utils::Kernel.String({a: 1, 'b' => 'c'}) # => "{:a=>1, \"b\"=>\"c\"}"
|
||||
# Hanami::Utils::Kernel.String({}) # => "{}"
|
||||
# Hanami::Utils::Kernel.String({a: 1, 'b' => 'c'}) # => "{:a=>1, \"b\"=>\"c\"}"
|
||||
#
|
||||
# Lotus::Utils::Kernel.String(Date.today) # => "2014-04-11"
|
||||
# Lotus::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(Date.today) # => "2014-04-11"
|
||||
# Hanami::Utils::Kernel.String(DateTime.now) # => "2014-04-11T10:15:06+02:00"
|
||||
# Hanami::Utils::Kernel.String(Time.now) # => "2014-04-11 10:15:53 +0200"
|
||||
#
|
||||
# Lotus::Utils::Kernel.String(1) # => "1"
|
||||
# Lotus::Utils::Kernel.String(3.14) # => "3.14"
|
||||
# Lotus::Utils::Kernel.String(013) # => "11"
|
||||
# Lotus::Utils::Kernel.String(0xc0ff33) # => "12648243"
|
||||
# Hanami::Utils::Kernel.String(1) # => "1"
|
||||
# Hanami::Utils::Kernel.String(3.14) # => "3.14"
|
||||
# Hanami::Utils::Kernel.String(013) # => "11"
|
||||
# Hanami::Utils::Kernel.String(0xc0ff33) # => "12648243"
|
||||
#
|
||||
# Lotus::Utils::Kernel.String(Rational(-22)) # => "-22/1"
|
||||
# Lotus::Utils::Kernel.String(Complex(11, 2)) # => "11+2i"
|
||||
# Lotus::Utils::Kernel.String(BigDecimal.new(7944.2343, 10)) # => "0.79442343E4"
|
||||
# Lotus::Utils::Kernel.String(BigDecimal.new('Infinity')) # => "Infinity"
|
||||
# Lotus::Utils::Kernel.String(BigDecimal.new('NaN')) # => "Infinity"
|
||||
# Hanami::Utils::Kernel.String(Rational(-22)) # => "-22/1"
|
||||
# Hanami::Utils::Kernel.String(Complex(11, 2)) # => "11+2i"
|
||||
# Hanami::Utils::Kernel.String(BigDecimal.new(7944.2343, 10)) # => "0.79442343E4"
|
||||
# Hanami::Utils::Kernel.String(BigDecimal.new('Infinity')) # => "Infinity"
|
||||
# Hanami::Utils::Kernel.String(BigDecimal.new('NaN')) # => "Infinity"
|
||||
#
|
||||
# @example String interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# SimpleObject = Class.new(BasicObject) do
|
||||
# def to_s
|
||||
|
@ -632,22 +632,22 @@ module Lotus
|
|||
# simple = SimpleObject.new
|
||||
# isbn = Isbn.new(123)
|
||||
#
|
||||
# Lotus::Utils::Kernel.String(simple) # => "simple object"
|
||||
# Lotus::Utils::Kernel.String(isbn) # => "123"
|
||||
# Hanami::Utils::Kernel.String(simple) # => "simple object"
|
||||
# Hanami::Utils::Kernel.String(isbn) # => "123"
|
||||
#
|
||||
# @example Comparison with Ruby
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # nil
|
||||
# Kernel.String(nil) # => ""
|
||||
# Lotus::Utils::Kernel.String(nil) # => ""
|
||||
# Hanami::Utils::Kernel.String(nil) # => ""
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # Missing #to_s or #to_str
|
||||
# input = BaseObject.new
|
||||
# Lotus::Utils::Kernel.String(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.String(input) # => TypeError
|
||||
if Utils.rubinius?
|
||||
def self.String(arg)
|
||||
case arg
|
||||
|
@ -681,25 +681,25 @@ module Lotus
|
|||
# @since 0.1.1
|
||||
#
|
||||
# @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)>
|
||||
#
|
||||
# Lotus::Utils::Kernel.Date(DateTime.now)
|
||||
# Hanami::Utils::Kernel.Date(DateTime.now)
|
||||
# # => #<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)>
|
||||
#
|
||||
# Lotus::Utils::Kernel.Date('2014-04-17')
|
||||
# Hanami::Utils::Kernel.Date('2014-04-17')
|
||||
# # => #<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)>
|
||||
#
|
||||
# @example Date Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class Christmas
|
||||
# def to_date
|
||||
|
@ -707,23 +707,23 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# Lotus::Utils::Kernel.Date(Christmas.new)
|
||||
# Hanami::Utils::Kernel.Date(Christmas.new)
|
||||
# # => #<Date: 2014-12-25 ((2457017j,0s,0n),+0s,2299161j)>
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # nil
|
||||
# input = nil
|
||||
# Lotus::Utils::Kernel.Date(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Date(input) # => TypeError
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Date(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Date(input) # => TypeError
|
||||
#
|
||||
# # Missing #to_s?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Date(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Date(input) # => TypeError
|
||||
def self.Date(arg)
|
||||
if arg.respond_to?(:to_date)
|
||||
arg.to_date
|
||||
|
@ -745,28 +745,28 @@ module Lotus
|
|||
# @since 0.1.1
|
||||
#
|
||||
# @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)>
|
||||
#
|
||||
# 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)>
|
||||
#
|
||||
# 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)>
|
||||
#
|
||||
# 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)>
|
||||
#
|
||||
# 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)>
|
||||
#
|
||||
# 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)>
|
||||
#
|
||||
# @example DateTime Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class NewYearEve
|
||||
# def to_datetime
|
||||
|
@ -774,23 +774,23 @@ module Lotus
|
|||
# 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)>
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # When nil
|
||||
# input = nil
|
||||
# Lotus::Utils::Kernel.DateTime(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.DateTime(input) # => TypeError
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.DateTime(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.DateTime(input) # => TypeError
|
||||
#
|
||||
# # Missing #to_s?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.DateTime(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.DateTime(input) # => TypeError
|
||||
def self.DateTime(arg)
|
||||
case arg
|
||||
when ->(a) { a.respond_to?(:to_datetime) } then arg.to_datetime
|
||||
|
@ -813,25 +813,25 @@ module Lotus
|
|||
# @since 0.1.1
|
||||
#
|
||||
# @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
|
||||
#
|
||||
# Lotus::Utils::Kernel.Time(DateTime.now)
|
||||
# Hanami::Utils::Kernel.Time(DateTime.now)
|
||||
# # => 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
|
||||
#
|
||||
# Lotus::Utils::Kernel.Time('2014-04-18')
|
||||
# Hanami::Utils::Kernel.Time('2014-04-18')
|
||||
# # => 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
|
||||
#
|
||||
# @example Time Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class Epoch
|
||||
# def to_time
|
||||
|
@ -839,23 +839,23 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# Lotus::Utils::Kernel.Time(Epoch.new)
|
||||
# Hanami::Utils::Kernel.Time(Epoch.new)
|
||||
# # => 1970-01-01 01:00:00 +0100
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # When nil
|
||||
# input = nil
|
||||
# Lotus::Utils::Kernel.Time(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Time(input) # => TypeError
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Time(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Time(input) # => TypeError
|
||||
#
|
||||
# # Missing #to_s?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Time(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Time(input) # => TypeError
|
||||
def self.Time(arg)
|
||||
case arg
|
||||
when ->(a) { a.respond_to?(:to_time) } then arg.to_time
|
||||
|
@ -878,17 +878,17 @@ module Lotus
|
|||
# @since 0.1.1
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Boolean(nil) # => false
|
||||
# Lotus::Utils::Kernel.Boolean(0) # => false
|
||||
# Lotus::Utils::Kernel.Boolean(1) # => true
|
||||
# Lotus::Utils::Kernel.Boolean('0') # => false
|
||||
# Lotus::Utils::Kernel.Boolean('1') # => true
|
||||
# Lotus::Utils::Kernel.Boolean(Object.new) # => true
|
||||
# Hanami::Utils::Kernel.Boolean(nil) # => false
|
||||
# Hanami::Utils::Kernel.Boolean(0) # => false
|
||||
# Hanami::Utils::Kernel.Boolean(1) # => true
|
||||
# Hanami::Utils::Kernel.Boolean('0') # => false
|
||||
# Hanami::Utils::Kernel.Boolean('1') # => true
|
||||
# Hanami::Utils::Kernel.Boolean(Object.new) # => true
|
||||
#
|
||||
# @example Boolean Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Answer = Struct.new(:answer) do
|
||||
# def to_bool
|
||||
|
@ -900,14 +900,14 @@ module Lotus
|
|||
# end
|
||||
#
|
||||
# answer = Answer.new('yes')
|
||||
# Lotus::Utils::Kernel.Boolean(answer) # => true
|
||||
# Hanami::Utils::Kernel.Boolean(answer) # => true
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Boolean(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Boolean(input) # => TypeError
|
||||
def self.Boolean(arg)
|
||||
case arg
|
||||
when Numeric then arg > 0 && arg <= 1
|
||||
|
@ -931,13 +931,13 @@ module Lotus
|
|||
# @since 0.1.2
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Pathname(Pathname.new('/path/to')) # => #<Pathname:/path/to>
|
||||
# Lotus::Utils::Kernel.Pathname('/path/to') # => #<Pathname:/path/to>
|
||||
# Hanami::Utils::Kernel.Pathname(Pathname.new('/path/to')) # => #<Pathname:/path/to>
|
||||
# Hanami::Utils::Kernel.Pathname('/path/to') # => #<Pathname:/path/to>
|
||||
#
|
||||
# @example Pathname Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class HomePath
|
||||
# def to_pathname
|
||||
|
@ -945,10 +945,10 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# Lotus::Utils::Kernel.Pathname(HomePath.new) # => #<Pathname:/Users/luca>
|
||||
# Hanami::Utils::Kernel.Pathname(HomePath.new) # => #<Pathname:/Users/luca>
|
||||
#
|
||||
# @example String Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class RootPath
|
||||
# def to_str
|
||||
|
@ -956,18 +956,18 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# Lotus::Utils::Kernel.Pathname(RootPath.new) # => #<Pathname:/>
|
||||
# Hanami::Utils::Kernel.Pathname(RootPath.new) # => #<Pathname:/>
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # When nil
|
||||
# input = nil
|
||||
# Lotus::Utils::Kernel.Pathname(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Pathname(input) # => TypeError
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Pathname(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Pathname(input) # => TypeError
|
||||
def self.Pathname(arg)
|
||||
case arg
|
||||
when ->(a) { a.respond_to?(:to_pathname) } then arg.to_pathname
|
||||
|
@ -989,13 +989,13 @@ module Lotus
|
|||
# @since 0.2.0
|
||||
#
|
||||
# @example Basic Usage
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# Lotus::Utils::Kernel.Symbol(:hello) # => :hello
|
||||
# Lotus::Utils::Kernel.Symbol('hello') # => :hello
|
||||
# Hanami::Utils::Kernel.Symbol(:hello) # => :hello
|
||||
# Hanami::Utils::Kernel.Symbol('hello') # => :hello
|
||||
#
|
||||
# @example Symbol Interface
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# class StatusSymbol
|
||||
# def to_sym
|
||||
|
@ -1003,22 +1003,22 @@ module Lotus
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# Lotus::Utils::Kernel.Symbol(StatusSymbol.new) # => :success
|
||||
# Hanami::Utils::Kernel.Symbol(StatusSymbol.new) # => :success
|
||||
#
|
||||
# @example Unchecked Exceptions
|
||||
# require 'lotus/utils/kernel'
|
||||
# require 'hanami/utils/kernel'
|
||||
#
|
||||
# # When nil
|
||||
# input = nil
|
||||
# Lotus::Utils::Kernel.Symbol(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Symbol(input) # => TypeError
|
||||
#
|
||||
# # When empty string
|
||||
# input = ''
|
||||
# Lotus::Utils::Kernel.Symbol(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Symbol(input) # => TypeError
|
||||
#
|
||||
# # Missing #respond_to?
|
||||
# input = BasicObject.new
|
||||
# Lotus::Utils::Kernel.Symbol(input) # => TypeError
|
||||
# Hanami::Utils::Kernel.Symbol(input) # => TypeError
|
||||
def self.Symbol(arg)
|
||||
case arg
|
||||
when '' then raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/kernel'
|
||||
require 'hanami/utils/kernel'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# A collection of loading paths.
|
||||
#
|
||||
|
@ -11,12 +11,12 @@ module Lotus
|
|||
# @param paths [String, Pathname, Array<String>, Array<Pathname>] A single
|
||||
# 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
|
||||
#
|
||||
# @see http://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html
|
||||
# @see Lotus::Utils::Kernel.Pathname
|
||||
# @see Hanami::Utils::Kernel.Pathname
|
||||
def initialize(*paths)
|
||||
@paths = Utils::Kernel.Array(paths)
|
||||
end
|
||||
|
@ -31,19 +31,19 @@ module Lotus
|
|||
# @see http://ruby-doc.org/core/Object.html#method-i-dup
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/load_paths'
|
||||
# require 'hanami/utils/load_paths'
|
||||
#
|
||||
# paths = Lotus::Utils::LoadPaths.new '.'
|
||||
# paths = Hanami::Utils::LoadPaths.new '.'
|
||||
# paths2 = paths.dup
|
||||
#
|
||||
# paths << '..'
|
||||
# paths2 << '../..'
|
||||
#
|
||||
# paths
|
||||
# # => #<Lotus::Utils::LoadPaths:0x007f84e0cad430 @paths=[".", ".."]>
|
||||
# # => #<Hanami::Utils::LoadPaths:0x007f84e0cad430 @paths=[".", ".."]>
|
||||
#
|
||||
# paths2
|
||||
# # => #<Lotus::Utils::LoadPaths:0x007faedc4ad3e0 @paths=[".", "../.."]>
|
||||
# # => #<Hanami::Utils::LoadPaths:0x007faedc4ad3e0 @paths=[".", "../.."]>
|
||||
def initialize_copy(original)
|
||||
@paths = original.instance_variable_get(:@paths).dup
|
||||
end
|
||||
|
@ -73,41 +73,41 @@ module Lotus
|
|||
# @param paths [String, Pathname, Array<String>, Array<Pathname>] A single
|
||||
# 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
|
||||
#
|
||||
# @since 0.2.0
|
||||
#
|
||||
# @see http://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html
|
||||
# @see Lotus::Utils::Kernel.Pathname
|
||||
# @see Lotus::Utils::LoadPaths#freeze
|
||||
# @see Hanami::Utils::Kernel.Pathname
|
||||
# @see Hanami::Utils::LoadPaths#freeze
|
||||
#
|
||||
# @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 '..', '../..'
|
||||
#
|
||||
# @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('.')
|
||||
# .push('..', '../..')
|
||||
#
|
||||
# @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 << ['..', '../..']
|
||||
#
|
||||
# @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 << '.' << '../..'
|
||||
def push(*paths)
|
||||
@paths.push(*paths)
|
||||
|
@ -124,9 +124,9 @@ module Lotus
|
|||
# @see http://ruby-doc.org/core/Object.html#method-i-freeze
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/load_paths'
|
||||
# require 'hanami/utils/load_paths'
|
||||
#
|
||||
# paths = Lotus::Utils::LoadPaths.new
|
||||
# paths = Hanami::Utils::LoadPaths.new
|
||||
# paths.freeze
|
||||
#
|
||||
# paths.frozen? # => true
|
|
@ -1,12 +1,12 @@
|
|||
require 'lotus/utils/string'
|
||||
require 'lotus/utils/kernel'
|
||||
require 'hanami/utils/string'
|
||||
require 'hanami/utils/kernel'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Prefixed string
|
||||
#
|
||||
# @since 0.1.0
|
||||
class PathPrefix < Lotus::Utils::String
|
||||
class PathPrefix < Hanami::Utils::String
|
||||
# Path separator
|
||||
#
|
||||
# @since 0.3.1
|
||||
|
@ -22,7 +22,7 @@ module Lotus
|
|||
#
|
||||
# @since 0.1.0
|
||||
#
|
||||
# @see Lotus::Utils::PathPrefix::DEFAULT_SEPARATOR
|
||||
# @see Hanami::Utils::PathPrefix::DEFAULT_SEPARATOR
|
||||
def initialize(string = nil, separator = DEFAULT_SEPARATOR)
|
||||
super(string)
|
||||
@separator = separator
|
||||
|
@ -33,25 +33,25 @@ module Lotus
|
|||
#
|
||||
# @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
|
||||
#
|
||||
# @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 = 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"
|
||||
#
|
||||
# @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
|
||||
# # => "/myapp/assets/application.js"
|
||||
def join(*strings)
|
||||
|
@ -64,7 +64,7 @@ module Lotus
|
|||
# @param strings [::String] the tokens we want to join
|
||||
# @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
|
||||
# string
|
||||
|
@ -72,9 +72,9 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @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'
|
||||
def relative_join(strings, separator = @separator)
|
||||
|
@ -114,10 +114,10 @@ module Lotus
|
|||
# @api private
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/path_prefix'
|
||||
# require 'hanami/utils/path_prefix'
|
||||
#
|
||||
# Lotus::Utils::PathPrefix.new('/posts').absolute? #=> true
|
||||
# Lotus::Utils::PathPrefix.new('posts').absolute? #=> false
|
||||
# Hanami::Utils::PathPrefix.new('/posts').absolute? #=> true
|
||||
# Hanami::Utils::PathPrefix.new('posts').absolute? #=> false
|
||||
def absolute?
|
||||
@string.start_with?(separator)
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'lotus/utils/inflector'
|
||||
require 'hanami/utils/inflector'
|
||||
|
||||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# String on steroids
|
||||
#
|
||||
|
@ -85,42 +85,42 @@ module Lotus
|
|||
|
||||
# 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
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/string'
|
||||
# require 'hanami/utils/string'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus utils'
|
||||
# string.titleize # => "Lotus Utils"
|
||||
# string = Hanami::Utils::String.new 'hanami utils'
|
||||
# string.titleize # => "Hanami Utils"
|
||||
def titleize
|
||||
self.class.new underscore.split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
|
||||
end
|
||||
|
||||
# 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
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/string'
|
||||
# require 'hanami/utils/string'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus'
|
||||
# string.capitalize # => "Lotus"
|
||||
# string = Hanami::Utils::String.new 'hanami'
|
||||
# string.capitalize # => "Hanami"
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus utils'
|
||||
# string.capitalize # => "Lotus utils"
|
||||
# string = Hanami::Utils::String.new 'hanami utils'
|
||||
# string.capitalize # => "Hanami utils"
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'Lotus Utils'
|
||||
# string.capitalize # => "Lotus utils"
|
||||
# string = Hanami::Utils::String.new 'Hanami Utils'
|
||||
# string.capitalize # => "Hanami utils"
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus_utils'
|
||||
# string.capitalize # => "Lotus utils"
|
||||
# string = Hanami::Utils::String.new 'hanami_utils'
|
||||
# string.capitalize # => "Hanami utils"
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus-utils'
|
||||
# string.capitalize # => "Lotus utils"
|
||||
# string = Hanami::Utils::String.new 'hanami-utils'
|
||||
# string.capitalize # => "Hanami utils"
|
||||
def capitalize
|
||||
head, *tail = underscore.split(CLASSIFY_SEPARATOR)
|
||||
|
||||
|
@ -136,10 +136,10 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/string'
|
||||
# require 'hanami/utils/string'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus_utils'
|
||||
# string.classify # => 'LotusUtils'
|
||||
# string = Hanami::Utils::String.new 'hanami_utils'
|
||||
# string.classify # => 'HanamiUtils'
|
||||
def classify
|
||||
words = split(CLASSIFY_WORD_SEPARATOR).map!(&:capitalize)
|
||||
delimiters = scan(CLASSIFY_WORD_SEPARATOR)
|
||||
|
@ -161,10 +161,10 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/string'
|
||||
# require 'hanami/utils/string'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'LotusUtils'
|
||||
# string.underscore # => 'lotus_utils'
|
||||
# string = Hanami::Utils::String.new 'HanamiUtils'
|
||||
# string.underscore # => 'hanami_utils'
|
||||
def underscore
|
||||
new_string = gsub(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
|
||||
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 [Lotus::Utils::String] the transformed string
|
||||
# @return [Hanami::Utils::String] the transformed string
|
||||
#
|
||||
# @since 0.4.0
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/string'
|
||||
# require 'hanami/utils/string'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'Lotus Utils'
|
||||
# string.dasherize # => 'lotus-utils'
|
||||
# string = Hanami::Utils::String.new 'Hanami Utils'
|
||||
# string.dasherize # => 'hanami-utils'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'lotus_utils'
|
||||
# string.dasherize # => 'lotus-utils'
|
||||
# string = Hanami::Utils::String.new 'hanami_utils'
|
||||
# string.dasherize # => 'hanami-utils'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'LotusUtils'
|
||||
# string.dasherize # => "lotus-utils"
|
||||
# string = Hanami::Utils::String.new 'HanamiUtils'
|
||||
# string.dasherize # => "hanami-utils"
|
||||
def dasherize
|
||||
self.class.new underscore.split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
|
||||
end
|
||||
|
@ -202,12 +202,12 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @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 = Lotus::Utils::String.new 'String'
|
||||
# string = Hanami::Utils::String.new 'String'
|
||||
# string.demodulize # => 'String'
|
||||
def demodulize
|
||||
self.class.new split(NAMESPACE_SEPARATOR).last
|
||||
|
@ -220,12 +220,12 @@ module Lotus
|
|||
# @since 0.1.2
|
||||
#
|
||||
# @example
|
||||
# require 'lotus/utils/string'
|
||||
# require 'hanami/utils/string'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'Lotus::Utils::String'
|
||||
# string.namespace # => 'Lotus'
|
||||
# string = Hanami::Utils::String.new 'Hanami::Utils::String'
|
||||
# string.namespace # => 'Hanami'
|
||||
#
|
||||
# string = Lotus::Utils::String.new 'String'
|
||||
# string = Hanami::Utils::String.new 'String'
|
||||
# string.namespace # => 'String'
|
||||
def namespace
|
||||
self.class.new split(NAMESPACE_SEPARATOR).first
|
||||
|
@ -241,16 +241,16 @@ module Lotus
|
|||
# @since 0.1.0
|
||||
#
|
||||
# @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|
|
||||
# puts token
|
||||
# end
|
||||
#
|
||||
# # =>
|
||||
# 'Lotus::Utils'
|
||||
# 'Lotus::App'
|
||||
# 'Hanami::Utils'
|
||||
# 'Hanami::App'
|
||||
def tokenize
|
||||
if match = TOKENIZE_REGEXP.match(@string)
|
||||
pre, post = match.pre_match, match.post_match
|
||||
|
@ -267,24 +267,24 @@ module Lotus
|
|||
|
||||
# Return a pluralized version of self.
|
||||
#
|
||||
# @return [Lotus::Utils::String] the pluralized string.
|
||||
# @return [Hanami::Utils::String] the pluralized string.
|
||||
#
|
||||
# @api private
|
||||
# @since 0.4.1
|
||||
#
|
||||
# @see Lotus::Utils::Inflector
|
||||
# @see Hanami::Utils::Inflector
|
||||
def pluralize
|
||||
self.class.new Inflector.pluralize(self)
|
||||
end
|
||||
|
||||
# Return a singularized version of self.
|
||||
#
|
||||
# @return [Lotus::Utils::String] the singularized string.
|
||||
# @return [Hanami::Utils::String] the singularized string.
|
||||
#
|
||||
# @api private
|
||||
# @since 0.4.1
|
||||
#
|
||||
# @see Lotus::Utils::Inflector
|
||||
# @see Hanami::Utils::Inflector
|
||||
def singularize
|
||||
self.class.new Inflector.singularize(self)
|
||||
end
|
||||
|
@ -364,23 +364,23 @@ module Lotus
|
|||
# This method does NOT mutate the original string.
|
||||
#
|
||||
# @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
|
||||
#
|
||||
# @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(/\//, '#')
|
||||
#
|
||||
# puts string
|
||||
# # => #<Lotus::Utils::String:0x007fdb41233ad8 @string="authors/books/index">
|
||||
# # => #<Hanami::Utils::String:0x007fdb41233ad8 @string="authors/books/index">
|
||||
#
|
||||
# puts result
|
||||
# # => #<Lotus::Utils::String:0x007fdb41232ed0 @string="authors/books#index">
|
||||
# # => #<Hanami::Utils::String:0x007fdb41232ed0 @string="authors/books#index">
|
||||
def rsub(pattern, replacement)
|
||||
if i = rindex(pattern)
|
||||
s = @string.dup
|
|
@ -1,8 +1,8 @@
|
|||
module Lotus
|
||||
module Hanami
|
||||
module Utils
|
||||
# Defines the version
|
||||
#
|
||||
# @since 0.1.0
|
||||
VERSION = '0.6.1'.freeze
|
||||
VERSION = '0.7.0'.freeze
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
require 'lotus/utils'
|
|
@ -1,8 +1,8 @@
|
|||
require 'test_helper'
|
||||
require 'bigdecimal'
|
||||
require 'lotus/utils/attributes'
|
||||
require 'hanami/utils/attributes'
|
||||
|
||||
describe Lotus::Utils::Attributes do
|
||||
describe Hanami::Utils::Attributes do
|
||||
describe '#initialize' do
|
||||
before do
|
||||
class AttributesSet
|
||||
|
@ -17,57 +17,57 @@ describe Lotus::Utils::Attributes do
|
|||
end
|
||||
|
||||
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})
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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]}})
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' 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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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 = Lotus::Utils::Attributes.new(foo: false)
|
||||
attributes = Hanami::Utils::Attributes.new(foo: false)
|
||||
attributes.get(:foo).must_equal false
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
@ -75,40 +75,40 @@ describe Lotus::Utils::Attributes do
|
|||
|
||||
describe '#[]' 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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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 = Lotus::Utils::Attributes.new(foo: false)
|
||||
attributes = Hanami::Utils::Attributes.new(foo: false)
|
||||
attributes[:foo].must_equal false
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
@ -116,11 +116,11 @@ describe Lotus::Utils::Attributes do
|
|||
|
||||
describe '#set' 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
|
||||
|
||||
it 'sets a value (string)' do
|
||||
attributes = Lotus::Utils::Attributes.new
|
||||
attributes = Hanami::Utils::Attributes.new
|
||||
attributes.set('foo', 'bar')
|
||||
|
||||
attributes.get('foo').must_equal 'bar'
|
||||
|
@ -128,7 +128,7 @@ describe Lotus::Utils::Attributes do
|
|||
end
|
||||
|
||||
it 'sets a value (symbol)' do
|
||||
attributes = Lotus::Utils::Attributes.new
|
||||
attributes = Hanami::Utils::Attributes.new
|
||||
attributes.set(:foo, 'bar')
|
||||
|
||||
attributes.get('foo').must_equal 'bar'
|
||||
|
@ -136,7 +136,7 @@ describe Lotus::Utils::Attributes do
|
|||
end
|
||||
|
||||
it 'sets a value (number)' do
|
||||
attributes = Lotus::Utils::Attributes.new
|
||||
attributes = Hanami::Utils::Attributes.new
|
||||
attributes.set(23, 'bar')
|
||||
|
||||
attributes.get(23).must_equal 'bar'
|
||||
|
@ -147,7 +147,7 @@ describe Lotus::Utils::Attributes do
|
|||
describe '#to_h' do
|
||||
before do
|
||||
@value = Class.new do
|
||||
def lotus_nested_attributes?
|
||||
def hanami_nested_attributes?
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -157,26 +157,26 @@ describe Lotus::Utils::Attributes do
|
|||
end.new
|
||||
end
|
||||
|
||||
it 'returns an instance of ::Lotus::Utils::Hash' do
|
||||
attributes = Lotus::Utils::Attributes.new
|
||||
it 'returns an instance of ::Hanami::Utils::Hash' do
|
||||
attributes = Hanami::Utils::Attributes.new
|
||||
attributes.to_h.must_be_kind_of(::Hash)
|
||||
end
|
||||
|
||||
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'})
|
||||
end
|
||||
|
||||
it 'prevents information escape' do
|
||||
actual = Lotus::Utils::Attributes.new({'a' => 1})
|
||||
actual = Hanami::Utils::Attributes.new({'a' => 1})
|
||||
hash = actual.to_h
|
||||
hash.merge!('b' => 2)
|
||||
|
||||
actual.get('b').must_be_nil
|
||||
end
|
||||
|
||||
it 'forces ::Lotus::Utils::Hash values when a validations nested attributes is given' do
|
||||
attributes = Lotus::Utils::Attributes.new(val: @value)
|
||||
it 'forces ::Hanami::Utils::Hash values when a validations nested attributes is given' do
|
||||
attributes = Hanami::Utils::Attributes.new(val: @value)
|
||||
actual = attributes.to_h
|
||||
|
||||
actual.must_equal({'val' => { 'foo' => 'bar'}})
|
||||
|
@ -184,9 +184,9 @@ describe Lotus::Utils::Attributes do
|
|||
end
|
||||
|
||||
# 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
|
||||
attributes = Lotus::Utils::Attributes.new(val: [1, 2])
|
||||
attributes = Hanami::Utils::Attributes.new(val: [1, 2])
|
||||
actual = attributes.to_h
|
||||
|
||||
actual.must_equal({'val' => [1, 2]})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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
|
||||
@chain.size
|
||||
end
|
||||
|
@ -41,9 +41,9 @@ class Action
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Utils::Callbacks::Chain do
|
||||
describe Hanami::Utils::Callbacks::Chain do
|
||||
before do
|
||||
@chain = Lotus::Utils::Callbacks::Chain.new
|
||||
@chain = Hanami::Utils::Callbacks::Chain.new
|
||||
end
|
||||
|
||||
describe '#append' do
|
||||
|
@ -263,17 +263,17 @@ describe Lotus::Utils::Callbacks::Chain do
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Utils::Callbacks::Factory do
|
||||
describe Hanami::Utils::Callbacks::Factory do
|
||||
describe '.fabricate' do
|
||||
before do
|
||||
@callback = Lotus::Utils::Callbacks::Factory.fabricate(callback)
|
||||
@callback = Hanami::Utils::Callbacks::Factory.fabricate(callback)
|
||||
end
|
||||
|
||||
describe 'when a callable is passed' do
|
||||
let(:callback) { Callable.new }
|
||||
|
||||
it 'fabricates a Callback' do
|
||||
@callback.must_be_kind_of(Lotus::Utils::Callbacks::Callback)
|
||||
@callback.must_be_kind_of(Hanami::Utils::Callbacks::Callback)
|
||||
end
|
||||
|
||||
it 'wraps the given callback' do
|
||||
|
@ -285,7 +285,7 @@ describe Lotus::Utils::Callbacks::Factory do
|
|||
let(:callback) { :symbolize! }
|
||||
|
||||
it 'fabricates a MethodCallback' do
|
||||
@callback.must_be_kind_of(Lotus::Utils::Callbacks::MethodCallback)
|
||||
@callback.must_be_kind_of(Hanami::Utils::Callbacks::MethodCallback)
|
||||
end
|
||||
|
||||
it 'wraps the given callback' do
|
||||
|
@ -295,9 +295,9 @@ describe Lotus::Utils::Callbacks::Factory do
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Utils::Callbacks::Callback do
|
||||
describe Hanami::Utils::Callbacks::Callback do
|
||||
before do
|
||||
@callback = Lotus::Utils::Callbacks::Callback.new(callback)
|
||||
@callback = Hanami::Utils::Callbacks::Callback.new(callback)
|
||||
end
|
||||
|
||||
let(:callback) { Proc.new{|params| logger.push("set_article: #{ params[:id] }") } }
|
||||
|
@ -311,9 +311,9 @@ describe Lotus::Utils::Callbacks::Callback do
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Utils::Callbacks::MethodCallback do
|
||||
describe Hanami::Utils::Callbacks::MethodCallback do
|
||||
before do
|
||||
@callback = Lotus::Utils::Callbacks::MethodCallback.new(callback)
|
||||
@callback = Hanami::Utils::Callbacks::MethodCallback.new(callback)
|
||||
end
|
||||
|
||||
let(:callback) { :set_article }
|
||||
|
@ -327,7 +327,7 @@ describe Lotus::Utils::Callbacks::MethodCallback do
|
|||
end
|
||||
|
||||
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))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
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
|
||||
class ClassAttributeTest
|
||||
include Lotus::Utils::ClassAttribute
|
||||
include Hanami::Utils::ClassAttribute
|
||||
class_attribute :callbacks, :functions, :values
|
||||
self.callbacks = [:a]
|
||||
self.values = [1]
|
||||
|
@ -20,7 +20,7 @@ describe Lotus::Utils::ClassAttribute do
|
|||
end
|
||||
|
||||
class Vehicle
|
||||
include Lotus::Utils::ClassAttribute
|
||||
include Hanami::Utils::ClassAttribute
|
||||
class_attribute :engines, :wheels
|
||||
|
||||
self.engines = 0
|
||||
|
@ -89,7 +89,7 @@ describe Lotus::Utils::ClassAttribute do
|
|||
module Routing
|
||||
class Resource
|
||||
class Action
|
||||
include Lotus::Utils::ClassAttribute
|
||||
include Hanami::Utils::ClassAttribute
|
||||
class_attribute :verb
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils/class'
|
||||
require 'hanami/utils/class'
|
||||
|
||||
describe Lotus::Utils::Class do
|
||||
describe Hanami::Utils::Class do
|
||||
before do
|
||||
module App
|
||||
module Layer
|
||||
|
@ -21,61 +21,61 @@ describe Lotus::Utils::Class do
|
|||
|
||||
describe '.load!' 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
describe '.load_from_pattern!' 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
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
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)"
|
||||
end
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
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)"
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils/deprecation'
|
||||
require 'hanami/utils/deprecation'
|
||||
|
||||
class DeprecationTest
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -21,16 +21,16 @@ class DeprecationWrapperTest
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Utils::Deprecation do
|
||||
describe Hanami::Utils::Deprecation do
|
||||
it 'prints a deprecation warning for direct call' do
|
||||
_, err = capture_io do
|
||||
DeprecationTest.new.old_method
|
||||
end
|
||||
|
||||
stack = if Lotus::Utils.jruby?
|
||||
stack = if Hanami::Utils.jruby?
|
||||
$0 == __FILE__ ? "#{ __FILE__ }:27:in `(root)'" :
|
||||
"#{ __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__'" :
|
||||
"#{ __FILE__ }:27:in `__script__'"
|
||||
else
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
require 'set'
|
||||
require 'bigdecimal'
|
||||
require 'lotus/utils/duplicable'
|
||||
require 'hanami/utils/duplicable'
|
||||
|
||||
describe Lotus::Utils::Duplicable do
|
||||
describe Hanami::Utils::Duplicable do
|
||||
describe "#dup" do
|
||||
describe "non duplicable types" do
|
||||
before do
|
||||
|
@ -28,7 +28,7 @@ describe Lotus::Utils::Duplicable do
|
|||
end
|
||||
|
||||
it "doesn't dup symbol" do
|
||||
assert_same_duped_object :lotus
|
||||
assert_same_duped_object :hanami
|
||||
end
|
||||
|
||||
it "doesn't dup integer" do
|
||||
|
@ -62,7 +62,7 @@ describe Lotus::Utils::Duplicable do
|
|||
end
|
||||
|
||||
it "duplicates string" do
|
||||
assert_different_duped_object "Lotus"
|
||||
assert_different_duped_object "Hanami"
|
||||
end
|
||||
|
||||
it "duplicates date" do
|
||||
|
@ -84,7 +84,7 @@ describe Lotus::Utils::Duplicable do
|
|||
actual = nil
|
||||
|
||||
_, stderr = capture_io do
|
||||
actual = Lotus::Utils::Duplicable.dup(object)
|
||||
actual = Hanami::Utils::Duplicable.dup(object)
|
||||
end
|
||||
|
||||
stderr.must_be_empty
|
||||
|
@ -94,7 +94,7 @@ describe Lotus::Utils::Duplicable do
|
|||
end
|
||||
|
||||
def assert_different_duped_object(object)
|
||||
actual = Lotus::Utils::Duplicable.dup(object)
|
||||
actual = Hanami::Utils::Duplicable.dup(object)
|
||||
|
||||
actual.must_equal object
|
||||
actual.object_id.wont_equal object.object_id
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils'
|
||||
require 'lotus/utils/escape'
|
||||
require 'hanami/utils'
|
||||
require 'hanami/utils/escape'
|
||||
|
||||
describe Lotus::Utils::Escape do
|
||||
let(:mod) { Lotus::Utils::Escape }
|
||||
describe Hanami::Utils::Escape do
|
||||
let(:mod) { Hanami::Utils::Escape }
|
||||
|
||||
describe '.html' do
|
||||
TEST_ENCODINGS.each do |encoding|
|
||||
describe "#{ encoding }" 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.must_equal '&'
|
||||
end
|
||||
|
@ -120,7 +120,7 @@ describe Lotus::Utils::Escape do
|
|||
TEST_ENCODINGS.each do |encoding|
|
||||
describe "#{ encoding }" 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.must_equal '&'
|
||||
end
|
||||
|
@ -260,7 +260,7 @@ describe Lotus::Utils::Escape do
|
|||
end
|
||||
|
||||
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
|
||||
result = mod.html_attribute(char)
|
||||
|
@ -273,7 +273,7 @@ describe Lotus::Utils::Escape do
|
|||
TEST_ENCODINGS.each do |encoding|
|
||||
describe "#{ encoding }" 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.must_equal 'javascript:alert(0);'
|
||||
end
|
||||
|
@ -288,24 +288,24 @@ describe Lotus::Utils::Escape do
|
|||
result.must_equal ''
|
||||
end
|
||||
|
||||
it "escapes 'http://lotusrb.org'" do
|
||||
result = mod.url('http://lotusrb.org'.encode(encoding))
|
||||
result.must_equal 'http://lotusrb.org'
|
||||
it "escapes 'http://hanamirb.org'" do
|
||||
result = mod.url('http://hanamirb.org'.encode(encoding))
|
||||
result.must_equal 'http://hanamirb.org'
|
||||
end
|
||||
|
||||
it "escapes 'https://lotusrb.org'" do
|
||||
result = mod.url('https://lotusrb.org'.encode(encoding))
|
||||
result.must_equal 'https://lotusrb.org'
|
||||
it "escapes 'https://hanamirb.org'" do
|
||||
result = mod.url('https://hanamirb.org'.encode(encoding))
|
||||
result.must_equal 'https://hanamirb.org'
|
||||
end
|
||||
|
||||
it "escapes 'https://lotusrb.org#introduction'" do
|
||||
result = mod.url('https://lotusrb.org#introduction'.encode(encoding))
|
||||
result.must_equal 'https://lotusrb.org#introduction'
|
||||
it "escapes 'https://hanamirb.org#introduction'" do
|
||||
result = mod.url('https://hanamirb.org#introduction'.encode(encoding))
|
||||
result.must_equal 'https://hanamirb.org#introduction'
|
||||
end
|
||||
|
||||
it "escapes 'https://lotusrb.org/guides/index.html'" do
|
||||
result = mod.url('https://lotusrb.org/guides/index.html'.encode(encoding))
|
||||
result.must_equal 'https://lotusrb.org/guides/index.html'
|
||||
it "escapes 'https://hanamirb.org/guides/index.html'" do
|
||||
result = mod.url('https://hanamirb.org/guides/index.html'.encode(encoding))
|
||||
result.must_equal 'https://hanamirb.org/guides/index.html'
|
||||
end
|
||||
|
||||
it "escapes 'mailto:user@example.com'" do
|
||||
|
|
|
@ -597,8 +597,8 @@ TEST_SINGULARS = {
|
|||
"kiss" => "kisses",
|
||||
}.merge(TEST_PLURALS)
|
||||
|
||||
require 'lotus/utils/inflector'
|
||||
Lotus::Utils::Inflector.inflections do
|
||||
require 'hanami/utils/inflector'
|
||||
Hanami::Utils::Inflector.inflections do
|
||||
exception 'analysis', 'analyses'
|
||||
exception 'alga', 'algae'
|
||||
uncountable 'music', 'butter'
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
require 'test_helper'
|
||||
require 'bigdecimal'
|
||||
require 'lotus/utils/hash'
|
||||
require 'hanami/utils/hash'
|
||||
|
||||
describe Lotus::Utils::Hash do
|
||||
describe Hanami::Utils::Hash do
|
||||
describe '#initialize' 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')
|
||||
end
|
||||
|
||||
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.must_equal({'foo' => ['bar']})
|
||||
end
|
||||
|
||||
it 'accepts a Lotus::Utils::Hash' do
|
||||
arg = Lotus::Utils::Hash.new('foo' => 'bar')
|
||||
hash = Lotus::Utils::Hash.new(arg)
|
||||
it 'accepts a Hanami::Utils::Hash' do
|
||||
arg = Hanami::Utils::Hash.new('foo' => 'bar')
|
||||
hash = Hanami::Utils::Hash.new(arg)
|
||||
|
||||
hash.to_h.must_be_kind_of(::Hash)
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ describe Lotus::Utils::Hash do
|
|||
|
||||
describe '#symbolize!' do
|
||||
it 'symbolize keys' do
|
||||
hash = Lotus::Utils::Hash.new('fub' => 'baz')
|
||||
hash = Hanami::Utils::Hash.new('fub' => 'baz')
|
||||
hash.symbolize!
|
||||
|
||||
hash['fub'].must_be_nil
|
||||
|
@ -34,17 +34,17 @@ describe Lotus::Utils::Hash do
|
|||
end
|
||||
|
||||
it 'symbolize nested hashes' do
|
||||
hash = Lotus::Utils::Hash.new('nested' => {'key' => 'value'})
|
||||
hash = Hanami::Utils::Hash.new('nested' => {'key' => 'value'})
|
||||
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')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stringify!' do
|
||||
it 'covert keys to strings' do
|
||||
hash = Lotus::Utils::Hash.new(fub: 'baz')
|
||||
hash = Hanami::Utils::Hash.new(fub: 'baz')
|
||||
hash.stringify!
|
||||
|
||||
hash[:fub].must_be_nil
|
||||
|
@ -52,22 +52,22 @@ describe Lotus::Utils::Hash do
|
|||
end
|
||||
|
||||
it 'stringifies nested hashes' do
|
||||
hash = Lotus::Utils::Hash.new(nested: {key: 'value'})
|
||||
hash = Hanami::Utils::Hash.new(nested: {key: 'value'})
|
||||
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')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#deep_dup' do
|
||||
it 'returns an instance of Utils::Hash' do
|
||||
duped = Lotus::Utils::Hash.new('foo' => 'bar').deep_dup
|
||||
duped.must_be_kind_of(Lotus::Utils::Hash)
|
||||
duped = Hanami::Utils::Hash.new('foo' => 'bar').deep_dup
|
||||
duped.must_be_kind_of(Hanami::Utils::Hash)
|
||||
end
|
||||
|
||||
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['foo'] = nil
|
||||
|
@ -91,7 +91,7 @@ describe Lotus::Utils::Hash do
|
|||
'rational' => Rational(0.3)
|
||||
}
|
||||
|
||||
hash = Lotus::Utils::Hash.new(original)
|
||||
hash = Hanami::Utils::Hash.new(original)
|
||||
duped = hash.deep_dup
|
||||
|
||||
duped.must_equal(original)
|
||||
|
@ -99,7 +99,7 @@ describe Lotus::Utils::Hash do
|
|||
end
|
||||
|
||||
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['foo']['bar'].reverse!
|
||||
|
@ -110,38 +110,38 @@ describe Lotus::Utils::Hash do
|
|||
end
|
||||
|
||||
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['x'].must_be_kind_of(Lotus::Utils::Hash)
|
||||
duped['x'].must_be_kind_of(Hanami::Utils::Hash)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'hash interface' do
|
||||
it 'returns a new Lotus::Utils::Hash for methods which return a ::Hash' do
|
||||
hash = Lotus::Utils::Hash.new({'a' => 1})
|
||||
it 'returns a new Hanami::Utils::Hash for methods which return a ::Hash' do
|
||||
hash = Hanami::Utils::Hash.new({'a' => 1})
|
||||
result = hash.clear
|
||||
|
||||
assert hash.empty?
|
||||
result.must_be_kind_of(Lotus::Utils::Hash)
|
||||
result.must_be_kind_of(Hanami::Utils::Hash)
|
||||
end
|
||||
|
||||
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.must_equal ['a', 1]
|
||||
end
|
||||
|
||||
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.wont_respond_to :unknown_method
|
||||
end
|
||||
|
||||
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' }
|
||||
|
||||
assert result.empty?
|
||||
|
@ -149,7 +149,7 @@ describe Lotus::Utils::Hash do
|
|||
|
||||
describe '#to_h' 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})
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
actual = utils_hash.to_h
|
||||
|
@ -198,7 +198,7 @@ describe Lotus::Utils::Hash do
|
|||
end
|
||||
|
||||
it 'prevents information escape' do
|
||||
actual = Lotus::Utils::Hash.new({'a' => 1})
|
||||
actual = Hanami::Utils::Hash.new({'a' => 1})
|
||||
hash = actual.to_h
|
||||
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' do
|
||||
# actual = Lotus::Utils::Hash.new({'a' => {'b' => 2}})
|
||||
# actual = Hanami::Utils::Hash.new({'a' => {'b' => 2}})
|
||||
# hash = actual.to_h
|
||||
# subhash = hash['a']
|
||||
# subhash.merge!('c' => 3)
|
||||
|
@ -218,7 +218,7 @@ describe Lotus::Utils::Hash do
|
|||
|
||||
describe '#to_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})
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
actual = utils_hash.to_h
|
||||
|
@ -267,7 +267,7 @@ describe Lotus::Utils::Hash do
|
|||
end
|
||||
|
||||
it 'prevents information escape' do
|
||||
actual = Lotus::Utils::Hash.new({'a' => 1})
|
||||
actual = Hanami::Utils::Hash.new({'a' => 1})
|
||||
hash = actual.to_hash
|
||||
hash.merge!('b' => 2)
|
||||
|
||||
|
@ -277,12 +277,12 @@ describe Lotus::Utils::Hash do
|
|||
|
||||
describe '#to_a' 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]])
|
||||
end
|
||||
|
||||
it 'prevents information escape' do
|
||||
actual = Lotus::Utils::Hash.new({'a' => 1})
|
||||
actual = Hanami::Utils::Hash.new({'a' => 1})
|
||||
array = actual.to_a
|
||||
array.push(['b', 2])
|
||||
|
||||
|
@ -292,54 +292,54 @@ describe Lotus::Utils::Hash do
|
|||
|
||||
describe 'equality' do
|
||||
it 'has a working equality' do
|
||||
hash = Lotus::Utils::Hash.new({'a' => 1})
|
||||
other = Lotus::Utils::Hash.new({'a' => 1})
|
||||
hash = Hanami::Utils::Hash.new({'a' => 1})
|
||||
other = Hanami::Utils::Hash.new({'a' => 1})
|
||||
|
||||
assert hash == other
|
||||
end
|
||||
|
||||
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}
|
||||
end
|
||||
end
|
||||
|
||||
describe 'case equality' do
|
||||
it 'has a working case equality' do
|
||||
hash = Lotus::Utils::Hash.new({'a' => 1})
|
||||
other = Lotus::Utils::Hash.new({'a' => 1})
|
||||
hash = Hanami::Utils::Hash.new({'a' => 1})
|
||||
other = Hanami::Utils::Hash.new({'a' => 1})
|
||||
|
||||
assert hash === other
|
||||
end
|
||||
|
||||
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}
|
||||
end
|
||||
end
|
||||
|
||||
describe 'value equality' do
|
||||
it 'has a working value equality' do
|
||||
hash = Lotus::Utils::Hash.new({'a' => 1})
|
||||
other = Lotus::Utils::Hash.new({'a' => 1})
|
||||
hash = Hanami::Utils::Hash.new({'a' => 1})
|
||||
other = Hanami::Utils::Hash.new({'a' => 1})
|
||||
|
||||
assert hash.eql?(other)
|
||||
end
|
||||
|
||||
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})
|
||||
end
|
||||
end
|
||||
|
||||
describe '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)
|
||||
end
|
||||
|
||||
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})
|
||||
end
|
||||
end
|
||||
|
@ -347,7 +347,7 @@ describe Lotus::Utils::Hash do
|
|||
describe '#hash' do
|
||||
it 'returns the same hash result of ::Hash' do
|
||||
expected = {'l' => 23}.hash
|
||||
actual = Lotus::Utils::Hash.new({'l' => 23}).hash
|
||||
actual = Hanami::Utils::Hash.new({'l' => 23}).hash
|
||||
|
||||
actual.must_equal expected
|
||||
end
|
||||
|
@ -356,7 +356,7 @@ describe Lotus::Utils::Hash do
|
|||
describe '#inspect' do
|
||||
it 'returns the same output of ::Hash' do
|
||||
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
|
||||
end
|
||||
|
@ -365,16 +365,16 @@ describe Lotus::Utils::Hash do
|
|||
describe 'unknown method' do
|
||||
it 'raises error' do
|
||||
begin
|
||||
Lotus::Utils::Hash.new('l' => 23).party!
|
||||
Hanami::Utils::Hash.new('l' => 23).party!
|
||||
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
|
||||
|
||||
# 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
|
||||
hash = Lotus::Utils::Hash.new({'a' => 1})
|
||||
exception_message = if Lotus::Utils.rubinius?
|
||||
hash = Hanami::Utils::Hash.new({'a' => 1})
|
||||
exception_message = if Hanami::Utils.rubinius?
|
||||
"undefined method `foo' on 1:Fixnum."
|
||||
else
|
||||
"undefined method `foo' for 1:Fixnum"
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils/inflector'
|
||||
require 'lotus/utils/string'
|
||||
require 'hanami/utils/inflector'
|
||||
require 'hanami/utils/string'
|
||||
|
||||
describe Lotus::Utils::Inflector do
|
||||
describe Hanami::Utils::Inflector do
|
||||
describe '.inflections' 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 = Lotus::Utils::Inflector.singularize('algae') # see test/fixtures.rb
|
||||
actual = Hanami::Utils::Inflector.singularize('algae') # see test/fixtures.rb
|
||||
actual.must_equal 'alga'
|
||||
end
|
||||
|
||||
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 = Lotus::Utils::Inflector.pluralize('alga') # see test/fixtures.rb
|
||||
actual = Hanami::Utils::Inflector.pluralize('alga') # see test/fixtures.rb
|
||||
actual.must_equal 'algae'
|
||||
end
|
||||
|
||||
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 = Lotus::Utils::Inflector.singularize('music') # see test/fixtures.rb
|
||||
actual = Hanami::Utils::Inflector.singularize('music') # see test/fixtures.rb
|
||||
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 = Lotus::Utils::Inflector.singularize('butter') # see test/fixtures.rb
|
||||
actual = Hanami::Utils::Inflector.singularize('butter') # see test/fixtures.rb
|
||||
actual.must_equal 'butter'
|
||||
end
|
||||
end
|
||||
|
||||
describe '.pluralize' 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
|
||||
end
|
||||
|
||||
it "returns empty string when empty string is given" do
|
||||
actual = Lotus::Utils::Inflector.pluralize("")
|
||||
actual = Hanami::Utils::Inflector.pluralize("")
|
||||
actual.must_be_empty
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
it "returns instance of String" do
|
||||
result = Lotus::Utils::Inflector.pluralize("Lotus")
|
||||
result = Hanami::Utils::Inflector.pluralize("Hanami")
|
||||
result.class.must_equal ::String
|
||||
end
|
||||
|
||||
it "doesn't modify original string" do
|
||||
string = "application"
|
||||
result = Lotus::Utils::Inflector.pluralize(string)
|
||||
result = Hanami::Utils::Inflector.pluralize(string)
|
||||
|
||||
result.object_id.wont_equal(string.object_id)
|
||||
string.must_equal("application")
|
||||
|
@ -66,51 +66,51 @@ describe Lotus::Utils::Inflector do
|
|||
|
||||
TEST_PLURALS.each do |singular, plural|
|
||||
it %(pluralizes "#{ singular }" to "#{ plural }") do
|
||||
actual = Lotus::Utils::Inflector.pluralize(singular)
|
||||
actual = Hanami::Utils::Inflector.pluralize(singular)
|
||||
actual.must_equal plural
|
||||
end
|
||||
|
||||
it %(pluralizes titleized "#{ Lotus::Utils::String.new(singular).titleize }" to "#{ plural }") do
|
||||
actual = Lotus::Utils::Inflector.pluralize(Lotus::Utils::String.new(singular).titleize)
|
||||
actual.must_equal Lotus::Utils::String.new(plural).titleize
|
||||
it %(pluralizes titleized "#{ Hanami::Utils::String.new(singular).titleize }" to "#{ plural }") do
|
||||
actual = Hanami::Utils::Inflector.pluralize(Hanami::Utils::String.new(singular).titleize)
|
||||
actual.must_equal Hanami::Utils::String.new(plural).titleize
|
||||
end
|
||||
|
||||
# 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
|
||||
# end
|
||||
|
||||
# it %(doesn't pluralize titleized "#{ Lotus::Utils::String.new(singular).titleize }" as it's already plural) do
|
||||
# actual = Lotus::Utils::Inflector.pluralize(Lotus::Utils::String.new(plural).titleize)
|
||||
# actual.must_equal Lotus::Utils::String.new(plural).titleize
|
||||
# it %(doesn't pluralize titleized "#{ Hanami::Utils::String.new(singular).titleize }" as it's already plural) do
|
||||
# actual = Hanami::Utils::Inflector.pluralize(Hanami::Utils::String.new(plural).titleize)
|
||||
# actual.must_equal Hanami::Utils::String.new(plural).titleize
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.singularize' 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
|
||||
end
|
||||
|
||||
it "returns empty string when empty string is given" do
|
||||
actual = Lotus::Utils::Inflector.singularize("")
|
||||
actual = Hanami::Utils::Inflector.singularize("")
|
||||
actual.must_be_empty
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
it "returns instance of String" do
|
||||
result = Lotus::Utils::Inflector.singularize("application")
|
||||
result = Hanami::Utils::Inflector.singularize("application")
|
||||
result.class.must_equal ::String
|
||||
end
|
||||
|
||||
it "doesn't modify original string" do
|
||||
string = "applications"
|
||||
result = Lotus::Utils::Inflector.singularize(string)
|
||||
result = Hanami::Utils::Inflector.singularize(string)
|
||||
|
||||
result.object_id.wont_equal(string.object_id)
|
||||
string.must_equal("applications")
|
||||
|
@ -118,23 +118,23 @@ describe Lotus::Utils::Inflector do
|
|||
|
||||
TEST_SINGULARS.each do |singular, plural|
|
||||
it %(singularizes "#{ plural }" to "#{ singular }") do
|
||||
actual = Lotus::Utils::Inflector.singularize(plural)
|
||||
actual = Hanami::Utils::Inflector.singularize(plural)
|
||||
actual.must_equal singular
|
||||
end
|
||||
|
||||
it %(singularizes titleized "#{ Lotus::Utils::String.new(plural).titleize }" to "#{ singular }") do
|
||||
actual = Lotus::Utils::Inflector.singularize(Lotus::Utils::String.new(plural).titleize)
|
||||
actual.must_equal Lotus::Utils::String.new(singular).titleize
|
||||
it %(singularizes titleized "#{ Hanami::Utils::String.new(plural).titleize }" to "#{ singular }") do
|
||||
actual = Hanami::Utils::Inflector.singularize(Hanami::Utils::String.new(plural).titleize)
|
||||
actual.must_equal Hanami::Utils::String.new(singular).titleize
|
||||
end
|
||||
|
||||
# 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
|
||||
# end
|
||||
|
||||
# it %(doesn't singularizes titleized "#{ Lotus::Utils::String.new(plural).titleize }" as it's already singular) do
|
||||
# actual = Lotus::Utils::Inflector.singularize(Lotus::Utils::String.new(singular).titleize)
|
||||
# actual.must_equal Lotus::Utils::String.new(singular).titleize
|
||||
# it %(doesn't singularizes titleized "#{ Hanami::Utils::String.new(plural).titleize }" as it's already singular) do
|
||||
# actual = Hanami::Utils::Inflector.singularize(Hanami::Utils::String.new(singular).titleize)
|
||||
# actual.must_equal Hanami::Utils::String.new(singular).titleize
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/interactor'
|
||||
require 'hanami/interactor'
|
||||
|
||||
class InteractorWithoutInitialize
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
|
||||
def call
|
||||
end
|
||||
end
|
||||
|
||||
class InteractorWithoutCall
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
end
|
||||
|
||||
class User
|
||||
|
@ -31,7 +31,7 @@ class User
|
|||
end
|
||||
|
||||
class Signup
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
expose :user, :params
|
||||
|
||||
def initialize(params)
|
||||
|
@ -53,7 +53,7 @@ class Signup
|
|||
end
|
||||
|
||||
class ErrorInteractor
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
expose :operations
|
||||
|
||||
def initialize
|
||||
|
@ -83,7 +83,7 @@ class ErrorInteractor
|
|||
end
|
||||
|
||||
class ErrorBangInteractor
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
expose :operations
|
||||
|
||||
def initialize
|
||||
|
@ -108,7 +108,7 @@ class ErrorBangInteractor
|
|||
end
|
||||
|
||||
class PublishVideo
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
|
||||
def call
|
||||
end
|
||||
|
@ -126,7 +126,7 @@ class PublishVideo
|
|||
end
|
||||
|
||||
class CreateUser
|
||||
include Lotus::Interactor
|
||||
include Hanami::Interactor
|
||||
expose :user
|
||||
|
||||
def initialize(params)
|
||||
|
@ -151,7 +151,7 @@ class UpdateUser < CreateUser
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Interactor do
|
||||
describe Hanami::Interactor do
|
||||
describe '#initialize' do
|
||||
it "works when it isn't overridden" do
|
||||
InteractorWithoutInitialize.new
|
||||
|
@ -165,7 +165,7 @@ describe Lotus::Interactor do
|
|||
describe '#call' do
|
||||
it "returns a result" do
|
||||
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
|
||||
|
||||
it "is successful by default" do
|
||||
|
@ -237,7 +237,7 @@ describe Lotus::Interactor do
|
|||
result.operations.must_equal [:prepare!, :persist!, :log!]
|
||||
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
|
||||
interactor = PublishVideo.new
|
||||
assert !interactor.valid?, "Expected interactor to not be valid"
|
||||
|
@ -264,27 +264,27 @@ describe Lotus::Interactor do
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Interactor::Result do
|
||||
describe Hanami::Interactor::Result do
|
||||
describe '#initialize' do
|
||||
it 'allows to skip payload' do
|
||||
Lotus::Interactor::Result.new
|
||||
Hanami::Interactor::Result.new
|
||||
end
|
||||
|
||||
it 'accepts a payload' do
|
||||
result = Lotus::Interactor::Result.new(foo: 'bar')
|
||||
result = Hanami::Interactor::Result.new(foo: 'bar')
|
||||
result.foo.must_equal 'bar'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#success?' 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"
|
||||
end
|
||||
|
||||
describe "when it has errors" do
|
||||
it "isn't successful" do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.add_error "There was a problem"
|
||||
assert !result.success?, "Expected `result' to NOT be successful"
|
||||
end
|
||||
|
@ -293,7 +293,7 @@ describe Lotus::Interactor::Result do
|
|||
|
||||
describe '#fail!' do
|
||||
it 'causes a failure' do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.fail!
|
||||
|
||||
assert !result.success?, "Expected `result' to NOT be successful"
|
||||
|
@ -302,14 +302,14 @@ describe Lotus::Interactor::Result do
|
|||
|
||||
describe '#prepare!' 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.foo.must_equal 23
|
||||
end
|
||||
|
||||
it 'returns self' do
|
||||
result = Lotus::Interactor::Result.new(foo: 'bar')
|
||||
result = Hanami::Interactor::Result.new(foo: 'bar')
|
||||
returning = result.prepare!(foo: 23)
|
||||
|
||||
assert returning == result, "Expected `returning' to equal `result'"
|
||||
|
@ -318,19 +318,19 @@ describe Lotus::Interactor::Result do
|
|||
|
||||
describe "#errors" do
|
||||
it "empty by default" do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.errors.must_be :empty?
|
||||
end
|
||||
|
||||
it "returns all the errors" do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.add_error ['Error 1', 'Error 2']
|
||||
|
||||
result.errors.must_equal ['Error 1', 'Error 2']
|
||||
end
|
||||
|
||||
it "prevents information escape" do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.add_error ['Error 1', 'Error 2']
|
||||
|
||||
result.errors.clear
|
||||
|
@ -341,12 +341,12 @@ describe Lotus::Interactor::Result do
|
|||
|
||||
describe "#error" do
|
||||
it "nil by default" do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.error.must_be_nil
|
||||
end
|
||||
|
||||
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.error.must_equal 'Error 1'
|
||||
|
@ -355,21 +355,21 @@ describe Lotus::Interactor::Result do
|
|||
|
||||
describe '#respond_to?' 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?'"
|
||||
end
|
||||
|
||||
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'"
|
||||
end
|
||||
|
||||
it 'returns true for methods derived from merged payload' do
|
||||
result = Lotus::Interactor::Result.new
|
||||
result = Hanami::Interactor::Result.new
|
||||
result.prepare!('bar' => 2)
|
||||
|
||||
assert result.respond_to?(:bar), "Expected `result' to respond to `#bar'"
|
||||
|
@ -378,10 +378,10 @@ describe Lotus::Interactor::Result do
|
|||
end
|
||||
|
||||
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
|
||||
result.inspect.must_match %(#<Lotus::Interactor::Result)
|
||||
result.inspect.must_match %(#<Hanami::Interactor::Result)
|
||||
end
|
||||
|
||||
it 'reports the object_id' do
|
||||
|
@ -400,13 +400,13 @@ describe Lotus::Interactor::Result do
|
|||
|
||||
describe '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.b.must_equal 2
|
||||
end
|
||||
|
||||
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.a.must_equal 23
|
||||
|
@ -415,17 +415,17 @@ describe Lotus::Interactor::Result do
|
|||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils/io'
|
||||
require 'hanami/utils/io'
|
||||
|
||||
class IOTest
|
||||
TEST_CONSTANT = 'initial'
|
||||
end
|
||||
|
||||
describe Lotus::Utils::IO do
|
||||
describe Hanami::Utils::IO do
|
||||
describe '.silence_warnings' do
|
||||
it 'lowers verbosity of stdout' do
|
||||
_, err = capture_io do
|
||||
Lotus::Utils::IO.silence_warnings do
|
||||
Hanami::Utils::IO.silence_warnings do
|
||||
IOTest::TEST_CONSTANT = 'redefined'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'test_helper'
|
||||
require 'ostruct'
|
||||
require 'bigdecimal'
|
||||
require 'lotus/utils/kernel'
|
||||
require 'hanami/utils/kernel'
|
||||
|
||||
describe Lotus::Utils::Kernel do
|
||||
describe Hanami::Utils::Kernel do
|
||||
describe '.Array' do
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
|
@ -19,7 +19,7 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
end
|
||||
|
||||
@result = Lotus::Utils::Kernel.Array(input)
|
||||
@result = Hanami::Utils::Kernel.Array(input)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -153,7 +153,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.Set(input)
|
||||
@result = Hanami::Utils::Kernel.Set(input)
|
||||
end
|
||||
|
||||
describe 'when nil is given' do
|
||||
|
@ -259,12 +259,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BaseObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Set(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Set(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Set(input)
|
||||
Hanami::Utils::Kernel.Set(input)
|
||||
rescue => e
|
||||
e.message.must_match "can't convert into Set"
|
||||
end
|
||||
|
@ -310,7 +310,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.Hash(input)
|
||||
@result = Hanami::Utils::Kernel.Hash(input)
|
||||
end
|
||||
|
||||
describe 'when nil is given' do
|
||||
|
@ -367,12 +367,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BaseObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Hash(input)
|
||||
Hanami::Utils::Kernel.Hash(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Hash"
|
||||
end
|
||||
|
@ -383,7 +383,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -391,7 +391,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -399,7 +399,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { [1] }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -408,7 +408,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { [:a, 1] }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -417,7 +417,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Set.new([1]) }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -426,7 +426,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Set.new([:a, 1]) }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Hash(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -442,7 +442,7 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
end
|
||||
|
||||
@result = Lotus::Utils::Kernel.Integer(input)
|
||||
@result = Hanami::Utils::Kernel.Integer(input)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -575,7 +575,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -583,7 +583,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -591,7 +591,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Date.today }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -599,7 +599,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { DateTime.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -607,12 +607,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Integer(input)
|
||||
Hanami::Utils::Kernel.Integer(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Integer"
|
||||
end
|
||||
|
@ -623,12 +623,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { OpenStruct.new(color: 'purple') }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Integer(input)
|
||||
Hanami::Utils::Kernel.Integer(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Integer"
|
||||
end
|
||||
|
@ -639,7 +639,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BigDecimal.new('Infinity') }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -647,12 +647,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BigDecimal.new('NaN') }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Integer(input)
|
||||
Hanami::Utils::Kernel.Integer(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Integer"
|
||||
end
|
||||
|
@ -663,12 +663,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Complex(2,3) }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Integer(input)
|
||||
Hanami::Utils::Kernel.Integer(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Integer"
|
||||
end
|
||||
|
@ -679,12 +679,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Rational(-8) ** Rational(1, 3) }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Integer(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Integer(input)
|
||||
Hanami::Utils::Kernel.Integer(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Integer"
|
||||
end
|
||||
|
@ -695,7 +695,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 'home' }
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -704,7 +704,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { '23 street' }
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -720,7 +720,7 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
end
|
||||
|
||||
@result = Lotus::Utils::Kernel.BigDecimal(input)
|
||||
@result = Hanami::Utils::Kernel.BigDecimal(input)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -871,7 +871,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { nil }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -879,7 +879,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -887,7 +887,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -895,7 +895,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Date.today }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -903,7 +903,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { DateTime.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -911,7 +911,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Time.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -919,7 +919,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 'home' }
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -928,7 +928,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { '23.0 street' }
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -937,12 +937,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.BigDecimal(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.BigDecimal(input)
|
||||
Hanami::Utils::Kernel.BigDecimal(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into BigDecimal"
|
||||
end
|
||||
|
@ -960,7 +960,7 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
end
|
||||
|
||||
@result = Lotus::Utils::Kernel.Float(input)
|
||||
@result = Hanami::Utils::Kernel.Float(input)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -1122,7 +1122,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1130,7 +1130,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Date.today }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1146,7 +1146,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { DateTime.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1154,7 +1154,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 'home' }
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -1163,7 +1163,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { '23.0 street' }
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
@ -1172,12 +1172,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Float(input)
|
||||
Hanami::Utils::Kernel.Float(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Float"
|
||||
end
|
||||
|
@ -1188,7 +1188,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { OpenStruct.new(color: 'purple') }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1196,12 +1196,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Complex(2,3) }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Float(input)
|
||||
Hanami::Utils::Kernel.Float(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Float"
|
||||
end
|
||||
|
@ -1212,12 +1212,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Rational(-8) ** Rational(1, 3) }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Float(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Float(input)
|
||||
Hanami::Utils::Kernel.Float(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Float"
|
||||
end
|
||||
|
@ -1255,7 +1255,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.String(input)
|
||||
@result = Hanami::Utils::Kernel.String(input)
|
||||
end
|
||||
|
||||
describe 'when nil is given' do
|
||||
|
@ -1419,10 +1419,10 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
|
||||
describe 'when a symbol is given' do
|
||||
let(:input) { :lotus }
|
||||
let(:input) { :hanami }
|
||||
|
||||
it 'returns the string representation' do
|
||||
@result.must_equal 'lotus'
|
||||
@result.must_equal 'hanami'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1475,10 +1475,10 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
|
||||
describe 'when a module is given' do
|
||||
let(:input) { Lotus }
|
||||
let(:input) { Hanami }
|
||||
|
||||
it 'returns the string representation' do
|
||||
@result.must_equal 'Lotus'
|
||||
@result.must_equal 'Hanami'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1504,7 +1504,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.String(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.String(input) }.must_raise(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1532,7 +1532,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.Boolean(input)
|
||||
@result = Hanami::Utils::Kernel.Boolean(input)
|
||||
end
|
||||
|
||||
describe 'when nil is given' do
|
||||
|
@ -1629,12 +1629,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Boolean(input) }.must_raise(TypeError)
|
||||
-> { Hanami::Utils::Kernel.Boolean(input) }.must_raise(TypeError)
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Boolean(input)
|
||||
Hanami::Utils::Kernel.Boolean(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Boolean"
|
||||
end
|
||||
|
@ -1665,7 +1665,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.Date(input)
|
||||
@result = Hanami::Utils::Kernel.Date(input)
|
||||
end
|
||||
|
||||
describe 'when a date is given' do
|
||||
|
@ -1722,12 +1722,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { nil }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1738,12 +1738,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1754,12 +1754,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1770,12 +1770,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 2 }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1786,12 +1786,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 2332.903007 }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1802,12 +1802,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 'lego' }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1818,12 +1818,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { '18:55' }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Date"
|
||||
end
|
||||
|
@ -1834,12 +1834,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Date"
|
||||
end
|
||||
|
@ -1850,12 +1850,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BaseObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Date(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Date(input)
|
||||
Hanami::Utils::Kernel.Date(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Date"
|
||||
end
|
||||
|
@ -1886,7 +1886,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.DateTime(input)
|
||||
@result = Hanami::Utils::Kernel.DateTime(input)
|
||||
end
|
||||
|
||||
describe 'when a datetime is given' do
|
||||
|
@ -1967,12 +1967,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { nil }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.DateTime(input)
|
||||
Hanami::Utils::Kernel.DateTime(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into DateTime"
|
||||
end
|
||||
|
@ -1983,12 +1983,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.DateTime(input)
|
||||
Hanami::Utils::Kernel.DateTime(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into DateTime"
|
||||
end
|
||||
|
@ -1999,12 +1999,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.DateTime(input)
|
||||
Hanami::Utils::Kernel.DateTime(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into DateTime"
|
||||
end
|
||||
|
@ -2015,12 +2015,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 'crab' }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.DateTime(input)
|
||||
Hanami::Utils::Kernel.DateTime(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into DateTime"
|
||||
end
|
||||
|
@ -2031,12 +2031,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.DateTime(input)
|
||||
Hanami::Utils::Kernel.DateTime(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into DateTime"
|
||||
end
|
||||
|
@ -2047,12 +2047,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BaseObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.DateTime(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.DateTime(input)
|
||||
Hanami::Utils::Kernel.DateTime(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into DateTime"
|
||||
end
|
||||
|
@ -2083,7 +2083,7 @@ describe Lotus::Utils::Kernel do
|
|||
|
||||
describe 'successful operations' do
|
||||
before do
|
||||
@result = Lotus::Utils::Kernel.Time(input)
|
||||
@result = Hanami::Utils::Kernel.Time(input)
|
||||
end
|
||||
|
||||
describe 'when a time is given' do
|
||||
|
@ -2164,12 +2164,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { nil }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Time(input)
|
||||
Hanami::Utils::Kernel.Time(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Time"
|
||||
end
|
||||
|
@ -2180,12 +2180,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Time(input)
|
||||
Hanami::Utils::Kernel.Time(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Time"
|
||||
end
|
||||
|
@ -2196,12 +2196,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Time(input)
|
||||
Hanami::Utils::Kernel.Time(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Time"
|
||||
end
|
||||
|
@ -2212,12 +2212,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 'boat' }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Time(input)
|
||||
Hanami::Utils::Kernel.Time(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert #{input.inspect} into Time"
|
||||
end
|
||||
|
@ -2228,12 +2228,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Time(input)
|
||||
Hanami::Utils::Kernel.Time(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Time"
|
||||
end
|
||||
|
@ -2244,12 +2244,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BaseObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Time(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Time(input)
|
||||
Hanami::Utils::Kernel.Time(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Time"
|
||||
end
|
||||
|
@ -2273,7 +2273,7 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
end
|
||||
|
||||
@result = Lotus::Utils::Kernel.Pathname(input)
|
||||
@result = Hanami::Utils::Kernel.Pathname(input)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -2319,7 +2319,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { nil }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2327,7 +2327,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2335,7 +2335,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2343,7 +2343,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 12 }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2351,7 +2351,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Date.today }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2359,7 +2359,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { DateTime.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2367,7 +2367,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Time.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2375,12 +2375,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Pathname(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Pathname(input)
|
||||
Hanami::Utils::Kernel.Pathname(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Pathname"
|
||||
end
|
||||
|
@ -2398,7 +2398,7 @@ describe Lotus::Utils::Kernel do
|
|||
end
|
||||
end
|
||||
|
||||
@result = Lotus::Utils::Kernel.Symbol(input)
|
||||
@result = Hanami::Utils::Kernel.Symbol(input)
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -2435,7 +2435,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { nil }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2443,7 +2443,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { '' }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2451,7 +2451,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { true }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2459,7 +2459,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { false }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2467,7 +2467,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { 12 }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2475,7 +2475,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Date.today }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2483,7 +2483,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { DateTime.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2491,7 +2491,7 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { Time.now }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2499,12 +2499,12 @@ describe Lotus::Utils::Kernel do
|
|||
let(:input) { BasicObject.new }
|
||||
|
||||
it 'raises error' do
|
||||
-> { Lotus::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
-> { Hanami::Utils::Kernel.Symbol(input) }.must_raise TypeError
|
||||
end
|
||||
|
||||
it 'returns useful informations about the failure' do
|
||||
begin
|
||||
Lotus::Utils::Kernel.Symbol(input)
|
||||
Hanami::Utils::Kernel.Symbol(input)
|
||||
rescue => e
|
||||
e.message.must_equal "can't convert into Symbol"
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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?
|
||||
@paths.empty?
|
||||
end
|
||||
|
@ -11,20 +11,20 @@ Lotus::Utils::LoadPaths.class_eval do
|
|||
end
|
||||
end
|
||||
|
||||
describe Lotus::Utils::LoadPaths do
|
||||
describe Hanami::Utils::LoadPaths do
|
||||
describe '#initialize' do
|
||||
it 'can be initialized with zero paths' do
|
||||
paths = Lotus::Utils::LoadPaths.new
|
||||
paths = Hanami::Utils::LoadPaths.new
|
||||
paths.must_be_empty
|
||||
end
|
||||
|
||||
it 'can be initialized with one path' do
|
||||
paths = Lotus::Utils::LoadPaths.new '..'
|
||||
paths = Hanami::Utils::LoadPaths.new '..'
|
||||
paths.must_include '..'
|
||||
end
|
||||
|
||||
it 'can be initialized with more paths' do
|
||||
paths = Lotus::Utils::LoadPaths.new '..', '../..'
|
||||
paths = Hanami::Utils::LoadPaths.new '..', '../..'
|
||||
paths.must_include '..'
|
||||
paths.must_include '../..'
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#each' 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|
|
||||
path.must_be_kind_of Pathname
|
||||
|
@ -40,12 +40,12 @@ describe Lotus::Utils::LoadPaths do
|
|||
end
|
||||
|
||||
it 'remove duplicates' do
|
||||
paths = Lotus::Utils::LoadPaths.new '..', '..'
|
||||
paths = Hanami::Utils::LoadPaths.new '..', '..'
|
||||
paths.each(&Proc.new{}).size.must_equal 1
|
||||
end
|
||||
|
||||
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 { }
|
||||
|
@ -55,7 +55,7 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#push' do
|
||||
it 'adds the given path' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths.push '..'
|
||||
|
||||
paths.must_include '.'
|
||||
|
@ -63,7 +63,7 @@ describe Lotus::Utils::LoadPaths do
|
|||
end
|
||||
|
||||
it 'adds the given paths' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths.push '..', '../..'
|
||||
|
||||
paths.must_include '.'
|
||||
|
@ -72,19 +72,19 @@ describe Lotus::Utils::LoadPaths do
|
|||
end
|
||||
|
||||
it 'removes duplicates' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths.push '.', '.'
|
||||
paths.each(&Proc.new{}).size.must_equal 1
|
||||
end
|
||||
|
||||
it 'removes nil' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths.push nil
|
||||
paths.each(&Proc.new{}).size.must_equal 1
|
||||
end
|
||||
|
||||
it 'returns self so multiple operations can be performed' do
|
||||
paths = Lotus::Utils::LoadPaths.new
|
||||
paths = Hanami::Utils::LoadPaths.new
|
||||
|
||||
returning = paths.push('.')
|
||||
returning.must_be_same_as(paths)
|
||||
|
@ -99,7 +99,7 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#<< (alias of #push)' do
|
||||
it 'adds the given path' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths << '..'
|
||||
|
||||
paths.must_include '.'
|
||||
|
@ -107,14 +107,14 @@ describe Lotus::Utils::LoadPaths do
|
|||
end
|
||||
|
||||
it 'adds the given paths' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths << ['..', '../..']
|
||||
|
||||
assert paths == ['.', '..', '../..']
|
||||
end
|
||||
|
||||
it 'returns self so multiple operations can be performed' do
|
||||
paths = Lotus::Utils::LoadPaths.new
|
||||
paths = Hanami::Utils::LoadPaths.new
|
||||
|
||||
returning = paths << '.'
|
||||
returning.must_be_same_as(paths)
|
||||
|
@ -129,7 +129,7 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#dup' do
|
||||
it 'returns a copy of self' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths2 = paths.dup
|
||||
|
||||
paths << '..'
|
||||
|
@ -147,7 +147,7 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#clone' do
|
||||
it 'returns a copy of self' do
|
||||
paths = Lotus::Utils::LoadPaths.new '.'
|
||||
paths = Hanami::Utils::LoadPaths.new '.'
|
||||
paths2 = paths.clone
|
||||
|
||||
paths << '..'
|
||||
|
@ -165,14 +165,14 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#freeze' do
|
||||
it 'freezes the object' do
|
||||
paths = Lotus::Utils::LoadPaths.new
|
||||
paths = Hanami::Utils::LoadPaths.new
|
||||
paths.freeze
|
||||
|
||||
paths.must_be :frozen?
|
||||
end
|
||||
|
||||
it "doesn't allow to push paths" do
|
||||
paths = Lotus::Utils::LoadPaths.new
|
||||
paths = Hanami::Utils::LoadPaths.new
|
||||
paths.freeze
|
||||
|
||||
-> { paths.push '.' }.must_raise RuntimeError
|
||||
|
@ -181,35 +181,35 @@ describe Lotus::Utils::LoadPaths do
|
|||
|
||||
describe '#==' do
|
||||
it "checks equality with LoadPaths" do
|
||||
paths = Lotus::Utils::LoadPaths.new('.', '.')
|
||||
other = Lotus::Utils::LoadPaths.new('.')
|
||||
paths = Hanami::Utils::LoadPaths.new('.', '.')
|
||||
other = Hanami::Utils::LoadPaths.new('.')
|
||||
|
||||
other.must_equal paths
|
||||
end
|
||||
|
||||
it "it returns false if the paths aren't equal" do
|
||||
paths = Lotus::Utils::LoadPaths.new('.', '..')
|
||||
other = Lotus::Utils::LoadPaths.new('.')
|
||||
paths = Hanami::Utils::LoadPaths.new('.', '..')
|
||||
other = Hanami::Utils::LoadPaths.new('.')
|
||||
|
||||
other.wont_equal paths
|
||||
end
|
||||
|
||||
it "checks equality with Array" do
|
||||
paths = Lotus::Utils::LoadPaths.new('.', '.')
|
||||
paths = Hanami::Utils::LoadPaths.new('.', '.')
|
||||
other = ['.']
|
||||
|
||||
other.must_equal paths
|
||||
end
|
||||
|
||||
it "it returns false if given array isn't equal" do
|
||||
paths = Lotus::Utils::LoadPaths.new('.', '..')
|
||||
paths = Hanami::Utils::LoadPaths.new('.', '..')
|
||||
other = ['.']
|
||||
|
||||
other.wont_equal paths
|
||||
end
|
||||
|
||||
it "it returns false the type isn't matchable" do
|
||||
paths = Lotus::Utils::LoadPaths.new('.', '..')
|
||||
paths = Hanami::Utils::LoadPaths.new('.', '..')
|
||||
other = nil
|
||||
|
||||
other.wont_equal paths
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/logger'
|
||||
require 'hanami/logger'
|
||||
|
||||
describe Lotus::Logger do
|
||||
describe Hanami::Logger do
|
||||
|
||||
before do
|
||||
#clear defined class
|
||||
|
@ -9,14 +9,14 @@ describe Lotus::Logger do
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
it 'always use STDOUT' do
|
||||
output =
|
||||
stub_stdout_constant do
|
||||
class TestLogger < Lotus::Logger; end
|
||||
class TestLogger < Hanami::Logger; end
|
||||
logger = TestLogger.new
|
||||
logger.info('foo')
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ describe Lotus::Logger do
|
|||
it 'has application_name when log' do
|
||||
output =
|
||||
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.info('foo')
|
||||
end
|
||||
|
@ -36,13 +36,13 @@ describe Lotus::Logger do
|
|||
end
|
||||
|
||||
it 'has default app tag when not in any namespace' do
|
||||
class TestLogger < Lotus::Logger; end
|
||||
TestLogger.new.application_name.must_equal 'Lotus'
|
||||
class TestLogger < Hanami::Logger; end
|
||||
TestLogger.new.application_name.must_equal 'Hanami'
|
||||
end
|
||||
|
||||
it 'infers apptag from namespace' do
|
||||
module App2
|
||||
class TestLogger < Lotus::Logger;end
|
||||
class TestLogger < Hanami::Logger;end
|
||||
class Bar
|
||||
def hoge
|
||||
TestLogger.new.send(:application_name).must_equal 'App2'
|
||||
|
@ -53,7 +53,7 @@ describe Lotus::Logger do
|
|||
end
|
||||
|
||||
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 =
|
||||
stub_stdout_constant do
|
||||
|
@ -67,10 +67,10 @@ describe Lotus::Logger do
|
|||
stub_time_now do
|
||||
output =
|
||||
stub_stdout_constant do
|
||||
class TestLogger < Lotus::Logger;end
|
||||
class TestLogger < Hanami::Logger;end
|
||||
TestLogger.new.info('foo')
|
||||
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
|
||||
|
|
|
@ -1,152 +1,152 @@
|
|||
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
|
||||
prefix = Lotus::Utils::PathPrefix.new
|
||||
prefix = Hanami::Utils::PathPrefix.new
|
||||
assert prefix == '', "Expected #{ prefix } to equal ''"
|
||||
end
|
||||
|
||||
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'"
|
||||
end
|
||||
|
||||
describe '#join' do
|
||||
it 'returns a PathPrefix' do
|
||||
prefix = Lotus::Utils::PathPrefix.new('orders', '?').join('new')
|
||||
prefix.must_be_kind_of(Lotus::Utils::PathPrefix)
|
||||
prefix = Hanami::Utils::PathPrefix.new('orders', '?').join('new')
|
||||
prefix.must_be_kind_of(Hanami::Utils::PathPrefix)
|
||||
prefix.__send__(:separator).must_equal('?')
|
||||
end
|
||||
|
||||
it 'joins a string' do
|
||||
prefix = Lotus::Utils::PathPrefix.new('fruits')
|
||||
prefix = Hanami::Utils::PathPrefix.new('fruits')
|
||||
prefix.join('peaches').must_equal '/fruits/peaches'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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 = Lotus::Utils::PathPrefix.new('myapp')
|
||||
prefix = Hanami::Utils::PathPrefix.new('myapp')
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#relative_join' do
|
||||
it 'returns a PathPrefix' do
|
||||
prefix = Lotus::Utils::PathPrefix.new('orders', '&').relative_join('new')
|
||||
prefix.must_be_kind_of(Lotus::Utils::PathPrefix)
|
||||
prefix = Hanami::Utils::PathPrefix.new('orders', '&').relative_join('new')
|
||||
prefix.must_be_kind_of(Hanami::Utils::PathPrefix)
|
||||
prefix.__send__(:separator).must_equal('&')
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
# describe '#resolve' do
|
||||
# it 'resolves empty path' do
|
||||
# prefix = Lotus::Utils::PathPrefix.new('')
|
||||
# prefix = Hanami::Utils::PathPrefix.new('')
|
||||
# prefix.resolve.must_equal '/'
|
||||
# end
|
||||
|
||||
# it 'resolves root path path' do
|
||||
# prefix = Lotus::Utils::PathPrefix.new('/')
|
||||
# prefix = Hanami::Utils::PathPrefix.new('/')
|
||||
# prefix.resolve.must_equal '/'
|
||||
# end
|
||||
|
||||
# it 'absolutize relative path' do
|
||||
# prefix = Lotus::Utils::PathPrefix.new('coffees')
|
||||
# prefix = Hanami::Utils::PathPrefix.new('coffees')
|
||||
# prefix.resolve.must_equal '/coffees'
|
||||
# end
|
||||
|
||||
# it 'leaves untouched absolute path' do
|
||||
# prefix = Lotus::Utils::PathPrefix.new('/coffees')
|
||||
# prefix = Hanami::Utils::PathPrefix.new('/coffees')
|
||||
# prefix.resolve.must_equal '/coffees'
|
||||
# end
|
||||
|
||||
# it 'removes double leading slashes' do
|
||||
# prefix = Lotus::Utils::PathPrefix.new('//coffees')
|
||||
# prefix = Hanami::Utils::PathPrefix.new('//coffees')
|
||||
# prefix.resolve.must_equal '/coffees'
|
||||
# end
|
||||
# end
|
||||
|
@ -154,60 +154,60 @@ describe Lotus::Utils::PathPrefix do
|
|||
describe 'string interface' do
|
||||
describe 'equality' do
|
||||
it 'has a working equality' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
other = Lotus::Utils::PathPrefix.new('lotus')
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
other = Hanami::Utils::PathPrefix.new('hanami')
|
||||
|
||||
assert string == other
|
||||
end
|
||||
|
||||
it 'has a working equality with raw strings' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
assert string == 'lotus'
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
assert string == 'hanami'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'case equality' do
|
||||
it 'has a working case equality' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
other = Lotus::Utils::PathPrefix.new('lotus')
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
other = Hanami::Utils::PathPrefix.new('hanami')
|
||||
assert string === other
|
||||
end
|
||||
|
||||
it 'has a working case equality with raw strings' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
assert string === 'lotus'
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
assert string === 'hanami'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'value equality' do
|
||||
it 'has a working value equality' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
other = Lotus::Utils::PathPrefix.new('lotus')
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
other = Hanami::Utils::PathPrefix.new('hanami')
|
||||
assert string.eql?(other)
|
||||
end
|
||||
|
||||
it 'has a working value equality with raw strings' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
assert string.eql?('lotus')
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
assert string.eql?('hanami')
|
||||
end
|
||||
end
|
||||
|
||||
describe '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)
|
||||
end
|
||||
|
||||
it 'has a working identity equality with raw strings' do
|
||||
string = Lotus::Utils::PathPrefix.new('lotus')
|
||||
assert !string.equal?('lotus')
|
||||
string = Hanami::Utils::PathPrefix.new('hanami')
|
||||
assert !string.equal?('hanami')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#hash' do
|
||||
it 'returns the same hash result of ::String' do
|
||||
expected = 'hello'.hash
|
||||
actual = Lotus::Utils::PathPrefix.new('hello').hash
|
||||
actual = Hanami::Utils::PathPrefix.new('hello').hash
|
||||
|
||||
actual.must_equal expected
|
||||
end
|
||||
|
|
|
@ -1,208 +1,208 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils'
|
||||
require 'lotus/utils/string'
|
||||
require 'hanami/utils'
|
||||
require 'hanami/utils/string'
|
||||
|
||||
describe Lotus::Utils::String do
|
||||
describe Hanami::Utils::String do
|
||||
describe '#titleize' do
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
Lotus::Utils::String.new('lotus').titleize.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
Hanami::Utils::String.new('hanami').titleize.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it "doesn't mutate self" do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
string.titleize
|
||||
string.must_equal 'lotus'
|
||||
string.must_equal 'hanami'
|
||||
end
|
||||
|
||||
it 'returns an titleized string' do
|
||||
Lotus::Utils::String.new('lotus').titleize.must_equal 'Lotus'
|
||||
Lotus::Utils::String.new('LotusUtils').titleize.must_equal 'Lotus Utils'
|
||||
Lotus::Utils::String.new('lotus utils').titleize.must_equal 'Lotus Utils'
|
||||
Lotus::Utils::String.new('lotus_utils').titleize.must_equal 'Lotus Utils'
|
||||
Lotus::Utils::String.new('lotus-utils').titleize.must_equal 'Lotus Utils'
|
||||
Lotus::Utils::String.new("lotus' utils").titleize.must_equal "Lotus' Utils"
|
||||
Lotus::Utils::String.new("lotus’ utils").titleize.must_equal "Lotus’ Utils"
|
||||
Lotus::Utils::String.new("lotus` utils").titleize.must_equal "Lotus` Utils"
|
||||
Hanami::Utils::String.new('hanami').titleize.must_equal 'Hanami'
|
||||
Hanami::Utils::String.new('HanamiUtils').titleize.must_equal 'Hanami Utils'
|
||||
Hanami::Utils::String.new('hanami utils').titleize.must_equal 'Hanami Utils'
|
||||
Hanami::Utils::String.new('hanami_utils').titleize.must_equal 'Hanami Utils'
|
||||
Hanami::Utils::String.new('hanami-utils').titleize.must_equal 'Hanami Utils'
|
||||
Hanami::Utils::String.new("hanami' utils").titleize.must_equal "Hanami' Utils"
|
||||
Hanami::Utils::String.new("hanami’ utils").titleize.must_equal "Hanami’ Utils"
|
||||
Hanami::Utils::String.new("hanami` utils").titleize.must_equal "Hanami` Utils"
|
||||
# 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
|
||||
|
||||
describe '#capitalize' do
|
||||
# it 'returns an instance of Lotus::Utils::String' do
|
||||
# Lotus::Utils::String.new('lotus').capitalize.must_be_kind_of(Lotus::Utils::String)
|
||||
# it 'returns an instance of Hanami::Utils::String' do
|
||||
# Hanami::Utils::String.new('hanami').capitalize.must_be_kind_of(Hanami::Utils::String)
|
||||
# end
|
||||
|
||||
# it "doesn't mutate self" do
|
||||
# string = Lotus::Utils::String.new('lotus')
|
||||
# string = Hanami::Utils::String.new('hanami')
|
||||
# string.capitalize
|
||||
# string.must_equal 'lotus'
|
||||
# string.must_equal 'hanami'
|
||||
# end
|
||||
|
||||
it 'returns an capitalized string' do
|
||||
Lotus::Utils::String.new('lotus').capitalize.must_equal 'Lotus'
|
||||
Lotus::Utils::String.new('LotusUtils').capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new('lotus utils').capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new('lotus_utils').capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new('lotus-utils').capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new("lotus' utils").capitalize.must_equal "Lotus' utils"
|
||||
Lotus::Utils::String.new("lotus’ utils").capitalize.must_equal "Lotus’ utils"
|
||||
Lotus::Utils::String.new("lotus` utils").capitalize.must_equal "Lotus` utils"
|
||||
Hanami::Utils::String.new('hanami').capitalize.must_equal 'Hanami'
|
||||
Hanami::Utils::String.new('HanamiUtils').capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new('hanami utils').capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new('hanami_utils').capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new('hanami-utils').capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new("hanami' utils").capitalize.must_equal "Hanami' utils"
|
||||
Hanami::Utils::String.new("hanami’ utils").capitalize.must_equal "Hanami’ utils"
|
||||
Hanami::Utils::String.new("hanami` utils").capitalize.must_equal "Hanami` utils"
|
||||
# Ruby's upcase works only with ASCII chars.
|
||||
# Lotus::Utils::String.new("è vero?").capitalize.must_equal "È vero?"
|
||||
Lotus::Utils::String.new('OneTwoThree').capitalize.must_equal 'One two three'
|
||||
Lotus::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'
|
||||
Lotus::Utils::String.new('one-two-three').capitalize.must_equal 'One two three'
|
||||
# Hanami::Utils::String.new("è vero?").capitalize.must_equal "È vero?"
|
||||
Hanami::Utils::String.new('OneTwoThree').capitalize.must_equal 'One two three'
|
||||
Hanami::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'
|
||||
Hanami::Utils::String.new('one-two-three').capitalize.must_equal 'One two three'
|
||||
|
||||
Lotus::Utils::String.new(:LotusUtils).capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new(:'lotus utils').capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new(:lotus_utils).capitalize.must_equal 'Lotus utils'
|
||||
Lotus::Utils::String.new(:'lotus-utils').capitalize.must_equal 'Lotus utils'
|
||||
Hanami::Utils::String.new(:HanamiUtils).capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new(:'hanami utils').capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new(:hanami_utils).capitalize.must_equal 'Hanami utils'
|
||||
Hanami::Utils::String.new(:'hanami-utils').capitalize.must_equal 'Hanami utils'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#classify' do
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
Lotus::Utils::String.new('lotus').classify.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
Hanami::Utils::String.new('hanami').classify.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it 'returns a classified string' do
|
||||
Lotus::Utils::String.new('lotus').classify.must_equal('Lotus')
|
||||
Lotus::Utils::String.new('lotus_router').classify.must_equal('LotusRouter')
|
||||
Lotus::Utils::String.new('lotus-router').classify.must_equal('Lotus::Router')
|
||||
Lotus::Utils::String.new('lotus/router').classify.must_equal('Lotus::Router')
|
||||
Lotus::Utils::String.new('lotus::router').classify.must_equal('Lotus::Router')
|
||||
Lotus::Utils::String.new('lotus::router/base_object').classify.must_equal('Lotus::Router::BaseObject')
|
||||
Hanami::Utils::String.new('hanami').classify.must_equal('Hanami')
|
||||
Hanami::Utils::String.new('hanami_router').classify.must_equal('HanamiRouter')
|
||||
Hanami::Utils::String.new('hanami-router').classify.must_equal('Hanami::Router')
|
||||
Hanami::Utils::String.new('hanami/router').classify.must_equal('Hanami::Router')
|
||||
Hanami::Utils::String.new('hanami::router').classify.must_equal('Hanami::Router')
|
||||
Hanami::Utils::String.new('hanami::router/base_object').classify.must_equal('Hanami::Router::BaseObject')
|
||||
end
|
||||
|
||||
it 'returns a classified string from symbol' do
|
||||
Lotus::Utils::String.new(:lotus).classify.must_equal('Lotus')
|
||||
Lotus::Utils::String.new(:lotus_router).classify.must_equal('LotusRouter')
|
||||
Lotus::Utils::String.new(:'lotus-router').classify.must_equal('Lotus::Router')
|
||||
Lotus::Utils::String.new(:'lotus/router').classify.must_equal('Lotus::Router')
|
||||
Lotus::Utils::String.new(:'lotus::router').classify.must_equal('Lotus::Router')
|
||||
Hanami::Utils::String.new(:hanami).classify.must_equal('Hanami')
|
||||
Hanami::Utils::String.new(:hanami_router).classify.must_equal('HanamiRouter')
|
||||
Hanami::Utils::String.new(:'hanami-router').classify.must_equal('Hanami::Router')
|
||||
Hanami::Utils::String.new(:'hanami/router').classify.must_equal('Hanami::Router')
|
||||
Hanami::Utils::String.new(:'hanami::router').classify.must_equal('Hanami::Router')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#underscore' do
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
Lotus::Utils::String.new('Lotus').underscore.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
Hanami::Utils::String.new('Hanami').underscore.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it "doesn't mutate self" do
|
||||
string = Lotus::Utils::String.new('Lotus')
|
||||
string = Hanami::Utils::String.new('Hanami')
|
||||
string.underscore
|
||||
string.must_equal 'Lotus'
|
||||
string.must_equal 'Hanami'
|
||||
end
|
||||
|
||||
it 'removes all the upcase characters' do
|
||||
string = Lotus::Utils::String.new('Lotus')
|
||||
string.underscore.must_equal 'lotus'
|
||||
string = Hanami::Utils::String.new('Hanami')
|
||||
string.underscore.must_equal 'hanami'
|
||||
end
|
||||
|
||||
it 'transforms camel case class names' do
|
||||
string = Lotus::Utils::String.new('LotusView')
|
||||
string.underscore.must_equal 'lotus_view'
|
||||
string = Hanami::Utils::String.new('HanamiView')
|
||||
string.underscore.must_equal 'hanami_view'
|
||||
end
|
||||
|
||||
it 'substitutes double colons with path separators' do
|
||||
string = Lotus::Utils::String.new('Lotus::Utils::String')
|
||||
string.underscore.must_equal 'lotus/utils/string'
|
||||
string = Hanami::Utils::String.new('Hanami::Utils::String')
|
||||
string.underscore.must_equal 'hanami/utils/string'
|
||||
end
|
||||
|
||||
it 'handles acronyms' do
|
||||
string = Lotus::Utils::String.new('APIDoc')
|
||||
string = Hanami::Utils::String.new('APIDoc')
|
||||
string.underscore.must_equal 'api_doc'
|
||||
end
|
||||
|
||||
it 'handles numbers' do
|
||||
string = Lotus::Utils::String.new('Lucky23Action')
|
||||
string = Hanami::Utils::String.new('Lucky23Action')
|
||||
string.underscore.must_equal 'lucky23_action'
|
||||
end
|
||||
|
||||
it 'handles dashes' do
|
||||
string = Lotus::Utils::String.new('lotus-utils')
|
||||
string.underscore.must_equal 'lotus_utils'
|
||||
string = Hanami::Utils::String.new('hanami-utils')
|
||||
string.underscore.must_equal 'hanami_utils'
|
||||
end
|
||||
|
||||
it 'handles spaces' do
|
||||
string = Lotus::Utils::String.new('Lotus Utils')
|
||||
string.underscore.must_equal 'lotus_utils'
|
||||
string = Hanami::Utils::String.new('Hanami Utils')
|
||||
string.underscore.must_equal 'hanami_utils'
|
||||
end
|
||||
|
||||
it 'handles accented letters' do
|
||||
string = Lotus::Utils::String.new('è vero')
|
||||
string = Hanami::Utils::String.new('è vero')
|
||||
string.underscore.must_equal 'è_vero'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dasherize' do
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
Lotus::Utils::String.new('Lotus').dasherize.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
Hanami::Utils::String.new('Hanami').dasherize.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it "doesn't mutate self" do
|
||||
string = Lotus::Utils::String.new('Lotus')
|
||||
string = Hanami::Utils::String.new('Hanami')
|
||||
string.dasherize
|
||||
string.must_equal 'Lotus'
|
||||
string.must_equal 'Hanami'
|
||||
end
|
||||
|
||||
it 'removes all the upcase characters' do
|
||||
string = Lotus::Utils::String.new('Lotus')
|
||||
string.dasherize.must_equal 'lotus'
|
||||
string = Hanami::Utils::String.new('Hanami')
|
||||
string.dasherize.must_equal 'hanami'
|
||||
end
|
||||
|
||||
it 'transforms camel case class names' do
|
||||
string = Lotus::Utils::String.new('LotusView')
|
||||
string.dasherize.must_equal 'lotus-view'
|
||||
string = Hanami::Utils::String.new('HanamiView')
|
||||
string.dasherize.must_equal 'hanami-view'
|
||||
end
|
||||
|
||||
it 'handles acronyms' do
|
||||
string = Lotus::Utils::String.new('APIDoc')
|
||||
string = Hanami::Utils::String.new('APIDoc')
|
||||
string.dasherize.must_equal 'api-doc'
|
||||
end
|
||||
|
||||
it 'handles numbers' do
|
||||
string = Lotus::Utils::String.new('Lucky23Action')
|
||||
string = Hanami::Utils::String.new('Lucky23Action')
|
||||
string.dasherize.must_equal 'lucky23-action'
|
||||
end
|
||||
|
||||
it 'handles underscores' do
|
||||
string = Lotus::Utils::String.new('lotus_utils')
|
||||
string.dasherize.must_equal 'lotus-utils'
|
||||
string = Hanami::Utils::String.new('hanami_utils')
|
||||
string.dasherize.must_equal 'hanami-utils'
|
||||
end
|
||||
|
||||
it 'handles spaces' do
|
||||
string = Lotus::Utils::String.new('Lotus Utils')
|
||||
string.dasherize.must_equal 'lotus-utils'
|
||||
string = Hanami::Utils::String.new('Hanami Utils')
|
||||
string.dasherize.must_equal 'hanami-utils'
|
||||
end
|
||||
|
||||
it 'handles accented letters' do
|
||||
string = Lotus::Utils::String.new('è vero')
|
||||
string = Hanami::Utils::String.new('è vero')
|
||||
string.dasherize.must_equal 'è-vero'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#demodulize' do
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
Lotus::Utils::String.new('Lotus').demodulize.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
Hanami::Utils::String.new('Hanami').demodulize.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it 'returns the class name without the namespace' do
|
||||
Lotus::Utils::String.new('String').demodulize.must_equal('String')
|
||||
Lotus::Utils::String.new('Lotus::Utils::String').demodulize.must_equal('String')
|
||||
Hanami::Utils::String.new('String').demodulize.must_equal('String')
|
||||
Hanami::Utils::String.new('Hanami::Utils::String').demodulize.must_equal('String')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#namespace' do
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
Lotus::Utils::String.new('Lotus').namespace.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
Hanami::Utils::String.new('Hanami').namespace.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it 'returns the top level module name' do
|
||||
Lotus::Utils::String.new('String').namespace.must_equal('String')
|
||||
Lotus::Utils::String.new('Lotus::Utils::String').namespace.must_equal('Lotus')
|
||||
Hanami::Utils::String.new('String').namespace.must_equal('String')
|
||||
Hanami::Utils::String.new('Hanami::Utils::String').namespace.must_equal('Hanami')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -211,37 +211,37 @@ describe Lotus::Utils::String do
|
|||
@logger = []
|
||||
end
|
||||
|
||||
it 'returns an instance of Lotus::Utils::String' do
|
||||
string = Lotus::Utils::String.new('Lotus::(Utils|App)')
|
||||
it 'returns an instance of Hanami::Utils::String' do
|
||||
string = Hanami::Utils::String.new('Hanami::(Utils|App)')
|
||||
string.tokenize do |token|
|
||||
@logger.push token
|
||||
end
|
||||
|
||||
@logger.each do |token|
|
||||
token.must_be_kind_of(Lotus::Utils::String)
|
||||
token.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
end
|
||||
|
||||
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|
|
||||
@logger.push token
|
||||
end
|
||||
|
||||
@logger.must_equal(['Lotus::Utils', 'Lotus::App'])
|
||||
@logger.must_equal(['Hanami::Utils', 'Hanami::App'])
|
||||
end
|
||||
|
||||
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|
|
||||
@logger.push token
|
||||
end
|
||||
|
||||
@logger.must_equal(['Lotus'])
|
||||
@logger.must_equal(['Hanami'])
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -251,18 +251,18 @@ describe Lotus::Utils::String do
|
|||
@singular, @plural = *TEST_PLURALS.to_a.sample
|
||||
end
|
||||
|
||||
it 'returns a Lotus::Utils::String instance' do
|
||||
result = Lotus::Utils::String.new(@singular).pluralize
|
||||
result.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns a Hanami::Utils::String instance' do
|
||||
result = Hanami::Utils::String.new(@singular).pluralize
|
||||
result.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
it 'pluralizes string' do
|
||||
result = Lotus::Utils::String.new(@singular).pluralize
|
||||
result = Hanami::Utils::String.new(@singular).pluralize
|
||||
result.must_equal(@plural)
|
||||
end
|
||||
|
||||
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.must_equal(@singular)
|
||||
|
@ -270,55 +270,55 @@ describe Lotus::Utils::String do
|
|||
end
|
||||
|
||||
describe "#rsub" do
|
||||
it 'returns a Lotus::Utils::String instance' do
|
||||
result = Lotus::Utils::String.new('authors/books/index').rsub(//, '')
|
||||
result.must_be_kind_of(Lotus::Utils::String)
|
||||
it 'returns a Hanami::Utils::String instance' do
|
||||
result = Hanami::Utils::String.new('authors/books/index').rsub(//, '')
|
||||
result.must_be_kind_of(Hanami::Utils::String)
|
||||
end
|
||||
|
||||
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.must_equal('authors/books/index')
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
it 'accepts Lotus::Utils::String as replacement' do
|
||||
replacement = Lotus::Utils::String.new('#')
|
||||
result = Lotus::Utils::String.new('authors/books/index').rsub(/\//, replacement)
|
||||
it 'accepts Hanami::Utils::String as replacement' do
|
||||
replacement = Hanami::Utils::String.new('#')
|
||||
result = Hanami::Utils::String.new('authors/books/index').rsub(/\//, replacement)
|
||||
|
||||
result.must_equal('authors/books#index')
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'string interface' do
|
||||
it 'responds to ::String methods and returns a new Lotus::Utils::String' do
|
||||
string = Lotus::Utils::String.new("Lotus\n").chomp
|
||||
string.must_equal 'Lotus'
|
||||
string.must_be_kind_of Lotus::Utils::String
|
||||
it 'responds to ::String methods and returns a new Hanami::Utils::String' do
|
||||
string = Hanami::Utils::String.new("Hanami\n").chomp
|
||||
string.must_equal 'Hanami'
|
||||
string.must_be_kind_of Hanami::Utils::String
|
||||
end
|
||||
|
||||
it 'responds to ::String methods and only returns a new Lotus::Utils::String when the return value is a string' do
|
||||
string = Lotus::Utils::String.new('abcdef')
|
||||
it 'responds to ::String methods and only returns a new Hanami::Utils::String when the return value is a string' do
|
||||
string = Hanami::Utils::String.new('abcdef')
|
||||
string.casecmp('abcde').must_equal 1
|
||||
end
|
||||
|
||||
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.wont_respond_to :unknown_method
|
||||
|
@ -326,60 +326,60 @@ describe Lotus::Utils::String do
|
|||
|
||||
describe 'equality' do
|
||||
it 'has a working equality' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
other = Lotus::Utils::String.new('lotus')
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
other = Hanami::Utils::String.new('hanami')
|
||||
|
||||
assert string == other
|
||||
end
|
||||
|
||||
it 'has a working equality with raw strings' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
assert string == 'lotus'
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
assert string == 'hanami'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'case equality' do
|
||||
it 'has a working case equality' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
other = Lotus::Utils::String.new('lotus')
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
other = Hanami::Utils::String.new('hanami')
|
||||
assert string === other
|
||||
end
|
||||
|
||||
it 'has a working case equality with raw strings' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
assert string === 'lotus'
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
assert string === 'hanami'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'value equality' do
|
||||
it 'has a working value equality' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
other = Lotus::Utils::String.new('lotus')
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
other = Hanami::Utils::String.new('hanami')
|
||||
assert string.eql?(other)
|
||||
end
|
||||
|
||||
it 'has a working value equality with raw strings' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
assert string.eql?('lotus')
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
assert string.eql?('hanami')
|
||||
end
|
||||
end
|
||||
|
||||
describe '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)
|
||||
end
|
||||
|
||||
it 'has a working identity equality with raw strings' do
|
||||
string = Lotus::Utils::String.new('lotus')
|
||||
assert !string.equal?('lotus')
|
||||
string = Hanami::Utils::String.new('hanami')
|
||||
assert !string.equal?('hanami')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#hash' do
|
||||
it 'returns the same hash result of ::String' do
|
||||
expected = 'hello'.hash
|
||||
actual = Lotus::Utils::String.new('hello').hash
|
||||
actual = Hanami::Utils::String.new('hello').hash
|
||||
|
||||
actual.must_equal expected
|
||||
end
|
||||
|
@ -389,16 +389,16 @@ describe Lotus::Utils::String do
|
|||
describe 'unknown method' do
|
||||
it 'raises error' do
|
||||
begin
|
||||
Lotus::Utils::String.new('one').yay!
|
||||
Hanami::Utils::String.new('one').yay!
|
||||
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
|
||||
|
||||
# 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
|
||||
string = Lotus::Utils::String.new('/path/to/something')
|
||||
exception_message = if Lotus::Utils.rubinius?
|
||||
string = Hanami::Utils::String.new('/path/to/something')
|
||||
exception_message = if Hanami::Utils.rubinius?
|
||||
%(undefined method `boom' on an instance of String.)
|
||||
else # MRI
|
||||
%(undefined method `boom' for "/":String)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require 'test_helper'
|
||||
require 'lotus/utils'
|
||||
require 'hanami/utils'
|
||||
|
||||
describe Lotus::Utils do
|
||||
describe Hanami::Utils do
|
||||
describe '.jruby?' do
|
||||
it 'introspects the current platform' do
|
||||
if RUBY_PLATFORM == 'java'
|
||||
assert Lotus::Utils.jruby?, 'expected JRuby platform'
|
||||
assert Hanami::Utils.jruby?, 'expected JRuby platform'
|
||||
else
|
||||
assert !Lotus::Utils.jruby?, 'expected non JRuby platform'
|
||||
assert !Hanami::Utils.jruby?, 'expected non JRuby platform'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -15,9 +15,9 @@ describe Lotus::Utils do
|
|||
describe '.rubinius?' do
|
||||
it 'introspects the current platform' do
|
||||
if RUBY_ENGINE == 'rbx'
|
||||
assert Lotus::Utils.rubinius?, 'expected Rubinius platform'
|
||||
assert Hanami::Utils.rubinius?, 'expected Rubinius platform'
|
||||
else
|
||||
assert !Lotus::Utils.rubinius?, 'expected non Rubinius platform'
|
||||
assert !Hanami::Utils.rubinius?, 'expected non Rubinius platform'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
describe Lotus::Utils::VERSION do
|
||||
describe Hanami::Utils::VERSION do
|
||||
it 'exposes version' do
|
||||
Lotus::Utils::VERSION.must_equal '0.6.1'
|
||||
Hanami::Utils::VERSION.must_equal '0.7.0'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue