diff --git a/.travis.yml b/.travis.yml index a4e81274..6f73125a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,23 +7,9 @@ script: - 'bundle install' - 'bundle exec rake test:coverage' 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 - - rbx-2 + - 2.2 + - 2.3 + - ruby-head - jruby-9000 - jruby-head @@ -32,5 +18,5 @@ addons: matrix: allow_failures: - - rvm: rbx-2 + - rvm: ruby-head - rvm: jruby-head diff --git a/CHANGELOG.md b/CHANGELOG.md index ccee3971..913e1480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,20 @@ -# Lotus::Model -A persistence layer for Lotus +# Hanami::Model +A persistence layer for Hanami ## v0.5.2 - 2016-01-19 ### Changed -- [Sean Collins] Improved error message for `Lotus::Model::Adapters::NoAdapterError` +- [Sean Collins] Improved error message for `Hanami::Model::Adapters::NoAdapterError` ### Fixed -- [Kyle Chong & Trung Lê] Catch Sequel exceptions and re-raise as `Lotus::Model::Error` +- [Kyle Chong & Trung Lê] Catch Sequel exceptions and re-raise as `Hanami::Model::Error` ## v0.5.1 - 2016-01-12 ### Added -- [Taylor Finnell] Let `Lotus::Model::Configuration#adapter` to accept arbitrary options (eg. `adapter type: :sql, uri: 'jdbc:...', after_connect: Proc.new { |connection| connection.auto_commit(true) }`) +- [Taylor Finnell] Let `Hanami::Model::Configuration#adapter` to accept arbitrary options (eg. `adapter type: :sql, uri: 'jdbc:...', after_connect: Proc.new { |connection| connection.auto_commit(true) }`) ### Changed - [Andrey Deryabin] Improved `Entity#inspect` -- [Karim Tarek] Introduced `Lotus::Model::Error` and let all the framework exceptions to inherit from it. +- [Karim Tarek] Introduced `Hanami::Model::Error` and let all the framework exceptions to inherit from it. ### Fixed - [Luca Guidi] Improved error message when trying to use a repository without mapping the corresponding collections @@ -53,9 +53,9 @@ A persistence layer for Lotus ## v0.3.1 - 2015-05-15 ### Added -- [Dmitry Tymchuk] Dirty tracking for entities (via `Lotus::Entity::DirtyTracking` module to include) +- [Dmitry Tymchuk] Dirty tracking for entities (via `Hanami::Entity::DirtyTracking` module to include) - [My Mai] Automatic update of timestamps when an entity is persisted. -- [Peter Berkenbosch] Introduced `Lotus::Repository#execute`, to execute raw query/commands against database (eg. `BookRepository.execute "SELECT * FROM users"` or `BookRepository.execute "UPDATE users SET admin = 'f'"`) +- [Peter Berkenbosch] Introduced `Hanami::Repository#execute`, to execute raw query/commands against database (eg. `BookRepository.execute "SELECT * FROM users"` or `BookRepository.execute "UPDATE users SET admin = 'f'"`) - [Guilherme Franco] Memory and File System adapters now accept a block for `where`, `or`, `and` conditions (eg `where { age > 33 }`). ### Fixed @@ -67,13 +67,13 @@ A persistence layer for Lotus ### Fixed - [Alfonso Uceda Pompa] Don't send unwanted null values to the database, while coercing entities -- [Jan Lelis] Do not define top-level `Boolean`, because it is already defined by `lotus-utils` +- [Jan Lelis] Do not define top-level `Boolean`, because it is already defined by `hanami-utils` - [Vsevolod Romashov] Fix entity class resolving in `Coercer#from_record` - [Jason Harrelson] Add file and line to `instance_eval` in `Coercer` to make backtrace more usable ## v0.2.4 - 2015-02-20 ### Fixed -- [Luca Guidi] When duplicate the framework don't copy over the original `Lotus::Model` configuration +- [Luca Guidi] When duplicate the framework don't copy over the original `Hanami::Model` configuration ## v0.2.3 - 2015-02-13 ### Added @@ -88,7 +88,7 @@ A persistence layer for Lotus ## v0.2.1 - 2015-01-12 ### Added -- [Luca Guidi] Compatibility between Lotus::Entity and Lotus::Validations +- [Luca Guidi] Compatibility between Hanami::Entity and Hanami::Validations ## v0.2.0 - 2014-12-23 ### Added @@ -97,17 +97,17 @@ A persistence layer for Lotus - [Trung Lê] Introduced `Entity#update` for bulk update of attributes - [Luca Guidi] Improved error when try to use a repository which wasn't configured or when the framework wasn't loaded yet - [Trung Lê] Introduced `Entity#to_h` -- [Trung Lê] Introduced `Lotus::Model.duplicate` -- [Trung Lê] Made `Lotus::Mapper` lazy +- [Trung Lê] Introduced `Hanami::Model.duplicate` +- [Trung Lê] Made `Hanami::Mapper` lazy - [Trung Lê] Introduced thread safe autoloading for adapters - [Felipe Sere] Add support for `Symbol` coercion - [Celso Fernandes] Add support for `BigDecimal` coercion -- [Trung Lê] Introduced `Lotus::Model.load!` as entry point for loading +- [Trung Lê] Introduced `Hanami::Model.load!` as entry point for loading - [Trung Lê] Introduced `Mapper#repository` as DSL to associate a repository to a collection - [Trung Lê & Tao Guo] Introduced `Configuration#mapping` as DSL to configure the mapping - [Coen Wessels] Allow `where`, `exclude` and `or` to accept blocks - [Trung Lê & Tao Guo] Introduced `Configuration#adapter` as DSL to configure the adapter -- [Trung Lê] Introduced `Lotus::Model::Configuration` +- [Trung Lê] Introduced `Hanami::Model::Configuration` ### Changed - [Trung Lê] Changed `Entity.attributes=` to `Entity.attributes` @@ -121,21 +121,21 @@ A persistence layer for Lotus ## v0.1.2 - 2014-06-26 ### Fixed -- [Stanislav Spiridonov] Ensure to require `'lotus/model/mapping/coercions'` +- [Stanislav Spiridonov] Ensure to require `'hanami/model/mapping/coercions'` - [Krzysztof Zalewski] `Entity` defines `#id` accessor by default ## v0.1.1 - 2014-06-23 ### Added -- [Luca Guidi] Introduced `Lotus::Model::Mapping::Coercions` in order to decouple from `Lotus::Utils::Kernel` +- [Luca Guidi] Introduced `Hanami::Model::Mapping::Coercions` in order to decouple from `Hanami::Utils::Kernel` - [Luca Guidi] Official support for Ruby 2.1 ## v0.1.0 - 2014-04-23 ### Added - [Luca Guidi] Allow to inject coercer into mapper - [Luca Guidi] Introduced database mapping -- [Luca Guidi] Introduced `Lotus::Entity` +- [Luca Guidi] Introduced `Hanami::Entity` - [Luca Guidi] Introduced SQL adapter - [Luca Guidi] Introduced memory adapter – [Luca Guidi] Introduced adapters for repositories -- [Luca Guidi] Introduced `Lotus::Repository` +- [Luca Guidi] Introduced `Hanami::Repository` diff --git a/EXAMPLE.md b/EXAMPLE.md index 35feac8b..f1e88ed7 100644 --- a/EXAMPLE.md +++ b/EXAMPLE.md @@ -1,6 +1,6 @@ -# Lotus::Model +# Hanami::Model -This is a guide that helps you to get started with [**Lotus::Model**](https://github.com/lotus/model). +This is a guide that helps you to get started with [**Hanami::Model**](https://github.com/hanami/model). You can find the full code source [here](https://gist.github.com/jodosha/11211048). ## Gems @@ -11,7 +11,7 @@ First of all, we need to setup a `Gemfile`. source 'https://rubygems.org' gem 'sqlite3' -gem 'lotus-model' +gem 'hanami-model' ``` Then we can fetch the dependencies with `bundle install`. @@ -20,7 +20,7 @@ Then we can fetch the dependencies with `bundle install`. -**Lotus::Model** doesn't have migrations. +**Hanami::Model** doesn't have migrations. For this example we will use [Sequel](http://sequel.jeremyevans.net). We create the database first. Then we create two tables: `authors` and `articles`. @@ -28,8 +28,8 @@ Then we create two tables: `authors` and `articles`. ```ruby require 'bundler/setup' require 'sqlite3' -require 'lotus/model' -require 'lotus/model/adapters/sql_adapter' +require 'hanami/model' +require 'hanami/model/adapters/sql_adapter' connection_uri = "sqlite://#{ __dir__ }/test.db" @@ -52,7 +52,7 @@ end ## Entities We have two entities in our application: `Author` and `Article`. -`Author` is a `Struct`, Lotus::Model can persist it. +`Author` is a `Struct`, Hanami::Model can persist it. `Article` has a small API concerning its publishing process. ```ruby @@ -63,7 +63,7 @@ Author = Struct.new(:id, :name) do end class Article - include Lotus::Entity + include Hanami::Entity attributes :author_id, :title, :comments_count, :published # id is implicit def published? @@ -82,11 +82,11 @@ In order to persist and query the entities above, we define two corresponding re ```ruby class AuthorRepository - include Lotus::Repository + include Hanami::Repository end class ArticleRepository - include Lotus::Repository + include Hanami::Repository def self.most_recent_by_author(author, limit = 8) query do @@ -127,7 +127,7 @@ end ## Loading ```ruby -Lotus::Model.configure do +Hanami::Model.configure do adapter type: :sql, uri: connection_uri mapping do @@ -162,10 +162,10 @@ author = Author.new(name: 'Luca') AuthorRepository.create(author) articles = [ - Article.new(title: 'Announcing Lotus', author_id: author.id, comments_count: 123, published: true), - Article.new(title: 'Introducing Lotus::Router', author_id: author.id, comments_count: 63, published: true), - Article.new(title: 'Introducing Lotus::Controller', author_id: author.id, comments_count: 82, published: true), - Article.new(title: 'Introducing Lotus::Model', author_id: author.id) + Article.new(title: 'Announcing Hanami', author_id: author.id, comments_count: 123, published: true), + Article.new(title: 'Introducing Hanami::Router', author_id: author.id, comments_count: 63, published: true), + Article.new(title: 'Introducing Hanami::Controller', author_id: author.id, comments_count: 82, published: true), + Article.new(title: 'Introducing Hanami::Model', author_id: author.id) ] articles.each do |article| diff --git a/Gemfile b/Gemfile index cdfab495..04aa9fc5 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,8 @@ unless ENV['TRAVIS'] gem 'yard', require: false end -gem 'lotus-utils', '~> 0.6', require: false, github: 'lotus/utils', branch: '0.6.x' -gem 'lotus-validations', '~> 0.4', require: false, github: 'lotus/validations', branch: '0.4.x' +gem 'hanami-utils', '~> 0.7', require: false, github: 'hanami/utils', branch: '0.7.x' +gem 'hanami-validations', '~> 0.5', require: false, github: 'hanami/validations', branch: '0.5.x' platforms :ruby do gem 'sqlite3', require: false diff --git a/README.md b/README.md index a68a30ce..f4a77a6c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Lotus::Model +# Hanami::Model -A persistence framework for [Lotus](http://lotusrb.org). +A persistence framework for [Hanami](http://hanamirb.org). It delivers a convenient public API to execute queries and commands against a database. The architecture eases keeping the business logic (entities) separated from details such as persistence or validations. @@ -13,36 +13,36 @@ It implements the following concepts: * [Adapter](#adapter) – A database adapter. * [Query](#query) - An object that represents a database query. -Like all the other Lotus components, it can be used as a standalone framework or within a full Lotus application. +Like all the other Hanami components, it can be used as a standalone framework or within a full Hanami application. ## Status -[![Gem Version](https://badge.fury.io/rb/lotus-model.svg)](http://badge.fury.io/rb/lotus-model) -[![Build Status](https://secure.travis-ci.org/lotus/model.svg?branch=master)](http://travis-ci.org/lotus/model?branch=master) -[![Coverage](https://img.shields.io/coveralls/lotus/model/master.svg)](https://coveralls.io/r/lotus/model) -[![Code Climate](https://img.shields.io/codeclimate/github/lotus/model.svg)](https://codeclimate.com/github/lotus/model) -[![Dependencies](https://gemnasium.com/lotus/model.svg)](https://gemnasium.com/lotus/model) -[![Inline docs](http://inch-ci.org/github/lotus/model.png)](http://inch-ci.org/github/lotus/model) +[![Gem Version](https://badge.fury.io/rb/hanami-model.svg)](http://badge.fury.io/rb/hanami-model) +[![Build Status](https://secure.travis-ci.org/hanami/model.svg?branch=master)](http://travis-ci.org/hanami/model?branch=master) +[![Coverage](https://img.shields.io/coveralls/hanami/model/master.svg)](https://coveralls.io/r/hanami/model) +[![Code Climate](https://img.shields.io/codeclimate/github/hanami/model.svg)](https://codeclimate.com/github/hanami/model) +[![Dependencies](https://gemnasium.com/hanami/model.svg)](https://gemnasium.com/hanami/model) +[![Inline docs](http://inch-ci.org/github/hanami/model.png)](http://inch-ci.org/github/hanami/model) ## Contact -* Home page: http://lotusrb.org -* Mailing List: http://lotusrb.org/mailing-list -* API Doc: http://rdoc.info/gems/lotus-model -* Bugs/Issues: https://github.com/lotus/model/issues -* Support: http://stackoverflow.com/questions/tagged/lotus-ruby -* Chat: https://chat.lotusrb.org +* Home page: http://hanamirb.org +* Mailing List: http://hanamirb.org/mailing-list +* API Doc: http://rdoc.info/gems/hanami-model +* Bugs/Issues: https://github.com/hanami/model/issues +* Support: http://stackoverflow.com/questions/tagged/hanami +* Chat: https://chat.hanamirb.org ## Rubies -__Lotus::Model__ supports Ruby (MRI) 2+ and JRuby 9000+ +__Hanami::Model__ supports Ruby (MRI) 2+ and JRuby 9000+ ## Installation Add this line to your application's Gemfile: ```ruby -gem 'lotus-model' +gem 'hanami-model' ``` And then execute: @@ -51,25 +51,25 @@ And then execute: Or install it yourself as: - $ gem install lotus-model + $ gem install hanami-model ## Usage This class provides a DSL to configure adapter, mapping and collection. ```ruby -require 'lotus/model' +require 'hanami/model' class User - include Lotus::Entity + include Hanami::Entity attributes :name, :age end class UserRepository - include Lotus::Repository + include Hanami::Repository end -Lotus::Model.configure do +Hanami::Model.configure do adapter type: :sql, uri: 'postgres://localhost/database' mapping do @@ -84,7 +84,7 @@ Lotus::Model.configure do end end -Lotus::Model.load! +Hanami::Model.load! user = User.new(name: 'Luca', age: 32) user = UserRepository.create(user) @@ -113,21 +113,21 @@ This simplicity of design allows developers to focus on behaviors, or message passing if you will, which is the quintessence of Object Oriented Programming. ```ruby -require 'lotus/model' +require 'hanami/model' class Person - include Lotus::Entity + include Hanami::Entity attributes :name, :age end ``` -When a class includes `Lotus::Entity` it receives the following interface: +When a class includes `Hanami::Entity` it receives the following interface: * `#id` * `#id=` * `#initialize(attributes = {})` -`Lotus::Entity` also provides the `.attributes` for defining attribute accessors for the given names. +`Hanami::Entity` also provides the `.attributes` for defining attribute accessors for the given names. If we expand the code above in **pure Ruby**, it would be: @@ -141,22 +141,22 @@ class Person end ``` -**Lotus::Model** ships `Lotus::Entity` for developers's convenience. +**Hanami::Model** ships `Hanami::Entity` for developers's convenience. -**Lotus::Model** depends on a narrow and well-defined interface for an Entity - `#id`, `#id=`, `#initialize(attributes={})`. -If your object implements that interface then that object can be used as an Entity in the **Lotus::Model** framework. +**Hanami::Model** depends on a narrow and well-defined interface for an Entity - `#id`, `#id=`, `#initialize(attributes={})`. +If your object implements that interface then that object can be used as an Entity in the **Hanami::Model** framework. -However, we suggest to implement this interface by including `Lotus::Entity`, in case that future versions of the framework will expand it. +However, we suggest to implement this interface by including `Hanami::Entity`, in case that future versions of the framework will expand it. See [Dependency Inversion Principle](http://en.wikipedia.org/wiki/Dependency_inversion_principle) for more on interfaces. -When a class extends a `Lotus::Entity` class, it will also *inherit* its mother's attributes. +When a class extends a `Hanami::Entity` class, it will also *inherit* its mother's attributes. ```ruby -require 'lotus/model' +require 'hanami/model' class Article - include Lotus::Entity + include Hanami::Entity attributes :name end @@ -190,7 +190,7 @@ This architecture has several advantages: * Multiple data sources can easily coexist in an application -When a class includes `Lotus::Repository`, it will receive the following interface: +When a class includes `Hanami::Repository`, it will receive the following interface: * `.persist(entity)` – Create or update an entity * `.create(entity)` – Create a record for the given entity @@ -230,10 +230,10 @@ This is **bad** for a variety of reasons: There is a better way: ```ruby -require 'lotus/model' +require 'hanami/model' class ArticleRepository - include Lotus::Repository + include Hanami::Repository def self.most_recent_by_author(author, limit = 8) query do @@ -260,7 +260,7 @@ Here is an extended example of a repository that uses the SQL adapter. ```ruby class ArticleRepository - include Lotus::Repository + include Hanami::Repository def self.most_recent_by_author(author, limit = 8) query do @@ -312,7 +312,7 @@ module RepositoryHelpers end class ArticleRepository - include Lotus::Repository + include Hanami::Repository extend RepositoryHelpers::Pagination def self.published @@ -328,24 +328,24 @@ end That will allow `.paginate` usage on `ArticleRepository`, for example: `ArticleRepository.published.paginate(15, 0)` -**Your models and repositories have to be in the same namespace.** Otherwise `Lotus::Model::Mapper#load!` +**Your models and repositories have to be in the same namespace.** Otherwise `Hanami::Model::Mapper#load!` will not initialize your repositories correctly. ```ruby -class MyLotusApp::Model::User - include Lotus::Entity +class MyHanamiApp::Model::User + include Hanami::Entity # your code here end # This repository will work... -class MyLotusApp::Model::UserRepository - include Lotus::Repository +class MyHanamiApp::Model::UserRepository + include Hanami::Repository # your code here end # ...this will not! -class MyLotusApp::Repository::UserRepository - include Lotus::Repository +class MyHanamiApp::Repository::UserRepository + include Hanami::Repository # your code here end ``` @@ -358,9 +358,9 @@ It is database independent, it can work with SQL, document, and even with key/va The role of a data mapper is to translate database columns into the corresponding attribute of an entity. ```ruby -require 'lotus/model' +require 'hanami/model' -mapper = Lotus::Model::Mapper.new do +mapper = Hanami::Model::Mapper.new do collection :users do entity User @@ -382,10 +382,10 @@ For advanced mapping and legacy databases, please have a look at the API doc. Note there are limitations with inherited entities: ```ruby -require 'lotus/model' +require 'hanami/model' class Article - include Lotus::Entity + include Hanami::Entity attributes :name end @@ -393,7 +393,7 @@ class RareArticle < Article attributes :price end -mapper = Lotus::Model::Mapper.new do +mapper = Hanami::Model::Mapper.new do collection :articles do entity Article @@ -413,7 +413,7 @@ the result is an `Article` not `RareArticle`. ### Adapter An adapter is a concrete implementation of persistence logic for a specific database. -**Lotus::Model** is shipped with three adapters: +**Hanami::Model** is shipped with three adapters: * SqlAdapter * MemoryAdapter @@ -423,14 +423,14 @@ An adapter can be associated with one or multiple repositories. ```ruby require 'pg' -require 'lotus/model' -require 'lotus/model/adapters/sql_adapter' +require 'hanami/model' +require 'hanami/model/adapters/sql_adapter' -mapper = Lotus::Model::Mapper.new do +mapper = Hanami::Model::Mapper.new do # ... end -adapter = Lotus::Model::Adapters::SqlAdapter.new(mapper, 'postgres://host:port/database') +adapter = Hanami::Model::Adapters::SqlAdapter.new(mapper, 'postgres://host:port/database') PersonRepository.adapter = adapter ArticleRepository.adapter = adapter @@ -466,7 +466,7 @@ Here is common interface for existing class: * `.join` - Adds an inner join with a table (only SQL) * `.left_join` - Adds a left join with a table (only SQL) -If you need more information regarding those methods, you can use comments from [memory](https://github.com/lotus/model/blob/master/lib/lotus/model/adapters/memory/query.rb#L29) or [sql](https://github.com/lotus/model/blob/master/lib/lotus/model/adapters/sql/query.rb#L28) adapters interface. +If you need more information regarding those methods, you can use comments from [memory](https://github.com/hanami/model/blob/master/lib/hanami/model/adapters/memory/query.rb#L29) or [sql](https://github.com/hanami/model/blob/master/lib/hanami/model/adapters/sql/query.rb#L28) adapters interface. Think of an adapter for Redis, it will probably employ different strategies to filter records than an SQL query object. @@ -479,9 +479,9 @@ Think of an adapter for Redis, it will probably employ different strategies to f * Non-standard repository can be configured for an entity, by setting `repository` on the collection. ```ruby - require 'lotus/model' + require 'hanami/model' - mapper = Lotus::Model::Mapper.new do + mapper = Hanami::Model::Mapper.new do collection :users do entity User repository EmployeeRepository @@ -491,16 +491,16 @@ Think of an adapter for Redis, it will probably employ different strategies to f ### Thread safety -**Lotus::Model**'s is thread safe during the runtime, but it isn't during the loading process. +**Hanami::Model**'s is thread safe during the runtime, but it isn't during the loading process. The mapper compiles some code internally, be sure to safely load it before your application starts. ```ruby Mutex.new.synchronize do - Lotus::Model.load! + Hanami::Model.load! end ``` -**This is not necessary, when Lotus::Model is used within a Lotus application.** +**This is not necessary, when Hanami::Model is used within a Hanami application.** ## Features @@ -509,18 +509,18 @@ end If an entity has the following accessors: `:created_at` and `:updated_at`, they will be automatically updated when the entity is persisted. ```ruby -require 'lotus/model' +require 'hanami/model' class User - include Lotus::Entity + include Hanami::Entity attributes :name, :created_at, :updated_at end class UserRepository - include Lotus::Repository + include Hanami::Repository end -Lotus::Model.configure do +Hanami::Model.configure do adapter type: :memory, uri: 'memory://localhost/timestamps' mapping do @@ -553,22 +553,22 @@ puts user.updated_at.to_s # => "2015-05-15T10:12:23+00:00" ### Dirty Tracking -Entities are able to track changes of their data, if `Lotus::Entity::DirtyTracking` is included. +Entities are able to track changes of their data, if `Hanami::Entity::DirtyTracking` is included. ```ruby -require 'lotus/model' +require 'hanami/model' class User - include Lotus::Entity - include Lotus::Entity::DirtyTracking + include Hanami::Entity + include Hanami::Entity::DirtyTracking attributes :name, :age end class UserRepository - include Lotus::Repository + include Hanami::Repository end -Lotus::Model.configure do +Hanami::Model.configure do adapter type: :memory, uri: 'memory://localhost/dirty_tracking' mapping do @@ -606,17 +606,17 @@ result.changed? # => false ## Example -For a full working example, have a look at [EXAMPLE.md](https://github.com/lotus/model/blob/master/EXAMPLE.md). -Please remember that the setup code is only required for the standalone usage of **Lotus::Model**. -A **Lotus** application will handle that configurations for you. +For a full working example, have a look at [EXAMPLE.md](https://github.com/hanami/model/blob/master/EXAMPLE.md). +Please remember that the setup code is only required for the standalone usage of **Hanami::Model**. +A **Hanami** application will handle that configurations for you. ## Versioning -__Lotus::Model__ uses [Semantic Versioning 2.0.0](http://semver.org) +__Hanami::Model__ uses [Semantic Versioning 2.0.0](http://semver.org) ## Contributing -1. Fork it ( https://github.com/lotus/model/fork ) +1. Fork it ( https://github.com/hanami/model/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`) @@ -625,3 +625,4 @@ __Lotus::Model__ 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-model`). diff --git a/lotus-model.gemspec b/hanami-model.gemspec similarity index 73% rename from lotus-model.gemspec rename to hanami-model.gemspec index 9ca0df29..3ef81702 100644 --- a/lotus-model.gemspec +++ b/hanami-model.gemspec @@ -1,25 +1,25 @@ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'lotus/model/version' +require 'hanami/model/version' Gem::Specification.new do |spec| - spec.name = 'lotus-model' - spec.version = Lotus::Model::VERSION + spec.name = 'hanami-model' + spec.version = Hanami::Model::VERSION spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda'] spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com'] - spec.summary = %q{A persistence layer for Lotus} + spec.summary = %q{A persistence layer for Hanami} spec.description = %q{A persistence framework with entities, repositories, data mapper and query objects} - spec.homepage = 'http://lotusrb.org' + spec.homepage = 'http://hanamirb.org' spec.license = 'MIT' - spec.files = `git ls-files -z -- lib/* CHANGELOG.md EXAMPLE.md LICENSE.md README.md lotus-model.gemspec`.split("\x0") + spec.files = `git ls-files -z -- lib/* CHANGELOG.md EXAMPLE.md LICENSE.md README.md hanami-model.gemspec`.split("\x0") 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'] spec.required_ruby_version = '>= 2.0.0' - spec.add_runtime_dependency 'lotus-utils', '~> 0.6' + spec.add_runtime_dependency 'hanami-utils', '~> 0.6' spec.add_runtime_dependency 'sequel', '~> 4.9' spec.add_development_dependency 'bundler', '~> 1.6' diff --git a/lib/hanami-model.rb b/lib/hanami-model.rb new file mode 100644 index 00000000..1372783d --- /dev/null +++ b/lib/hanami-model.rb @@ -0,0 +1 @@ +require 'hanami/model' diff --git a/lib/lotus/entity.rb b/lib/hanami/entity.rb similarity index 82% rename from lib/lotus/entity.rb rename to lib/hanami/entity.rb index 860131e2..64b404a6 100644 --- a/lib/lotus/entity.rb +++ b/lib/hanami/entity.rb @@ -1,7 +1,7 @@ -require 'lotus/utils/kernel' -require 'lotus/utils/attributes' +require 'hanami/utils/kernel' +require 'hanami/utils/attributes' -module Lotus +module Hanami # An object that is defined by its identity. # See "Domain Driven Design" by Eric Evans. # @@ -17,21 +17,21 @@ module Lotus # message passing if you will, which is the quintessence of Object Oriented # Programming. # - # @example With Lotus::Entity - # require 'lotus/model' + # @example With Hanami::Entity + # require 'hanami/model' # # class Person - # include Lotus::Entity + # include Hanami::Entity # attributes :name, :age # end # - # When a class includes `Lotus::Entity` it receives the following interface: + # When a class includes `Hanami::Entity` it receives the following interface: # # * #id # * #id= # * #initialize(attributes = {}) # - # `Lotus::Entity` also provides the `.attributes=` for defining attribute accessors for the given names. + # `Hanami::Entity` also provides the `.attributes=` for defining attribute accessors for the given names. # # If we expand the code above in **pure Ruby**, it would be: # @@ -44,39 +44,39 @@ module Lotus # end # end # - # **Lotus::Model** ships `Lotus::Entity` for developers's convenience. + # **Hanami::Model** ships `Hanami::Entity` for developers's convenience. # - # **Lotus::Model** depends on a narrow and well-defined interface for an + # **Hanami::Model** depends on a narrow and well-defined interface for an # Entity - `#id`, `#id=`, `#initialize(attributes={})`.If your object # implements that interface then that object can be used as an Entity in the - # **Lotus::Model** framework. + # **Hanami::Model** framework. # # However, we suggest to implement this interface by including - # `Lotus::Entity`, in case that future versions of the framework will expand + # `Hanami::Entity`, in case that future versions of the framework will expand # it. # # See Dependency Inversion Principle for more on interfaces. # # @since 0.1.0 # - # @see Lotus::Repository + # @see Hanami::Repository module Entity # Inject the public API into the hosting class. # # @since 0.1.0 # # @example With Object - # require 'lotus/model' + # require 'hanami/model' # # class User - # include Lotus::Entity + # include Hanami::Entity # end # # @example With Struct - # require 'lotus/model' + # require 'hanami/model' # # User = Struct.new(:id, :name) do - # include Lotus::Entity + # include Hanami::Entity # end def self.included(base) base.class_eval do @@ -102,37 +102,37 @@ module ClassMethods # # @since 0.2.0 # - # @see Lotus::Repository - # @see Lotus::Model::Mapper + # @see Hanami::Repository + # @see Hanami::Model::Mapper # # @example - # require 'lotus/model' + # require 'hanami/model' # # class User - # include Lotus::Entity + # include Hanami::Entity # attributes :name, :age # end # User.attributes => # # # @example Given params is array of attributes - # require 'lotus/model' + # require 'hanami/model' # # class User - # include Lotus::Entity + # include Hanami::Entity # attributes [:name, :age] # end # User.attributes => # # # @example Extend entity - # require 'lotus/model' + # require 'hanami/model' # # class User - # include Lotus::Entity + # include Hanami::Entity # attributes :name # end # # class DeletedUser < User - # include Lotus::Entity + # include Hanami::Entity # attributes :deleted_at # end # @@ -142,7 +142,7 @@ module ClassMethods def attributes(*attrs) return @attributes ||= Set.new unless attrs.any? - Lotus::Utils::Kernel.Array(attrs).each do |attr| + Hanami::Utils::Kernel.Array(attrs).each do |attr| if allowed_attribute_name?(attr) define_attr_accessor(attr) self.attributes << attr @@ -211,9 +211,9 @@ def ==(other) # @since 0.2.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # class User - # include Lotus::Entity + # include Hanami::Entity # attributes :name # end # @@ -228,9 +228,9 @@ def to_h # @since 0.5.1 # # @example - # require 'lotus/model' + # require 'hanami/model' # class User - # include Lotus::Entity + # include Hanami::Entity # attributes :name # end # @@ -247,9 +247,9 @@ def attribute_names # @since 0.5.1 # # @example - # require 'lotus/model' + # require 'hanami/model' # class User - # include Lotus::Entity + # include Hanami::Entity # attributes :name, :email # end # @@ -270,9 +270,9 @@ def inspect # @since 0.2.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # class User - # include Lotus::Entity + # include Hanami::Entity # attributes :name # end # diff --git a/lib/lotus/entity/dirty_tracking.rb b/lib/hanami/entity/dirty_tracking.rb similarity index 85% rename from lib/lotus/entity/dirty_tracking.rb rename to lib/hanami/entity/dirty_tracking.rb index e9e68d17..564e20ca 100644 --- a/lib/lotus/entity/dirty_tracking.rb +++ b/lib/hanami/entity/dirty_tracking.rb @@ -1,15 +1,15 @@ -module Lotus +module Hanami module Entity # Dirty tracking for entities # # @since 0.3.1 # # @example Dirty tracking - # require 'lotus/model' + # require 'hanami/model' # # class User - # include Lotus::Entity - # include Lotus::Entity::DirtyTracking + # include Hanami::Entity + # include Hanami::Entity::DirtyTracking # # attributes :name # end @@ -28,7 +28,7 @@ module DirtyTracking # # @since 0.3.1 # - # @see Lotus::Entity#initialize + # @see Hanami::Entity#initialize def initialize(attributes = {}) super @_initial_state = Utils::Hash.new(to_h).deep_dup @@ -43,11 +43,11 @@ def initialize(attributes = {}) # @since 0.3.1 # # @example - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity - # include Lotus::Entity::DirtyTracking + # include Hanami::Entity + # include Hanami::Entity::DirtyTracking # # attributes :title # end diff --git a/lib/lotus/model.rb b/lib/hanami/model.rb similarity index 66% rename from lib/lotus/model.rb rename to lib/hanami/model.rb index 3b8b3dec..7f289ca7 100644 --- a/lib/lotus/model.rb +++ b/lib/hanami/model.rb @@ -1,12 +1,12 @@ -require 'lotus/model/version' -require 'lotus/entity' -require 'lotus/entity/dirty_tracking' -require 'lotus/repository' -require 'lotus/model/mapper' -require 'lotus/model/configuration' -require 'lotus/model/error' +require 'hanami/model/version' +require 'hanami/entity' +require 'hanami/entity/dirty_tracking' +require 'hanami/repository' +require 'hanami/model/mapper' +require 'hanami/model/configuration' +require 'hanami/model/error' -module Lotus +module Hanami # Model # # @since 0.1.0 @@ -16,8 +16,8 @@ module Model # # @since 0.1.0 # - # @see Lotus::Repository.update - class NonPersistedEntityError < Lotus::Model::Error + # @see Hanami::Repository.update + class NonPersistedEntityError < Hanami::Model::Error end # Error for invalid mapper configuration @@ -25,14 +25,14 @@ class NonPersistedEntityError < Lotus::Model::Error # # @since 0.2.0 # - # @see Lotus::Configuration#mapping - class InvalidMappingError < Lotus::Model::Error + # @see Hanami::Configuration#mapping + class InvalidMappingError < Hanami::Model::Error end # Error for invalid raw command syntax # # @since 0.5.0 - class InvalidCommandError < Lotus::Model::Error + class InvalidCommandError < Hanami::Model::Error def initialize(message = "Invalid command") super end @@ -41,7 +41,7 @@ def initialize(message = "Invalid command") # Error for invalid raw query syntax # # @since 0.3.1 - class InvalidQueryError < Lotus::Model::Error + class InvalidQueryError < Hanami::Model::Error def initialize(message = "Invalid query") super end @@ -63,12 +63,12 @@ def initialize(message = "Invalid query") # # @since 0.2.0 # - # @see Lotus::Model + # @see Hanami::Model # # @example - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # adapter type: :sql, uri: 'postgres://localhost/database' # # mapping do @@ -82,7 +82,7 @@ def initialize(message = "Invalid query") # end # # Adapter MUST follow the convention in which adapter class is inflection of adapter name - # The above example has name :sql, thus derived class will be `Lotus::Model::Adapters::SqlAdapter` + # The above example has name :sql, thus derived class will be `Hanami::Model::Adapters::SqlAdapter` def self.configure(&blk) configuration.instance_eval(&blk) self @@ -104,49 +104,49 @@ def self.unload! configuration.unload! end - # Duplicate Lotus::Model in order to create a new separated instance + # Duplicate Hanami::Model in order to create a new separated instance # of the framework. # # The new instance of the framework will be completely decoupled from the # original. It will inherit the configuration, but all the changes that # happen after the duplication, won't be reflected on the other copies. # - # @return [Module] a copy of Lotus::Model + # @return [Module] a copy of Hanami::Model # # @since 0.2.0 # @api private # # @example Basic usage - # require 'lotus/model' + # require 'hanami/model' # # module MyApp - # Model = Lotus::Model.dupe + # Model = Hanami::Model.dupe # end # - # MyApp::Model == Lotus::Model # => false + # MyApp::Model == Hanami::Model # => false # # MyApp::Model.configuration == - # Lotus::Model.configuration # => false + # Hanami::Model.configuration # => false # # @example Inheriting configuration - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # adapter type: :sql, uri: 'sqlite3://uri' # end # # module MyApp - # Model = Lotus::Model.dupe + # Model = Hanami::Model.dupe # end # # module MyApi - # Model = Lotus::Model.dupe + # Model = Hanami::Model.dupe # Model.configure do # adapter type: :sql, uri: 'postgresql://uri' # end # end # - # Lotus::Model.configuration.adapter_config.uri # => 'sqlite3://uri' + # Hanami::Model.configuration.adapter_config.uri # => 'sqlite3://uri' # MyApp::Model.configuration.adapter_config.uri # => 'sqlite3://uri' # MyApi::Model.configuration.adapter_config.uri # => 'postgresql://uri' def self.dupe @@ -160,18 +160,18 @@ def self.dupe # @param mod [Module] the Ruby namespace of the application # @param blk [Proc] an optional block to configure the framework # - # @return [Module] a copy of Lotus::Model + # @return [Module] a copy of Hanami::Model # # @since 0.2.0 # - # @see Lotus::Model#dupe - # @see Lotus::Model::Configuration + # @see Hanami::Model#dupe + # @see Hanami::Model::Configuration # # @example Basic usage - # require 'lotus/model' + # require 'hanami/model' # # module MyApp - # Model = Lotus::Model.dupe + # Model = Hanami::Model.dupe # end # # # It will: @@ -180,25 +180,25 @@ def self.dupe # # 2. Generate MyApp::Entity # # 3. Generate MyApp::Repository # - # MyApp::Model == Lotus::Model # => false - # MyApp::Repository == Lotus::Repository # => false + # MyApp::Model == Hanami::Model # => false + # MyApp::Repository == Hanami::Repository # => false # # @example Block usage - # require 'lotus/model' + # require 'hanami/model' # # module MyApp - # Model = Lotus::Model.duplicate(self) do + # Model = Hanami::Model.duplicate(self) do # adapter type: :memory, uri: 'memory://localhost' # end # end # - # Lotus::Model.configuration.adapter_config # => nil - # MyApp::Model.configuration.adapter_config # => # + # Hanami::Model.configuration.adapter_config # => nil + # MyApp::Model.configuration.adapter_config # => # def self.duplicate(mod, &blk) dupe.tap do |duplicated| mod.module_eval %{ - Entity = Lotus::Entity.dup - Repository = Lotus::Repository.dup + Entity = Hanami::Entity.dup + Repository = Hanami::Repository.dup } duplicated.configure(&blk) if block_given? diff --git a/lib/lotus/model/adapters/abstract.rb b/lib/hanami/model/adapters/abstract.rb similarity index 91% rename from lib/lotus/model/adapters/abstract.rb rename to lib/hanami/model/adapters/abstract.rb index 8ccc921f..eae85e45 100644 --- a/lib/lotus/model/adapters/abstract.rb +++ b/lib/hanami/model/adapters/abstract.rb @@ -1,6 +1,6 @@ -require 'lotus/utils/basic_object' +require 'hanami/utils/basic_object' -module Lotus +module Hanami module Model module Adapters # It's raised when an adapter can't find the underlying database adapter. @@ -8,10 +8,10 @@ module Adapters # Example: When we try to use the SqlAdapter with a Postgres database # but we didn't loaded the pg gem before. # - # @see Lotus::Model::Adapters::SqlAdapter#initialize + # @see Hanami::Model::Adapters::SqlAdapter#initialize # # @since 0.1.0 - class DatabaseAdapterNotFound < Lotus::Model::Error + class DatabaseAdapterNotFound < Hanami::Model::Error end # It's raised when an adapter does not support a feature. @@ -19,17 +19,17 @@ class DatabaseAdapterNotFound < Lotus::Model::Error # Example: When we try to get a connection string for the current database # but the adapter has not implemented it. # - # @see Lotus::Model::Adapters::Abstract#connection_string + # @see Hanami::Model::Adapters::Abstract#connection_string # # @since 0.3.0 - class NotSupportedError < Lotus::Model::Error + class NotSupportedError < Hanami::Model::Error end # It's raised when an operation is requested to an adapter after it was # disconnected. # # @since 0.5.0 - class DisconnectedAdapterError < Lotus::Model::Error + class DisconnectedAdapterError < Hanami::Model::Error def initialize super "You have tried to perform an operation on a disconnected adapter" end @@ -55,9 +55,9 @@ def initialize # @api private # @since 0.5.0 # - # @see Lotus::Model::Adapters::Abstract#disconnect - # @see Lotus::Model::Adapters::MemoryAdapter#disconnect - # @see Lotus::Model::Adapters::FileSystemAdapter#disconnect + # @see Hanami::Model::Adapters::Abstract#disconnect + # @see Hanami::Model::Adapters::MemoryAdapter#disconnect + # @see Hanami::Model::Adapters::FileSystemAdapter#disconnect class DisconnectedResource < Utils::BasicObject def method_missing(method_name, *) ::Kernel.raise DisconnectedAdapterError.new @@ -69,7 +69,7 @@ def method_missing(method_name, *) # An adapter is a concrete implementation that allows a repository to # communicate with a single database. # - # Lotus::Model is shipped with Memory and SQL adapters. + # Hanami::Model is shipped with Memory and SQL adapters. # Third part adapters MUST implement the interface defined here. # For convenience they may inherit from this class. # @@ -80,7 +80,7 @@ def method_missing(method_name, *) class Abstract # Initialize the adapter # - # @param mapper [Lotus::Model::Mapper] the object that defines the + # @param mapper [Hanami::Model::Mapper] the object that defines the # database to entities mapping # # @param uri [String] the optional connection string to the database @@ -228,8 +228,8 @@ def query(collection, &blk) # # @param options [Hash] options for transaction # - # @see Lotus::Model::Adapters::SqlAdapter#transaction - # @see Lotus::Model::Adapters::MemoryAdapter#transaction + # @see Hanami::Model::Adapters::SqlAdapter#transaction + # @see Hanami::Model::Adapters::MemoryAdapter#transaction # # @since 0.2.3 def transaction(options = {}) diff --git a/lib/lotus/model/adapters/file_system_adapter.rb b/lib/hanami/model/adapters/file_system_adapter.rb similarity index 94% rename from lib/lotus/model/adapters/file_system_adapter.rb rename to lib/hanami/model/adapters/file_system_adapter.rb index 6652047b..f8e3cdcd 100644 --- a/lib/lotus/model/adapters/file_system_adapter.rb +++ b/lib/hanami/model/adapters/file_system_adapter.rb @@ -1,8 +1,8 @@ require 'thread' require 'pathname' -require 'lotus/model/adapters/memory_adapter' +require 'hanami/model/adapters/memory_adapter' -module Lotus +module Hanami module Model module Adapters # In memory adapter with file system persistence. @@ -22,8 +22,8 @@ module Adapters # The persistence policy uses Ruby `Marshal` `dump` and `load` operations. # Please be aware of the limitations this model. # - # @see Lotus::Model::Adapters::Implementation - # @see Lotus::Model::Adapters::MemoryAdapter + # @see Hanami::Model::Adapters::Implementation + # @see Hanami::Model::Adapters::MemoryAdapter # @see http://www.ruby-doc.org/core/Marshal.html # # @api private @@ -61,9 +61,9 @@ class FileSystemAdapter < MemoryAdapter # @param uri [String] the connection uri # @param options [Hash] a hash of non-mandatory adapter options # - # @return [Lotus::Model::Adapters::FileSystemAdapter] + # @return [Hanami::Model::Adapters::FileSystemAdapter] # - # @see Lotus::Model::Mapper + # @see Hanami::Model::Mapper # # @api private # @since 0.2.0 @@ -201,9 +201,9 @@ def clear(collection) # @param blk [Proc] a block of code to be executed in the context of # the query. # - # @return [Lotus::Model::Adapters::Memory::Query] + # @return [Hanami::Model::Adapters::Memory::Query] # - # @see Lotus::Model::Adapters::Memory::Query + # @see Hanami::Model::Adapters::Memory::Query # # @api private # @since 0.2.0 @@ -229,7 +229,7 @@ def info # @api private # @since 0.5.0 # - # @see Lotus::Model::Adapters::Abstract#disconnect + # @see Hanami::Model::Adapters::Abstract#disconnect def disconnect super diff --git a/lib/lotus/model/adapters/implementation.rb b/lib/hanami/model/adapters/implementation.rb similarity index 99% rename from lib/lotus/model/adapters/implementation.rb rename to lib/hanami/model/adapters/implementation.rb index 0e5d1e37..88412340 100644 --- a/lib/lotus/model/adapters/implementation.rb +++ b/lib/hanami/model/adapters/implementation.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Adapters # Shared implementation for SqlAdapter and MemoryAdapter diff --git a/lib/lotus/model/adapters/memory/collection.rb b/lib/hanami/model/adapters/memory/collection.rb similarity index 91% rename from lib/lotus/model/adapters/memory/collection.rb rename to lib/hanami/model/adapters/memory/collection.rb index aab24479..6b5de762 100644 --- a/lib/lotus/model/adapters/memory/collection.rb +++ b/lib/hanami/model/adapters/memory/collection.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Adapters module Memory @@ -14,7 +14,7 @@ class Collection class PrimaryKey # Initialize # - # @return [Lotus::Model::Adapters::Memory::Collection::PrimaryKey] + # @return [Hanami::Model::Adapters::Memory::Collection::PrimaryKey] # # @api private # @since 0.1.0 @@ -70,7 +70,7 @@ def initialize(name, identity) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Memory::Command#create + # @see Hanami::Model::Adapters::Memory::Command#create # # @return the primary key of the created record # @@ -87,7 +87,7 @@ def create(entity) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Memory::Command#update + # @see Hanami::Model::Adapters::Memory::Command#update # # @api private # @since 0.1.0 @@ -99,7 +99,7 @@ def update(entity) # # @param entity [Object] the entity to delete # - # @see Lotus::Model::Adapters::Memory::Command#delete + # @see Hanami::Model::Adapters::Memory::Command#delete # # @api private # @since 0.1.0 diff --git a/lib/lotus/model/adapters/memory/command.rb b/lib/hanami/model/adapters/memory/command.rb similarity index 81% rename from lib/lotus/model/adapters/memory/command.rb rename to lib/hanami/model/adapters/memory/command.rb index 2e6331ef..2680ccaf 100644 --- a/lib/lotus/model/adapters/memory/command.rb +++ b/lib/hanami/model/adapters/memory/command.rb @@ -1,19 +1,19 @@ -module Lotus +module Hanami module Model module Adapters module Memory # Execute a command for the given collection. # - # @see Lotus::Model::Adapters::Memory::Collection - # @see Lotus::Model::Mapping::Collection + # @see Hanami::Model::Adapters::Memory::Collection + # @see Hanami::Model::Mapping::Collection # # @api private # @since 0.1.0 class Command # Initialize a command # - # @param dataset [Lotus::Model::Adapters::Memory::Collection] - # @param collection [Lotus::Model::Mapping::Collection] + # @param dataset [Hanami::Model::Adapters::Memory::Collection] + # @param collection [Hanami::Model::Mapping::Collection] # # @api private # @since 0.1.0 @@ -26,7 +26,7 @@ def initialize(dataset, collection) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Memory::Collection#insert + # @see Hanami::Model::Adapters::Memory::Collection#insert # # @return the primary key of the just created record. # @@ -43,7 +43,7 @@ def create(entity) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Memory::Collection#update + # @see Hanami::Model::Adapters::Memory::Collection#update # # @api private # @since 0.1.0 @@ -58,7 +58,7 @@ def update(entity) # # @param entity [Object] the entity to delete # - # @see Lotus::Model::Adapters::Memory::Collection#delete + # @see Hanami::Model::Adapters::Memory::Collection#delete # # @api private # @since 0.1.0 @@ -68,7 +68,7 @@ def delete(entity) # Deletes all the records from the table. # - # @see Lotus::Model::Adapters::Memory::Collection#clear + # @see Hanami::Model::Adapters::Memory::Collection#clear # # @api private # @since 0.1.0 @@ -89,7 +89,7 @@ def _serialize(entity) # Deserialize the given entity after it was persisted in the database. # - # @return [Lotus::Entity] the deserialized entity + # @return [Hanami::Entity] the deserialized entity # # @api private # @since 0.2.2 diff --git a/lib/lotus/model/adapters/memory/query.rb b/lib/hanami/model/adapters/memory/query.rb similarity index 92% rename from lib/lotus/model/adapters/memory/query.rb rename to lib/hanami/model/adapters/memory/query.rb index ed822cee..81604a0c 100644 --- a/lib/lotus/model/adapters/memory/query.rb +++ b/lib/hanami/model/adapters/memory/query.rb @@ -1,8 +1,8 @@ require 'forwardable' require 'ostruct' -require 'lotus/utils/kernel' +require 'hanami/utils/kernel' -module Lotus +module Hanami module Model module Adapters module Memory @@ -17,7 +17,7 @@ module Memory # @example # # query.where(language: 'ruby') - # .and(framework: 'lotus') + # .and(framework: 'hanami') # .reverse_order(:users_count).all # # # the records are fetched only when we invoke #all @@ -46,8 +46,8 @@ class Query # Initialize a query # - # @param dataset [Lotus::Model::Adapters::Memory::Collection] - # @param collection [Lotus::Model::Mapping::Collection] + # @param dataset [Hanami::Model::Adapters::Memory::Collection] + # @param collection [Hanami::Model::Mapping::Collection] # @param blk [Proc] an optional block that gets yielded in the # context of the current query # @@ -102,17 +102,17 @@ def all # @example Multiple conditions # # query.where(language: 'ruby') - # .where(framework: 'lotus') + # .where(framework: 'hanami') # # @example Multiple conditions with blocks # # query.where { language == 'ruby' } - # .where { framework == 'lotus' } + # .where { framework == 'hanami' } # # @example Mixed hash and block conditions # # query.where(language: 'ruby') - # .where { framework == 'lotus' } + # .where { framework == 'hanami' } def where(condition = nil, &blk) if blk _push_evaluated_block_condition(:where, blk, :find_all) @@ -152,7 +152,7 @@ def where(condition = nil, &blk) # # @example Fixed value # - # query.where(language: 'ruby').or(framework: 'lotus') + # query.where(language: 'ruby').or(framework: 'hanami') # # @example Array # @@ -169,7 +169,7 @@ def where(condition = nil, &blk) # @example Mixed hash and block conditions # # query.where(language: 'ruby') - # .or { framework == 'lotus' } + # .or { framework == 'hanami' } def or(condition = nil, &blk) if blk _push_evaluated_block_condition(:or, blk, :find_all) @@ -256,7 +256,7 @@ def exclude(condition = nil, &blk) # # query.select(:name, :year) def select(*columns) - columns = Lotus::Utils::Kernel.Array(columns) + columns = Hanami::Utils::Kernel.Array(columns) modifiers.push(Proc.new{ flatten!; each {|r| r.delete_if {|k,_| !columns.include?(k)} } }) end @@ -269,7 +269,7 @@ def select(*columns) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Memory::Query#reverse_order + # @see Hanami::Model::Adapters::Memory::Query#reverse_order # # @example Single column # @@ -283,7 +283,7 @@ def select(*columns) # # query.order(:name).order(:year) def order(*columns) - Lotus::Utils::Kernel.Array(columns).each do |column| + Hanami::Utils::Kernel.Array(columns).each do |column| modifiers.push(Proc.new{ sort_by!{|r| r.fetch(column)} }) end @@ -294,7 +294,7 @@ def order(*columns) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Memory::Query#order + # @see Hanami::Model::Adapters::Memory::Query#order # # @example Single column # @@ -318,7 +318,7 @@ def order(*columns) # # @since 0.3.1 # - # @see Lotus::Model::Adapters::Memory::Query#order + # @see Hanami::Model::Adapters::Memory::Query#order # # @example Single column # @@ -332,7 +332,7 @@ def order(*columns) # # query.reverse_order(:name).reverse_order(:year) def reverse_order(*columns) - Lotus::Utils::Kernel.Array(columns).each do |column| + Hanami::Utils::Kernel.Array(columns).each do |column| modifiers.push(Proc.new{ sort_by!{|r| r.fetch(column)}.reverse! }) end @@ -343,7 +343,7 @@ def reverse_order(*columns) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Memory::Query#reverse_order + # @see Hanami::Model::Adapters::Memory::Query#reverse_order # # @example Single column # @@ -472,8 +472,8 @@ def min(column) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Memory::Query#max - # @see Lotus::Model::Adapters::Memory::Query#min + # @see Hanami::Model::Adapters::Memory::Query#max + # @see Hanami::Model::Adapters::Memory::Query#min # # @example # @@ -492,8 +492,8 @@ def interval(column) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Memory::Query#max - # @see Lotus::Model::Adapters::Memory::Query#min + # @see Hanami::Model::Adapters::Memory::Query#max + # @see Hanami::Model::Adapters::Memory::Query#min # # @example # @@ -536,7 +536,7 @@ def count # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#negate! + # @see Hanami::Model::Adapters::Sql::Query#negate! def negate! raise NotImplementedError end @@ -549,7 +549,7 @@ def negate! # # @since 0.5.0 # - # @see Lotus::Model::Adapters::Sql::Query#group! + # @see Hanami::Model::Adapters::Sql::Query#group! def group raise NotImplementedError end @@ -593,7 +593,7 @@ def run result.instance_exec(&modifier) end - Lotus::Utils::Kernel.Array(result) + Hanami::Utils::Kernel.Array(result) end def _all_with_present_column(column) @@ -628,7 +628,7 @@ def _push_to_expanded_condition(condition_type, condition) # # @return [Array] the conditions array itself. # - # @raise [Lotus::Model::InvalidQueryError] if block raises error when + # @raise [Hanami::Model::InvalidQueryError] if block raises error when # evaluated. # # @api private @@ -641,7 +641,7 @@ def _push_evaluated_block_condition(condition_type, condition, strategy) rescue NoMethodError # TODO improve the error message, informing which # attributes are invalid - raise Lotus::Model::InvalidQueryError.new + raise Hanami::Model::InvalidQueryError.new end } }]) diff --git a/lib/lotus/model/adapters/memory_adapter.rb b/lib/hanami/model/adapters/memory_adapter.rb similarity index 83% rename from lib/lotus/model/adapters/memory_adapter.rb rename to lib/hanami/model/adapters/memory_adapter.rb index f581b081..cf2bd8d5 100644 --- a/lib/lotus/model/adapters/memory_adapter.rb +++ b/lib/hanami/model/adapters/memory_adapter.rb @@ -1,10 +1,10 @@ -require 'lotus/model/adapters/abstract' -require 'lotus/model/adapters/implementation' -require 'lotus/model/adapters/memory/collection' -require 'lotus/model/adapters/memory/command' -require 'lotus/model/adapters/memory/query' +require 'hanami/model/adapters/abstract' +require 'hanami/model/adapters/implementation' +require 'hanami/model/adapters/memory/collection' +require 'hanami/model/adapters/memory/command' +require 'hanami/model/adapters/memory/query' -module Lotus +module Hanami module Model module Adapters # In memory adapter that behaves like a SQL database. @@ -13,7 +13,7 @@ module Adapters # This adapter SHOULD be used only for development or testing purposes, # because its computations are inefficient and the data is volatile. # - # @see Lotus::Model::Adapters::Implementation + # @see Hanami::Model::Adapters::Implementation # # @api private # @since 0.1.0 @@ -26,9 +26,9 @@ class MemoryAdapter < Abstract # @param uri [String] the connection uri (ignored) # @param options [Hash] a hash of non mandatory adapter options # - # @return [Lotus::Model::Adapters::MemoryAdapter] + # @return [Hanami::Model::Adapters::MemoryAdapter] # - # @see Lotus::Model::Mapper + # @see Hanami::Model::Mapper # # @api private # @since 0.1.0 @@ -100,9 +100,9 @@ def clear(collection) # # @param collection [Symbol] the collection name (it must be mapped) # - # @return [Lotus::Model::Adapters::Memory::Command] + # @return [Hanami::Model::Adapters::Memory::Command] # - # @see Lotus::Model::Adapters::Memory::Command + # @see Hanami::Model::Adapters::Memory::Command # # @api private # @since 0.1.0 @@ -116,9 +116,9 @@ def command(collection) # @param blk [Proc] a block of code to be executed in the context of # the query. # - # @return [Lotus::Model::Adapters::Memory::Query] + # @return [Hanami::Model::Adapters::Memory::Query] # - # @see Lotus::Model::Adapters::Memory::Query + # @see Hanami::Model::Adapters::Memory::Query # # @api private # @since 0.1.0 @@ -133,8 +133,8 @@ def query(collection, context = nil, &blk) # # @param options [Hash] options for transaction # - # @see Lotus::Model::Adapters::SqlAdapter#transaction - # @see Lotus::Model::Adapters::Abstract#transaction + # @see Hanami::Model::Adapters::SqlAdapter#transaction + # @see Hanami::Model::Adapters::Abstract#transaction # # @since 0.2.3 def transaction(options = {}) @@ -144,7 +144,7 @@ def transaction(options = {}) # @api private # @since 0.5.0 # - # @see Lotus::Model::Adapters::Abstract#disconnect + # @see Hanami::Model::Adapters::Abstract#disconnect def disconnect @collections = DisconnectedResource.new @mutex = DisconnectedResource.new @@ -156,9 +156,9 @@ def disconnect # # @param name [Symbol] a name of the collection (it must be mapped). # - # @return [Lotus::Model::Adapters::Memory::Collection] + # @return [Hanami::Model::Adapters::Memory::Collection] # - # @see Lotus::Model::Adapters::Memory::Collection + # @see Hanami::Model::Adapters::Memory::Collection # # @api private # @since 0.1.0 diff --git a/lib/lotus/model/adapters/null_adapter.rb b/lib/hanami/model/adapters/null_adapter.rb similarity index 84% rename from lib/lotus/model/adapters/null_adapter.rb rename to lib/hanami/model/adapters/null_adapter.rb index 32d835f6..342972ef 100644 --- a/lib/lotus/model/adapters/null_adapter.rb +++ b/lib/hanami/model/adapters/null_adapter.rb @@ -1,10 +1,10 @@ -require 'lotus/model/error' +require 'hanami/model/error' -module Lotus +module Hanami module Model module Adapters # @since 0.2.0 - class NoAdapterError < Lotus::Model::Error + class NoAdapterError < Hanami::Model::Error def initialize(method_name) super("Cannot invoke `#{ method_name }' on repository. "\ "Please check if `adapter' and `mapping' are set, "\ diff --git a/lib/lotus/model/adapters/sql/collection.rb b/lib/hanami/model/adapters/sql/collection.rb similarity index 79% rename from lib/lotus/model/adapters/sql/collection.rb rename to lib/hanami/model/adapters/sql/collection.rb index da298188..9630c8c5 100644 --- a/lib/lotus/model/adapters/sql/collection.rb +++ b/lib/hanami/model/adapters/sql/collection.rb @@ -1,7 +1,7 @@ require 'delegate' -require 'lotus/utils/kernel' unless RUBY_VERSION >= '2.1' +require 'hanami/utils/kernel' unless RUBY_VERSION >= '2.1' -module Lotus +module Hanami module Model module Adapters module Sql @@ -17,10 +17,10 @@ class Collection < SimpleDelegator # # @param dataset [Sequel::Dataset] the dataset that maps a table or a # subset of it. - # @param mapped_collection [Lotus::Model::Mapping::Collection] a + # @param mapped_collection [Hanami::Model::Mapping::Collection] a # mapped collection # - # @return [Lotus::Model::Adapters::Sql::Collection] + # @return [Hanami::Model::Adapters::Sql::Collection] # # @api private # @since 0.1.0 @@ -33,9 +33,9 @@ def initialize(dataset, mapped_collection) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#exclude + # @see Hanami::Model::Adapters::Sql::Query#exclude # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -48,7 +48,7 @@ def exclude(*args) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Sql::Command#create + # @see Hanami::Model::Adapters::Sql::Command#create # # @return the primary key of the created record # @@ -65,9 +65,9 @@ def insert(entity) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#limit + # @see Hanami::Model::Adapters::Sql::Query#limit # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -80,9 +80,9 @@ def limit(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#offset + # @see Hanami::Model::Adapters::Sql::Query#offset # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -95,9 +95,9 @@ def offset(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#or + # @see Hanami::Model::Adapters::Sql::Query#or # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -110,9 +110,9 @@ def or(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#order + # @see Hanami::Model::Adapters::Sql::Query#order # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -125,9 +125,9 @@ def order(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#order + # @see Hanami::Model::Adapters::Sql::Query#order # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -140,9 +140,9 @@ def order_more(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#select + # @see Hanami::Model::Adapters::Sql::Query#select # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -153,7 +153,7 @@ def select(*args) end else def select(*args) - Collection.new(__getobj__.select(*Lotus::Utils::Kernel.Array(args)), @mapped_collection) + Collection.new(__getobj__.select(*Hanami::Utils::Kernel.Array(args)), @mapped_collection) end end @@ -162,9 +162,9 @@ def select(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#group + # @see Hanami::Model::Adapters::Sql::Query#group # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -177,9 +177,9 @@ def group(*args) # # @param args [Array] the array of arguments # - # @see Lotus::Model::Adapters::Sql::Query#where + # @see Hanami::Model::Adapters::Sql::Query#where # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -192,7 +192,7 @@ def where(*args) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Sql::Command#update + # @see Hanami::Model::Adapters::Sql::Command#update # # @api private # @since 0.1.0 @@ -216,7 +216,7 @@ def to_a # Select all attributes for current scope # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -229,7 +229,7 @@ def select_all # Use join table for current scope # - # @return [Lotus::Model::Adapters::Sql::Collection] the filtered + # @return [Hanami::Model::Adapters::Sql::Collection] the filtered # collection # # @api private @@ -273,7 +273,7 @@ def _serialize(entity) # Deserialize the given entity after it was persisted in the database. # - # @return [Lotus::Entity] the deserialized entity + # @return [Hanami::Entity] the deserialized entity # # @api private # @since 0.2.2 diff --git a/lib/lotus/model/adapters/sql/command.rb b/lib/hanami/model/adapters/sql/command.rb similarity index 73% rename from lib/lotus/model/adapters/sql/command.rb rename to lib/hanami/model/adapters/sql/command.rb index 01575ddf..e426aed0 100644 --- a/lib/lotus/model/adapters/sql/command.rb +++ b/lib/hanami/model/adapters/sql/command.rb @@ -1,17 +1,17 @@ -module Lotus +module Hanami module Model module Adapters module Sql # Execute a command for the given query. # - # @see Lotus::Model::Adapters::Sql::Query + # @see Hanami::Model::Adapters::Sql::Query # # @api private # @since 0.1.0 class Command # Initialize a command # - # @param query [Lotus::Model::Adapters::Sql::Query] + # @param query [Hanami::Model::Adapters::Sql::Query] # # @api private # @since 0.1.0 @@ -23,7 +23,7 @@ def initialize(query) # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Sql::Collection#insert + # @see Hanami::Model::Adapters::Sql::Collection#insert # # @return the primary key of the just created record. # @@ -32,36 +32,36 @@ def initialize(query) def create(entity) @collection.insert(entity) rescue Sequel::DatabaseError => e - raise Lotus::Model::Error.new(e.message) + raise Hanami::Model::Error.new(e.message) end # Updates the corresponding record for the given entity. # # @param entity [Object] the entity to persist # - # @see Lotus::Model::Adapters::Sql::Collection#update + # @see Hanami::Model::Adapters::Sql::Collection#update # # @api private # @since 0.1.0 def update(entity) @collection.update(entity) rescue Sequel::DatabaseError => e - raise Lotus::Model::Error.new(e.message) + raise Hanami::Model::Error.new(e.message) end # Deletes all the records for the current query. # # It's used to delete a single record or an entire database table. # - # @see Lotus::Model::Adapters::SqlAdapter#delete - # @see Lotus::Model::Adapters::SqlAdapter#clear + # @see Hanami::Model::Adapters::SqlAdapter#delete + # @see Hanami::Model::Adapters::SqlAdapter#clear # # @api private # @since 0.1.0 def delete @collection.delete rescue Sequel::DatabaseError => e - raise Lotus::Model::Error.new(e.message) + raise Hanami::Model::Error.new(e.message) end alias_method :clear, :delete diff --git a/lib/lotus/model/adapters/sql/console.rb b/lib/hanami/model/adapters/sql/console.rb similarity index 73% rename from lib/lotus/model/adapters/sql/console.rb rename to lib/hanami/model/adapters/sql/console.rb index c60c57df..ab403bf7 100644 --- a/lib/lotus/model/adapters/sql/console.rb +++ b/lib/hanami/model/adapters/sql/console.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Adapters module Sql @@ -16,13 +16,13 @@ def initialize(uri) def console case @uri.scheme when 'sqlite' - require 'lotus/model/adapters/sql/consoles/sqlite' + require 'hanami/model/adapters/sql/consoles/sqlite' Consoles::Sqlite.new(@uri) when 'postgres' - require 'lotus/model/adapters/sql/consoles/postgresql' + require 'hanami/model/adapters/sql/consoles/postgresql' Consoles::Postgresql.new(@uri) when 'mysql', 'mysql2' - require 'lotus/model/adapters/sql/consoles/mysql' + require 'hanami/model/adapters/sql/consoles/mysql' Consoles::Mysql.new(@uri) end end diff --git a/lib/lotus/model/adapters/sql/consoles/mysql.rb b/lib/hanami/model/adapters/sql/consoles/mysql.rb similarity index 98% rename from lib/lotus/model/adapters/sql/consoles/mysql.rb rename to lib/hanami/model/adapters/sql/consoles/mysql.rb index c99cda09..89c32e3a 100644 --- a/lib/lotus/model/adapters/sql/consoles/mysql.rb +++ b/lib/hanami/model/adapters/sql/consoles/mysql.rb @@ -1,5 +1,5 @@ require 'shellwords' -module Lotus +module Hanami module Model module Adapters module Sql diff --git a/lib/lotus/model/adapters/sql/consoles/postgresql.rb b/lib/hanami/model/adapters/sql/consoles/postgresql.rb similarity index 98% rename from lib/lotus/model/adapters/sql/consoles/postgresql.rb rename to lib/hanami/model/adapters/sql/consoles/postgresql.rb index 837346f3..bc2f6469 100644 --- a/lib/lotus/model/adapters/sql/consoles/postgresql.rb +++ b/lib/hanami/model/adapters/sql/consoles/postgresql.rb @@ -1,5 +1,5 @@ require 'shellwords' -module Lotus +module Hanami module Model module Adapters module Sql diff --git a/lib/lotus/model/adapters/sql/consoles/sqlite.rb b/lib/hanami/model/adapters/sql/consoles/sqlite.rb similarity index 96% rename from lib/lotus/model/adapters/sql/consoles/sqlite.rb rename to lib/hanami/model/adapters/sql/consoles/sqlite.rb index fef4a419..a60a9e85 100644 --- a/lib/lotus/model/adapters/sql/consoles/sqlite.rb +++ b/lib/hanami/model/adapters/sql/consoles/sqlite.rb @@ -1,5 +1,5 @@ require 'shellwords' -module Lotus +module Hanami module Model module Adapters module Sql diff --git a/lib/lotus/model/adapters/sql/query.rb b/lib/hanami/model/adapters/sql/query.rb similarity index 92% rename from lib/lotus/model/adapters/sql/query.rb rename to lib/hanami/model/adapters/sql/query.rb index 163b69c4..a1d113d5 100644 --- a/lib/lotus/model/adapters/sql/query.rb +++ b/lib/hanami/model/adapters/sql/query.rb @@ -1,7 +1,7 @@ require 'forwardable' -require 'lotus/utils/kernel' +require 'hanami/utils/kernel' -module Lotus +module Hanami module Model module Adapters module Sql @@ -16,7 +16,7 @@ module Sql # @example # # query.where(language: 'ruby') - # .and(framework: 'lotus') + # .and(framework: 'hanami') # .reverse_order(:users_count).all # # # the records are fetched only when we invoke #all @@ -28,7 +28,7 @@ module Sql class Query # Define negations for operators. # - # @see Lotus::Model::Adapters::Sql::Query#negate! + # @see Hanami::Model::Adapters::Sql::Query#negate! # # @api private # @since 0.1.0 @@ -51,13 +51,13 @@ class Query # Initialize a query # - # @param collection [Lotus::Model::Adapters::Sql::Collection] the + # @param collection [Hanami::Model::Adapters::Sql::Collection] the # collection to query # # @param blk [Proc] an optional block that gets yielded in the # context of the current query # - # @return [Lotus::Model::Adapters::Sql::Query] + # @return [Hanami::Model::Adapters::Sql::Query] def initialize(collection, context = nil, &blk) @collection, @context = collection, context @conditions = [] @@ -70,14 +70,14 @@ def initialize(collection, context = nil, &blk) # # @return [Array] a collection of entities # - # @raise [Lotus::Model::InvalidQueryError] if there is some issue when + # @raise [Hanami::Model::InvalidQueryError] if there is some issue when # hitting the database for fetching records # # @since 0.1.0 def all run.to_a rescue Sequel::DatabaseError => e - raise Lotus::Model::InvalidQueryError.new(e.message) + raise Hanami::Model::InvalidQueryError.new(e.message) end # Adds a SQL `WHERE` condition. @@ -113,9 +113,9 @@ def all # @example Multiple conditions # # query.where(language: 'ruby') - # .where(framework: 'lotus') + # .where(framework: 'hanami') # - # # => SELECT * FROM `projects` WHERE (`language` = 'ruby') AND (`framework` = 'lotus') + # # => SELECT * FROM `projects` WHERE (`language` = 'ruby') AND (`framework` = 'hanami') # # @example Expressions # @@ -145,9 +145,9 @@ def where(condition = nil, &blk) # # @example Fixed value # - # query.where(language: 'ruby').or(framework: 'lotus') + # query.where(language: 'ruby').or(framework: 'hanami') # - # # => SELECT * FROM `projects` WHERE ((`language` = 'ruby') OR (`framework` = 'lotus')) + # # => SELECT * FROM `projects` WHERE ((`language` = 'ruby') OR (`framework` = 'hanami')) # # @example Array # @@ -276,7 +276,7 @@ def limit(number) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#limit + # @see Hanami::Model::Adapters::Sql::Query#limit # # @example # @@ -297,7 +297,7 @@ def offset(number) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#reverse_order + # @see Hanami::Model::Adapters::Sql::Query#reverse_order # # @example Single column # @@ -325,7 +325,7 @@ def order(*columns) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#order + # @see Hanami::Model::Adapters::Sql::Query#order # # @example Single column # @@ -355,7 +355,7 @@ def order(*columns) # # @since 0.3.1 # - # @see Lotus::Model::Adapters::Sql::Query#order + # @see Hanami::Model::Adapters::Sql::Query#order # # @example Single column # @@ -386,7 +386,7 @@ def reverse_order(*columns) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#reverse_order + # @see Hanami::Model::Adapters::Sql::Query#reverse_order # # @example Single column # @@ -515,8 +515,8 @@ def min(column) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#max - # @see Lotus::Model::Adapters::Sql::Query#min + # @see Hanami::Model::Adapters::Sql::Query#max + # @see Hanami::Model::Adapters::Sql::Query#min # # @example # @@ -536,8 +536,8 @@ def interval(column) # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#max - # @see Lotus::Model::Adapters::Sql::Query#min + # @see Hanami::Model::Adapters::Sql::Query#max + # @see Hanami::Model::Adapters::Sql::Query#min # # @example # @@ -581,9 +581,9 @@ def count # # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#where - # @see Lotus::Model::Adapters::Sql::Query#exclude - # @see Lotus::Repository#exclude + # @see Hanami::Model::Adapters::Sql::Query#where + # @see Hanami::Model::Adapters::Sql::Query#exclude + # @see Hanami::Repository#exclude # # @example # @@ -601,7 +601,7 @@ def negate! # This operation is idempotent, and the returned result didn't # fetched the records yet. # - # @return [Lotus::Model::Adapters::Sql::Collection] + # @return [Hanami::Model::Adapters::Sql::Collection] # # @since 0.1.0 def scoped @@ -666,7 +666,7 @@ def left_join(collection, options = {}) # @api private # @since 0.1.0 # - # @see Lotus::Model::Adapters:Sql::Query#apply + # @see Hanami::Model::Adapters:Sql::Query#apply def method_missing(m, *args, &blk) if @context.respond_to?(m) apply @context.public_send(m, *args, &blk) @@ -706,19 +706,19 @@ def _join(collection, options = {}) # # This is used to combine queries together in a Repository. # - # @param query [Lotus::Model::Adapters::Sql::Query] the query to apply + # @param query [Hanami::Model::Adapters::Sql::Query] the query to apply # - # @return [Lotus::Model::Adapters::Sql::Query] a new query with the + # @return [Hanami::Model::Adapters::Sql::Query] a new query with the # merged conditions # # @api private # @since 0.1.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.by_author(author) # query do diff --git a/lib/lotus/model/adapters/sql_adapter.rb b/lib/hanami/model/adapters/sql_adapter.rb similarity index 80% rename from lib/lotus/model/adapters/sql_adapter.rb rename to lib/hanami/model/adapters/sql_adapter.rb index 6ee071a2..e857fb77 100644 --- a/lib/lotus/model/adapters/sql_adapter.rb +++ b/lib/hanami/model/adapters/sql_adapter.rb @@ -1,20 +1,20 @@ -require 'lotus/model/adapters/abstract' -require 'lotus/model/adapters/implementation' -require 'lotus/model/adapters/sql/collection' -require 'lotus/model/adapters/sql/command' -require 'lotus/model/adapters/sql/query' -require 'lotus/model/adapters/sql/console' +require 'hanami/model/adapters/abstract' +require 'hanami/model/adapters/implementation' +require 'hanami/model/adapters/sql/collection' +require 'hanami/model/adapters/sql/command' +require 'hanami/model/adapters/sql/query' +require 'hanami/model/adapters/sql/console' require 'sequel' -module Lotus +module Hanami module Model module Adapters # Adapter for SQL databases # # In order to use it with a specific database, you must require the Ruby - # gem before of loading Lotus::Model. + # gem before of loading Hanami::Model. # - # @see Lotus::Model::Adapters::Implementation + # @see Hanami::Model::Adapters::Implementation # # @api private # @since 0.1.0 @@ -23,21 +23,21 @@ class SqlAdapter < Abstract # Initialize the adapter. # - # Lotus::Model uses Sequel. For a complete reference of the connection + # Hanami::Model uses Sequel. For a complete reference of the connection # URI, please see: http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html # # @param mapper [Object] the database mapper # @param uri [String] the connection uri for the database # @param options [Hash] a hash of non-mandatory adapter options # - # @return [Lotus::Model::Adapters::SqlAdapter] + # @return [Hanami::Model::Adapters::SqlAdapter] # - # @raise [Lotus::Model::Adapters::DatabaseAdapterNotFound] if the given + # @raise [Hanami::Model::Adapters::DatabaseAdapterNotFound] if the given # URI refers to an unknown or not registered adapter. # # @raise [URI::InvalidURIError] if the given URI is malformed # - # @see Lotus::Model::Mapper + # @see Hanami::Model::Mapper # @see http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html # # @api private @@ -105,12 +105,12 @@ def clear(collection) # Fabricates a command for the given query. # - # @param query [Lotus::Model::Adapters::Sql::Query] the query object to + # @param query [Hanami::Model::Adapters::Sql::Query] the query object to # act on. # - # @return [Lotus::Model::Adapters::Sql::Command] + # @return [Hanami::Model::Adapters::Sql::Command] # - # @see Lotus::Model::Adapters::Sql::Command + # @see Hanami::Model::Adapters::Sql::Command # # @api private # @since 0.1.0 @@ -124,9 +124,9 @@ def command(query) # @param blk [Proc] a block of code to be executed in the context of # the query. # - # @return [Lotus::Model::Adapters::Sql::Query] + # @return [Hanami::Model::Adapters::Sql::Query] # - # @see Lotus::Model::Adapters::Sql::Query + # @see Hanami::Model::Adapters::Sql::Query # # @api private # @since 0.1.0 @@ -143,21 +143,21 @@ def query(collection, context = nil, &blk) # @option rollback [Symbol] the optional rollback policy: `:always` or # `:reraise`. # - # @see Lotus::Repository::ClassMethods#transaction + # @see Hanami::Repository::ClassMethods#transaction # # @since 0.2.3 # @api private # # @example Basic usage - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = Article.new(title: 'Introducing transactions', @@ -169,15 +169,15 @@ def query(collection, context = nil, &blk) # end # # @example Policy rollback always - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = Article.new(title: 'Introducing transactions', @@ -191,15 +191,15 @@ def query(collection, context = nil, &blk) # # The operation is rolled back, even in no exceptions were raised. # # @example Policy rollback reraise - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = Article.new(title: 'Introducing transactions', @@ -232,7 +232,7 @@ def connection_string # # @param raw [String] the raw SQL statement to execute on the connection # - # @raise [Lotus::Model::InvalidCommandError] if the raw SQL statement is invalid + # @raise [Hanami::Model::InvalidCommandError] if the raw SQL statement is invalid # # @return [NilClass] # @@ -242,7 +242,7 @@ def execute(raw) @connection.execute(raw) nil rescue Sequel::DatabaseError => e - raise Lotus::Model::InvalidCommandError.new(e.message) + raise Hanami::Model::InvalidCommandError.new(e.message) end end @@ -253,7 +253,7 @@ def execute(raw) # # @return [Array] # - # @raise [Lotus::Model::InvalidQueryError] if the raw SQL statement is invalid + # @raise [Hanami::Model::InvalidQueryError] if the raw SQL statement is invalid # # @since 0.5.0 def fetch(raw, &blk) @@ -263,13 +263,13 @@ def fetch(raw, &blk) @connection.fetch(raw).to_a end rescue Sequel::DatabaseError => e - raise Lotus::Model::InvalidQueryError.new(e.message) + raise Hanami::Model::InvalidQueryError.new(e.message) end # @api private # @since 0.5.0 # - # @see Lotus::Model::Adapters::Abstract#disconnect + # @see Hanami::Model::Adapters::Abstract#disconnect def disconnect @connection.disconnect @connection = DisconnectedResource.new @@ -281,9 +281,9 @@ def disconnect # # @param name [Symbol] a name of the collection (it must be mapped). # - # @return [Lotus::Model::Adapters::Sql::Collection] + # @return [Hanami::Model::Adapters::Sql::Collection] # - # @see Lotus::Model::Adapters::Sql::Collection + # @see Hanami::Model::Adapters::Sql::Collection # # @api private # @since 0.1.0 diff --git a/lib/lotus/model/coercer.rb b/lib/hanami/model/coercer.rb similarity index 86% rename from lib/lotus/model/coercer.rb rename to lib/hanami/model/coercer.rb index b4bd79c6..637ff8f4 100644 --- a/lib/lotus/model/coercer.rb +++ b/lib/hanami/model/coercer.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model # Abstract coercer # @@ -6,13 +6,13 @@ module Model # # @since 0.5.0 # - # @see Lotus::Model::Mapper + # @see Hanami::Model::Mapper # # @example Postgres Array - # require 'lotus/model/coercer' + # require 'hanami/model/coercer' # require 'sequel/extensions/pg_array' # - # class PGArray < Lotus::Model::Coercer + # class PGArray < Hanami::Model::Coercer # def self.dump(value) # ::Sequel.pg_array(value) rescue nil # end @@ -22,7 +22,7 @@ module Model # end # end # - # Lotus::Model.configure do + # Hanami::Model.configure do # mapping do # collection :articles do # entity Article @@ -52,7 +52,7 @@ class Coercer # # @since 0.5.0 # - # @see Lotus::Model::Mapping::Coercers + # @see Hanami::Model::Mapping::Coercers def self.load(value) raise NotImplementedError end @@ -65,7 +65,7 @@ def self.load(value) # # @since 0.5.0 # - # @see Lotus::Model::Mapping::Coercers + # @see Hanami::Model::Mapping::Coercers def self.dump(value) self.load(value) end diff --git a/lib/lotus/model/config/adapter.rb b/lib/hanami/model/config/adapter.rb similarity index 58% rename from lib/lotus/model/config/adapter.rb rename to lib/hanami/model/config/adapter.rb index 7101b288..c69925c6 100644 --- a/lib/lotus/model/config/adapter.rb +++ b/lib/hanami/model/config/adapter.rb @@ -1,38 +1,38 @@ -require 'lotus/utils/class' +require 'hanami/utils/class' -module Lotus +module Hanami module Model module Config # Raised when an adapter class does not exist # # @since 0.2.0 - class AdapterNotFound < Lotus::Model::Error + class AdapterNotFound < Hanami::Model::Error def initialize(adapter_name) - super "Cannot find Lotus::Model adapter #{adapter_name}" + super "Cannot find Hanami::Model adapter #{adapter_name}" end end # Configuration for the adapter # - # Lotus::Model has its own global configuration that can be manipulated - # via `Lotus::Model.configure`. + # Hanami::Model has its own global configuration that can be manipulated + # via `Hanami::Model.configure`. # - # New adapter configuration can be registered via `Lotus::Model.adapter`. + # New adapter configuration can be registered via `Hanami::Model.adapter`. # - # @see Lotus::Model.adapter + # @see Hanami::Model.adapter # # @example - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # adapter type: :sql, uri: 'postgres://localhost/database' # end # - # Lotus::Model.configuration.adapter_config - # # => Lotus::Model::Config::Adapter(type: :sql, uri: 'postgres://localhost/database') + # Hanami::Model.configuration.adapter_config + # # => Hanami::Model::Config::Adapter(type: :sql, uri: 'postgres://localhost/database') # - # By convention, Lotus inflects type to find the adapter class - # For example, if type is :sql, derived class will be `Lotus::Model::Adapters::SqlAdapter` + # By convention, Hanami inflects type to find the adapter class + # For example, if type is :sql, derived class will be `Hanami::Model::Adapters::SqlAdapter` # # @since 0.2.0 class Adapter @@ -61,7 +61,7 @@ class Adapter # @option options [Symbol] :type adapter type name # @option options [String] :uri adapter URI # - # @return [Lotus::Model::Config::Adapter] a new apdapter configuration's + # @return [Hanami::Model::Config::Adapter] a new apdapter configuration's # instance # # @since 0.2.0 @@ -72,16 +72,16 @@ def initialize(**options) @uri = opts.delete(:uri) @options = opts - @class_name ||= Lotus::Utils::String.new("#{@type}_adapter").classify + @class_name ||= Hanami::Utils::String.new("#{@type}_adapter").classify end # Initialize the adapter # - # @param mapper [Lotus::Model::Mapper] the mapper instance + # @param mapper [Hanami::Model::Mapper] the mapper instance # - # @return [Lotus::Model::Adapters::SqlAdapter, Lotus::Model::Adapters::MemoryAdapter] an adapter instance + # @return [Hanami::Model::Adapters::SqlAdapter, Hanami::Model::Adapters::MemoryAdapter] an adapter instance # - # @see Lotus::Model::Adapters + # @see Hanami::Model::Adapters # # @since 0.2.0 def build(mapper) @@ -93,15 +93,15 @@ def build(mapper) def load_adapter begin - require "lotus/model/adapters/#{type}_adapter" + require "hanami/model/adapters/#{type}_adapter" rescue LoadError => e - raise LoadError.new("Cannot find Lotus::Model adapter '#{type}' (#{e.message})") + raise LoadError.new("Cannot find Hanami::Model adapter '#{type}' (#{e.message})") end end def instantiate_adapter(mapper) begin - klass = Lotus::Utils::Class.load!(class_name, Lotus::Model::Adapters) + klass = Hanami::Utils::Class.load!(class_name, Hanami::Model::Adapters) klass.new(mapper, uri, options) rescue NameError raise AdapterNotFound.new(class_name) diff --git a/lib/lotus/model/config/mapper.rb b/lib/hanami/model/config/mapper.rb similarity index 85% rename from lib/lotus/model/config/mapper.rb rename to lib/hanami/model/config/mapper.rb index 682f4772..380d1d6d 100644 --- a/lib/lotus/model/config/mapper.rb +++ b/lib/hanami/model/config/mapper.rb @@ -1,6 +1,6 @@ -require 'lotus/utils/kernel' +require 'hanami/utils/kernel' -module Lotus +module Hanami module Model module Config # Read mapping file for mapping DSL @@ -16,7 +16,7 @@ def initialize(path=nil, &blk) elsif path @path = root.join(path) else - raise Lotus::Model::InvalidMappingError.new('You must specify a block or a file.') + raise Hanami::Model::InvalidMappingError.new('You must specify a block or a file.') end end diff --git a/lib/lotus/model/configuration.rb b/lib/hanami/model/configuration.rb similarity index 76% rename from lib/lotus/model/configuration.rb rename to lib/hanami/model/configuration.rb index c1d102b4..4bfd9a47 100644 --- a/lib/lotus/model/configuration.rb +++ b/lib/hanami/model/configuration.rb @@ -1,12 +1,12 @@ -require 'lotus/model/config/adapter' -require 'lotus/model/config/mapper' +require 'hanami/model/config/adapter' +require 'hanami/model/config/mapper' -module Lotus +module Hanami module Model # Configuration for the framework, models and adapters. # - # Lotus::Model has its own global configuration that can be manipulated - # via `Lotus::Model.configure`. + # Hanami::Model has its own global configuration that can be manipulated + # via `Hanami::Model.configure`. # # @since 0.2.0 class Configuration @@ -15,7 +15,7 @@ class Configuration # @since 0.4.0 # @api private # - # @see Lotus::Model::Configuration#migrations + # @see Hanami::Model::Configuration#migrations DEFAULT_MIGRATIONS_PATH = Pathname.new('db/migrations').freeze # Default schema path @@ -23,26 +23,26 @@ class Configuration # @since 0.4.0 # @api private # - # @see Lotus::Model::Configuration#schema + # @see Hanami::Model::Configuration#schema DEFAULT_SCHEMA_PATH = Pathname.new('db/schema.sql').freeze # The persistence mapper # - # @return [Lotus::Model::Mapper] + # @return [Hanami::Model::Mapper] # # @since 0.2.0 attr_reader :mapper # An adapter configuration template # - # @return [Lotus::Model::Config::Adapter] + # @return [Hanami::Model::Config::Adapter] # # @since 0.2.0 attr_reader :adapter_config # Initialize a configuration instance # - # @return [Lotus::Model::Configuration] a new configuration's + # @return [Hanami::Model::Configuration] a new configuration's # instance # # @since 0.2.0 @@ -84,7 +84,7 @@ def load! # # @overload adapter # Retrieves the configured adapter - # @return [Lotus::Model::Config::Adapter,NilClass] the adapter, if + # @return [Hanami::Model::Config::Adapter,NilClass] the adapter, if # present # # @overload adapter @@ -98,17 +98,17 @@ def load! # # @raise [ArgumentError] if one of the mandatory options is omitted # - # @see Lotus::Model.configure - # @see Lotus::Model::Config::Adapter + # @see Hanami::Model.configure + # @see Hanami::Model::Config::Adapter # # @example Register the adapter - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # adapter type: :sql, uri: 'sqlite3://localhost/database' # end # - # Lotus::Model.configuration.adapter_config + # Hanami::Model.configuration.adapter_config # # @since 0.2.0 def adapter(options = nil) @@ -116,7 +116,7 @@ def adapter(options = nil) @adapter_config else _check_adapter_options!(options) - @adapter_config ||= Lotus::Model::Config::Adapter.new(options) + @adapter_config ||= Hanami::Model::Config::Adapter.new(options) end end @@ -132,13 +132,13 @@ def adapter(options = nil) # # @return void # - # @see Lotus::Model.configure - # @see Lotus::Model::Mapper + # @see Hanami::Model.configure + # @see Hanami::Model::Mapper # # @example Set global persistence mapper - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # mapping do # collection :users do # entity User @@ -151,7 +151,7 @@ def adapter(options = nil) # # @since 0.2.0 def mapping(path=nil, &blk) - @mapper_config = Lotus::Model::Config::Mapper.new(path, &blk) + @mapper_config = Hanami::Model::Config::Mapper.new(path, &blk) end # Migrations directory @@ -169,12 +169,12 @@ def mapping(path=nil, &blk) # # @since 0.4.0 # - # @see Lotus::Model::Migrations::DEFAULT_MIGRATIONS_PATH + # @see Hanami::Model::Migrations::DEFAULT_MIGRATIONS_PATH # # @example Set Custom Path - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # migrations 'path/to/migrations' # end @@ -200,12 +200,12 @@ def migrations(path = nil) # # @since 0.4.0 # - # @see Lotus::Model::Migrations::DEFAULT_SCHEMA_PATH + # @see Hanami::Model::Migrations::DEFAULT_SCHEMA_PATH # # @example Set Custom Path - # require 'lotus/model' + # require 'hanami/model' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # schema 'path/to/schema.sql' # end @@ -222,12 +222,12 @@ def schema(path = nil) # @since 0.4.0 # @api private def root - Lotus.respond_to?(:root) ? Lotus.root : Pathname.pwd + Hanami.respond_to?(:root) ? Hanami.root : Pathname.pwd end # Duplicate by copying the settings in a new instance. # - # @return [Lotus::Model::Configuration] a copy of the configuration + # @return [Hanami::Model::Configuration] a copy of the configuration # # @since 0.2.0 # @api private @@ -242,12 +242,12 @@ def duplicate # Instantiate mapper from mapping block # - # @see Lotus::Model::Configuration#mapping + # @see Hanami::Model::Configuration#mapping # # @api private # @since 0.2.0 def _build_mapper - @mapper = Lotus::Model::Mapper.new(&@mapper_config) if @mapper_config + @mapper = Hanami::Model::Mapper.new(&@mapper_config) if @mapper_config end # @api private @@ -262,10 +262,10 @@ def _build_adapter # NOTE Drop this manual check when Ruby 2.0 will not be supported anymore. # Use keyword arguments instead. def _check_adapter_options!(options) - # TODO Maybe this is a candidate for Lotus::Utils::Options + # TODO Maybe this is a candidate for Hanami::Utils::Options # We already have two similar cases: - # 1. Lotus::Router :only/:except for RESTful resources - # 2. Lotus::Validations.validate_options! + # 1. Hanami::Router :only/:except for RESTful resources + # 2. Hanami::Validations.validate_options! [:type, :uri].each do |keyword| raise ArgumentError.new("missing keyword: #{keyword}") if !options.keys.include?(keyword) end diff --git a/lib/lotus/model/error.rb b/lib/hanami/model/error.rb similarity index 86% rename from lib/lotus/model/error.rb rename to lib/hanami/model/error.rb index b87519c7..e58a9515 100644 --- a/lib/lotus/model/error.rb +++ b/lib/hanami/model/error.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model # @since 0.5.1 class Error < ::StandardError diff --git a/lib/lotus/model/mapper.rb b/lib/hanami/model/mapper.rb similarity index 87% rename from lib/lotus/model/mapper.rb rename to lib/hanami/model/mapper.rb index 064fb1b8..d73f7488 100644 --- a/lib/lotus/model/mapper.rb +++ b/lib/hanami/model/mapper.rb @@ -1,14 +1,14 @@ -require 'lotus/model/mapping' +require 'hanami/model/mapping' -module Lotus +module Hanami module Model # Error for missing mapper # It's raised when loading model without mapper # # @since 0.2.0 # - # @see Lotus::Model::Configuration#mapping - class NoMappingError < Lotus::Model::Error + # @see Hanami::Model::Configuration#mapping + class NoMappingError < Hanami::Model::Error def initialize super("Mapping is missing. Please check your framework configuration.") end @@ -32,9 +32,9 @@ def method_missing(m, *args) # @see http://martinfowler.com/eaaCatalog/dataMapper.html # # @example - # require 'lotus/model' + # require 'hanami/model' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :users do # entity User # @@ -60,12 +60,12 @@ class Mapper # # If provided, this class must implement the following interface: # - # * #initialize(collection) # Lotus::Model::Mapping::Collection + # * #initialize(collection) # Hanami::Model::Mapping::Collection # * #to_record(entity) # translates an entity to the database type # * #from_record(record) # translates a record into an entity # * #deserialize_*(value) # a set of methods, one for each database column. # - # If not given, it uses `Lotus::Model::Mapping::CollectionCoercer`, by default. + # If not given, it uses `Hanami::Model::Mapping::CollectionCoercer`, by default. # # # @@ -75,7 +75,7 @@ class Mapper # @param blk [Proc] an optional block of code that gets evaluated in the # context of the current instance # - # @return [Lotus::Model::Mapper] + # @return [Hanami::Model::Mapper] # # @since 0.1.0 def initialize(coercer = nil, &blk) @@ -97,7 +97,7 @@ def initialize(coercer = nil, &blk) # # @since 0.1.0 # - # @see Lotus::Model::Mapping::Collection + # @see Hanami::Model::Mapping::Collection def collection(name, &blk) if block_given? @collections[name] = Mapping::Collection.new(name, @coercer, &blk) diff --git a/lib/lotus/model/mapping.rb b/lib/hanami/model/mapping.rb similarity index 75% rename from lib/lotus/model/mapping.rb rename to lib/hanami/model/mapping.rb index 8913fd5b..272ba33c 100644 --- a/lib/lotus/model/mapping.rb +++ b/lib/hanami/model/mapping.rb @@ -1,8 +1,8 @@ -require 'lotus/model/mapping/collection' -require 'lotus/model/mapping/collection_coercer' -require 'lotus/model/mapping/coercers' +require 'hanami/model/mapping/collection' +require 'hanami/model/mapping/collection_coercer' +require 'hanami/model/mapping/coercers' -module Lotus +module Hanami module Model # Mapping internal utilities # @@ -14,7 +14,7 @@ module Mapping # collection. # # @since 0.1.0 - class UnmappedCollectionError < Lotus::Model::Error + class UnmappedCollectionError < Hanami::Model::Error def initialize(name) super("Cannot find collection: #{ name }") end @@ -26,7 +26,7 @@ def initialize(name) # entity. # # @since 0.2.0 - class EntityNotFound < Lotus::Model::Error + class EntityNotFound < Hanami::Model::Error def initialize(name) super("Cannot find class for entity: #{ name }") end @@ -38,7 +38,7 @@ def initialize(name) # repository. # # @since 0.2.0 - class RepositoryNotFound < Lotus::Model::Error + class RepositoryNotFound < Hanami::Model::Error def initialize(name) super("Cannot find class for repository: #{ name }") end diff --git a/lib/lotus/model/mapping/attribute.rb b/lib/hanami/model/mapping/attribute.rb similarity index 82% rename from lib/lotus/model/mapping/attribute.rb rename to lib/hanami/model/mapping/attribute.rb index 229c74d6..109ad043 100644 --- a/lib/lotus/model/mapping/attribute.rb +++ b/lib/hanami/model/mapping/attribute.rb @@ -1,6 +1,6 @@ -require 'lotus/utils/class' +require 'hanami/utils/class' -module Lotus +module Hanami module Model module Mapping # Mapping attribute @@ -10,7 +10,7 @@ module Mapping class Attribute # @api private # @since 0.5.0 - COERCERS_NAMESPACE = "Lotus::Model::Mapping::Coercers".freeze + COERCERS_NAMESPACE = "Hanami::Model::Mapping::Coercers".freeze # Initialize a new attribute # @@ -21,14 +21,14 @@ class Attribute # @option options [#to_sym] :as Resolve mismatch between database column # name and entity attribute name # - # @return [Lotus::Model::Mapping::Attribute] + # @return [Hanami::Model::Mapping::Attribute] # # @api private # @since 0.5.0 # - # @see Lotus::Model::Coercer - # @see Lotus::Model::Mapping::Coercers - # @see Lotus::Model::Mapping::Collection#attribute + # @see Hanami::Model::Coercer + # @see Hanami::Model::Mapping::Coercers + # @see Hanami::Model::Mapping::Collection#attribute def initialize(name, coercer, options) @name = name.to_sym @coercer = coercer @@ -42,7 +42,7 @@ def initialize(name, coercer, options) # @api private # @since 0.5.0 # - # @see Lotus::Model::Mapping::Collection#attribute + # @see Hanami::Model::Mapping::Collection#attribute def mapped (@options.fetch(:as) { name }).to_sym end diff --git a/lib/lotus/model/mapping/coercers.rb b/lib/hanami/model/mapping/coercers.rb similarity index 77% rename from lib/lotus/model/mapping/coercers.rb rename to lib/hanami/model/mapping/coercers.rb index c9d98d66..523b4ab6 100644 --- a/lib/lotus/model/mapping/coercers.rb +++ b/lib/hanami/model/mapping/coercers.rb @@ -1,7 +1,7 @@ -require 'lotus/model/coercer' -require 'lotus/utils/kernel' +require 'hanami/model/coercer' +require 'hanami/utils/kernel' -module Lotus +module Hanami module Model module Mapping # Default coercers @@ -14,7 +14,7 @@ module Coercers # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Array < Coercer # Transform a value from the database into a Ruby Array, unless nil # @@ -27,7 +27,7 @@ class Array < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load + # @see Hanami::Model::Coercer.load # @see http://ruby-doc.org/core/Kernel.html#method-i-Array def self.load(value) ::Kernel.Array(value) unless value.nil? @@ -39,7 +39,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Boolean < Coercer # Transform a value from the database into a Boolean, unless nil # @@ -52,8 +52,8 @@ class Boolean < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Boolean-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Boolean-class_method def self.load(value) Utils::Kernel.Boolean(value) unless value.nil? end @@ -64,7 +64,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Date < Coercer # Transform a value from the database into a Date, unless nil # @@ -77,8 +77,8 @@ class Date < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Date-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Date-class_method def self.load(value) Utils::Kernel.Date(value) unless value.nil? end @@ -89,7 +89,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class DateTime < Coercer # Transform a value from the database into a DateTime, unless nil # @@ -102,8 +102,8 @@ class DateTime < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#DateTime-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#DateTime-class_method def self.load(value) Utils::Kernel.DateTime(value) unless value.nil? end @@ -114,7 +114,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Float < Coercer # Transform a value from the database into a Float, unless nil # @@ -127,8 +127,8 @@ class Float < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Float-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Float-class_method def self.load(value) Utils::Kernel.Float(value) unless value.nil? end @@ -139,7 +139,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Hash < Coercer # Transform a value from the database into a Hash, unless nil # @@ -152,8 +152,8 @@ class Hash < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Hash-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Hash-class_method def self.load(value) Utils::Kernel.Hash(value) unless value.nil? end @@ -164,7 +164,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Integer < Coercer # Transform a value from the database into a Integer, unless nil # @@ -177,8 +177,8 @@ class Integer < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Integer-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Integer-class_method def self.load(value) Utils::Kernel.Integer(value) unless value.nil? end @@ -189,7 +189,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class BigDecimal < Coercer # Transform a value from the database into a BigDecimal, unless nil # @@ -202,8 +202,8 @@ class BigDecimal < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#BigDecimal-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#BigDecimal-class_method def self.load(value) Utils::Kernel.BigDecimal(value) unless value.nil? end @@ -214,7 +214,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Set < Coercer # Transform a value from the database into a Set, unless nil # @@ -227,8 +227,8 @@ class Set < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Set-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Set-class_method def self.load(value) Utils::Kernel.Set(value) unless value.nil? end @@ -239,7 +239,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class String < Coercer # Transform a value from the database into a String, unless nil # @@ -252,8 +252,8 @@ class String < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#String-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#String-class_method def self.load(value) Utils::Kernel.String(value) unless value.nil? end @@ -264,7 +264,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Symbol < Coercer # Transform a value from the database into a Symbol, unless nil # @@ -277,8 +277,8 @@ class Symbol < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Symbol-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Symbol-class_method def self.load(value) Utils::Kernel.Symbol(value) unless value.nil? end @@ -289,7 +289,7 @@ def self.load(value) # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer class Time < Coercer # Transform a value from the database into a Time, unless nil # @@ -302,8 +302,8 @@ class Time < Coercer # @since 0.5.0 # @api private # - # @see Lotus::Model::Coercer.load - # @see http://rdoc.info/gems/lotus-utils/Lotus/Utils/Kernel#Time-class_method + # @see Hanami::Model::Coercer.load + # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Time-class_method def self.load(value) Utils::Kernel.Time(value) unless value.nil? end diff --git a/lib/lotus/model/mapping/collection.rb b/lib/hanami/model/mapping/collection.rb similarity index 88% rename from lib/lotus/model/mapping/collection.rb rename to lib/hanami/model/mapping/collection.rb index e8b05403..af7c1ab3 100644 --- a/lib/lotus/model/mapping/collection.rb +++ b/lib/hanami/model/mapping/collection.rb @@ -1,7 +1,7 @@ -require 'lotus/utils/class' -require 'lotus/model/mapping/attribute' +require 'hanami/utils/class' +require 'hanami/model/mapping/attribute' -module Lotus +module Hanami module Model module Mapping # Maps a collection and its attributes. @@ -14,12 +14,12 @@ module Mapping # # @since 0.1.0 # - # @see Lotus::Model::Mapper + # @see Hanami::Model::Mapper # # @example - # require 'lotus/model' + # require 'hanami/model' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :users do # entity User # @@ -33,7 +33,7 @@ class Collection # @api private # @since 0.1.0 # - # @see Lotus::Repository + # @see Hanami::Repository REPOSITORY_SUFFIX = 'Repository'.freeze # @attr_reader name [Symbol] the name of the collection @@ -54,7 +54,7 @@ class Collection # @api private attr_reader :attributes - # @attr_reader adapter [Lotus::Model::Adapters] the instance of adapter + # @attr_reader adapter [Hanami::Model::Adapters] the instance of adapter # # @since 0.1.0 # @api private @@ -70,7 +70,7 @@ class Collection # # @since 0.1.0 # - # @see Lotus::Model::Mapper#collection + # @see Hanami::Model::Mapper#collection def initialize(name, coercer_class, &blk) @name = name @coercer_class = coercer_class @@ -87,12 +87,12 @@ def initialize(name, coercer_class, &blk) # # @since 0.1.0 # - # @see Lotus::Entity + # @see Hanami::Entity # # @example Set entity with class name - # require 'lotus/model' + # require 'hanami/model' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # end @@ -101,9 +101,9 @@ def initialize(name, coercer_class, &blk) # mapper.entity #=> Article # # @example Set entity with class name string - # require 'lotus/model' + # require 'hanami/model' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity 'Article' # end @@ -125,12 +125,12 @@ def entity(klass = nil) # # @since 0.2.0 # - # @see Lotus::Repository + # @see Hanami::Repository # # @example Set repository with class name - # require 'lotus/model' + # require 'hanami/model' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # @@ -141,9 +141,9 @@ def entity(klass = nil) # mapper.repository #=> RemoteArticleRepository # # @example Set repository with class name string - # require 'lotus/model' + # require 'hanami/model' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # @@ -175,14 +175,14 @@ def repository(klass = nil) # @since 0.1.0 # # @example Default - # require 'lotus/model' + # require 'hanami/model' # # # We have an SQL table `users` with a primary key `id`. # # # # This this is compliant to the mapper default, we can omit # # `#identity`. # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :users do # entity User # @@ -191,7 +191,7 @@ def repository(klass = nil) # end # # @example Custom identity - # require 'lotus/model' + # require 'hanami/model' # # # We have an SQL table `articles` with a primary key `i_id`. # # @@ -199,7 +199,7 @@ def repository(klass = nil) # # we need to use #identity to let the mapper to recognize the # # primary key. # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # @@ -255,10 +255,10 @@ def identity(name = nil) # # @since 0.1.0 # - # @see Lotus::Model::Coercer + # @see Hanami::Model::Coercer # # @example Default schema - # require 'lotus/model' + # require 'hanami/model' # # # Given the following schema: # # @@ -270,11 +270,11 @@ def identity(name = nil) # # And the following entity: # # # # class User - # # include Lotus::Entity + # # include Hanami::Entity # # attributes :name # # end # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :users do # entity User # @@ -293,7 +293,7 @@ def identity(name = nil) # # `User` attributes. # # @example Customized schema - # require 'lotus/model' + # require 'hanami/model' # # # Given the following schema: # # @@ -307,11 +307,11 @@ def identity(name = nil) # # And the following entity: # # # # class Article - # # include Lotus::Entity + # # include Hanami::Entity # # attributes :user_id, :title, :comments_count # # end # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # @@ -337,7 +337,7 @@ def identity(name = nil) # # `:title`, but not for `:comments_count`. # # @example Custom coercer - # require 'lotus/model' + # require 'hanami/model' # # # Given the following schema: # # @@ -350,16 +350,16 @@ def identity(name = nil) # # The following entity: # # # # class Article - # # include Lotus::Entity + # # include Hanami::Entity # # attributes :title, :tags # # end # # # # And the following custom coercer: # # - # # require 'lotus/model/coercer' + # # require 'hanami/model/coercer' # # require 'sequel/extensions/pg_array' # # - # # class PGArray < Lotus::Model::Coercer + # # class PGArray < Hanami::Model::Coercer # # def self.dump(value) # # ::Sequel.pg_array(value) rescue nil # # end @@ -369,7 +369,7 @@ def identity(name = nil) # # end # # end # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # @@ -437,7 +437,7 @@ def load! # Assigns a repository to an entity # - # @see Lotus::Repository + # @see Hanami::Repository # # @api private # @since 0.1.0 @@ -453,7 +453,7 @@ def _configure_repository! def _load_repository! @repository = Utils::Class.load!(repository) rescue NameError - raise Lotus::Model::Mapping::RepositoryNotFound.new(repository.to_s) + raise Hanami::Model::Mapping::RepositoryNotFound.new(repository.to_s) end # Convert entity string to entity class @@ -463,7 +463,7 @@ def _load_repository! def _load_entity! @entity = Utils::Class.load!(entity) rescue NameError - raise Lotus::Model::Mapping::EntityNotFound.new(entity.to_s) + raise Hanami::Model::Mapping::EntityNotFound.new(entity.to_s) end # Load coercer @@ -476,7 +476,7 @@ def _load_coercer! # Retrieves the default repository class # - # @see Lotus::Repository + # @see Hanami::Repository # # @api private # @since 0.2.0 diff --git a/lib/lotus/model/mapping/collection_coercer.rb b/lib/hanami/model/mapping/collection_coercer.rb similarity index 95% rename from lib/lotus/model/mapping/collection_coercer.rb rename to lib/hanami/model/mapping/collection_coercer.rb index e4ec2c5e..1a69d851 100644 --- a/lib/lotus/model/mapping/collection_coercer.rb +++ b/lib/hanami/model/mapping/collection_coercer.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Mapping # Translates values from/to the database with the corresponding Ruby type. @@ -8,7 +8,7 @@ module Mapping class CollectionCoercer # Initialize a coercer for the given collection. # - # @param collection [Lotus::Model::Mapping::Collection] the collection + # @param collection [Hanami::Model::Mapping::Collection] the collection # # @api private # @since 0.1.0 diff --git a/lib/lotus/model/migrator.rb b/lib/hanami/model/migrator.rb similarity index 74% rename from lib/lotus/model/migrator.rb rename to lib/hanami/model/migrator.rb index 280fa80e..0ec9530c 100644 --- a/lib/lotus/model/migrator.rb +++ b/lib/hanami/model/migrator.rb @@ -1,14 +1,14 @@ require 'sequel' require 'sequel/extensions/migration' -require 'lotus/model/migrator/connection' -require 'lotus/model/migrator/adapter' +require 'hanami/model/migrator/connection' +require 'hanami/model/migrator/adapter' -module Lotus +module Hanami module Model # Migration error # # @since 0.4.0 - class MigrationError < Lotus::Model::Error + class MigrationError < Hanami::Model::Error end # Define a migration @@ -24,7 +24,7 @@ class MigrationError < Lotus::Model::Error # @since 0.4.0 # # @example Use up/down blocks - # Lotus::Model.migration do + # Hanami::Model.migration do # up do # create_table :books do # primary_key :id @@ -38,7 +38,7 @@ class MigrationError < Lotus::Model::Error # end # # @example Use change block - # Lotus::Model.migration do + # Hanami::Model.migration do # change do # create_table :books do # primary_key :id @@ -64,22 +64,22 @@ module Migrator # * PostgreSQL # * MySQL # - # @raise [Lotus::Model::MigrationError] if an error occurs + # @raise [Hanami::Model::MigrationError] if an error occurs # # @since 0.4.0 # - # @see Lotus::Model::Configuration#adapter + # @see Hanami::Model::Configuration#adapter # # @example - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # end # - # Lotus::Model::Migrator.create # Creates `foo' database + # Hanami::Model::Migrator.create # Creates `foo' database def self.create adapter(connection).create end @@ -92,22 +92,22 @@ def self.create # * PostgreSQL # * MySQL # - # @raise [Lotus::Model::MigrationError] if an error occurs + # @raise [Hanami::Model::MigrationError] if an error occurs # # @since 0.4.0 # - # @see Lotus::Model::Configuration#adapter + # @see Hanami::Model::Configuration#adapter # # @example - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # end # - # Lotus::Model::Migrator.drop # Drops `foo' database + # Hanami::Model::Migrator.drop # Drops `foo' database def self.drop adapter(connection).drop end @@ -119,41 +119,41 @@ def self.drop # # @param version [String,NilClass] target version # - # @raise [Lotus::Model::MigrationError] if an error occurs + # @raise [Hanami::Model::MigrationError] if an error occurs # # @since 0.4.0 # - # @see Lotus::Model::Configuration#adapter - # @see Lotus::Model::Configuration#migrations + # @see Hanami::Model::Configuration#adapter + # @see Hanami::Model::Configuration#migrations # # @example Migrate Up - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # migrations 'db/migrations' # end # # # Reads all files from "db/migrations" and apply them - # Lotus::Model::Migrator.migrate + # Hanami::Model::Migrator.migrate # # @example Migrate Down - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # migrations 'db/migrations' # end # # # Reads all files from "db/migrations" and apply them - # Lotus::Model::Migrator.migrate + # Hanami::Model::Migrator.migrate # # # Migrate to a specifiy version - # Lotus::Model::Migrator.migrate(version: "20150610133853") + # Hanami::Model::Migrator.migrate(version: "20150610133853") def self.migrate(version: nil) version = Integer(version) unless version.nil? @@ -179,18 +179,18 @@ def self.migrate(version: nil) # When we use "apply", it eliminates all the migrations that are no longer # necessary. # - # @raise [Lotus::Model::MigrationError] if an error occurs + # @raise [Hanami::Model::MigrationError] if an error occurs # # @since 0.4.0 # - # @see Lotus::Model::Configuration#adapter - # @see Lotus::Model::Configuration#migrations + # @see Hanami::Model::Configuration#adapter + # @see Hanami::Model::Configuration#migrations # # @example Apply Migrations - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # migrations 'db/migrations' @@ -199,7 +199,7 @@ def self.migrate(version: nil) # # # Reads all files from "db/migrations" and apply and delete them. # # It generates an updated version of "db/schema.sql" - # Lotus::Model::Migrator.apply + # Hanami::Model::Migrator.apply def self.apply migrate adapter(connection).dump @@ -211,37 +211,37 @@ def self.apply # This is designed for development machines and testing mode. # It works faster if used with apply. # - # @raise [Lotus::Model::MigrationError] if an error occurs + # @raise [Hanami::Model::MigrationError] if an error occurs # # @since 0.4.0 # - # @see Lotus::Model::Migrator.apply + # @see Hanami::Model::Migrator.apply # # @example Prepare Database - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # migrations 'db/migrations' # end # - # Lotus::Model::Migrator.prepare # => creates `foo' and run migrations + # Hanami::Model::Migrator.prepare # => creates `foo' and run migrations # # @example Prepare Database (with schema dump) - # require 'lotus/model' - # require 'lotus/model/migrator' + # require 'hanami/model' + # require 'hanami/model/migrator' # - # Lotus::Model.configure do + # Hanami::Model.configure do # # ... # adapter type: :sql, uri: 'postgres://localhost/foo' # migrations 'db/migrations' # schema 'db/schema.sql' # end # - # Lotus::Model::Migrator.apply # => updates schema dump - # Lotus::Model::Migrator.prepare # => creates `foo', load schema and run pending migrations (if any) + # Hanami::Model::Migrator.apply # => updates schema dump + # Hanami::Model::Migrator.prepare # => creates `foo', load schema and run pending migrations (if any) def self.prepare drop rescue nil create @@ -261,7 +261,7 @@ def self.prepare # # Given last migrations is: # # 20150610133853_create_books.rb # - # Lotus::Model::Migrator.version # => "20150610133853" + # Hanami::Model::Migrator.version # => "20150610133853" def self.version adapter(connection).version end @@ -296,7 +296,7 @@ def self.connection raise MigrationError.new("Current adapter (#{ configuration.adapter.type }) doesn't support SQL database operations.") end - # Lotus::Model configuration + # Hanami::Model configuration # # @since 0.4.0 # @api private diff --git a/lib/lotus/model/migrator/adapter.rb b/lib/hanami/model/migrator/adapter.rb similarity index 92% rename from lib/lotus/model/migrator/adapter.rb rename to lib/hanami/model/migrator/adapter.rb index d3a2122b..a703bb54 100644 --- a/lib/lotus/model/migrator/adapter.rb +++ b/lib/hanami/model/migrator/adapter.rb @@ -1,7 +1,7 @@ require 'uri' require 'shellwords' -module Lotus +module Hanami module Model module Migrator # Migrator base adapter @@ -28,13 +28,13 @@ class Adapter def self.for(connection) case connection.database_type when :sqlite - require 'lotus/model/migrator/sqlite_adapter' + require 'hanami/model/migrator/sqlite_adapter' SQLiteAdapter when :postgres - require 'lotus/model/migrator/postgres_adapter' + require 'hanami/model/migrator/postgres_adapter' PostgresAdapter when :mysql - require 'lotus/model/migrator/mysql_adapter' + require 'hanami/model/migrator/mysql_adapter' MySQLAdapter else self @@ -55,7 +55,7 @@ def initialize(connection) # @since 0.4.0 # @api private # - # @see Lotus::Model::Migrator.create + # @see Hanami::Model::Migrator.create def create raise MigrationError.new("Current adapter (#{ connection.database_type }) doesn't support create.") end @@ -66,7 +66,7 @@ def create # @since 0.4.0 # @api private # - # @see Lotus::Model::Migrator.drop + # @see Hanami::Model::Migrator.drop def drop raise MigrationError.new("Current adapter (#{ connection.database_type }) doesn't support drop.") end @@ -77,7 +77,7 @@ def drop # @since 0.4.0 # @api private # - # @see Lotus::Model::Migrator.prepare + # @see Hanami::Model::Migrator.prepare def load raise MigrationError.new("Current adapter (#{ connection.database_type }) doesn't support load.") end diff --git a/lib/lotus/model/migrator/connection.rb b/lib/hanami/model/migrator/connection.rb similarity index 99% rename from lib/lotus/model/migrator/connection.rb rename to lib/hanami/model/migrator/connection.rb index ca786a73..ba7a150e 100644 --- a/lib/lotus/model/migrator/connection.rb +++ b/lib/hanami/model/migrator/connection.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Migrator # Sequel connection wrapper diff --git a/lib/lotus/model/migrator/mysql_adapter.rb b/lib/hanami/model/migrator/mysql_adapter.rb similarity index 99% rename from lib/lotus/model/migrator/mysql_adapter.rb rename to lib/hanami/model/migrator/mysql_adapter.rb index ac7a1389..f25e8861 100644 --- a/lib/lotus/model/migrator/mysql_adapter.rb +++ b/lib/hanami/model/migrator/mysql_adapter.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Migrator # MySQL adapter diff --git a/lib/lotus/model/migrator/postgres_adapter.rb b/lib/hanami/model/migrator/postgres_adapter.rb similarity index 99% rename from lib/lotus/model/migrator/postgres_adapter.rb rename to lib/hanami/model/migrator/postgres_adapter.rb index 2be29d21..72c069b8 100644 --- a/lib/lotus/model/migrator/postgres_adapter.rb +++ b/lib/hanami/model/migrator/postgres_adapter.rb @@ -1,4 +1,4 @@ -module Lotus +module Hanami module Model module Migrator # PostgreSQL adapter diff --git a/lib/lotus/model/migrator/sqlite_adapter.rb b/lib/hanami/model/migrator/sqlite_adapter.rb similarity index 97% rename from lib/lotus/model/migrator/sqlite_adapter.rb rename to lib/hanami/model/migrator/sqlite_adapter.rb index 7dc5cd6e..bd49b04a 100644 --- a/lib/lotus/model/migrator/sqlite_adapter.rb +++ b/lib/hanami/model/migrator/sqlite_adapter.rb @@ -1,6 +1,6 @@ require 'pathname' -module Lotus +module Hanami module Model module Migrator # SQLite3 Migrator @@ -76,7 +76,7 @@ def path # @since 0.4.0 # @api private def root - Lotus::Model.configuration.root + Hanami::Model.configuration.root end # @since 0.4.0 diff --git a/lib/lotus/model/version.rb b/lib/hanami/model/version.rb similarity index 63% rename from lib/lotus/model/version.rb rename to lib/hanami/model/version.rb index b8f4ff29..8f1740a0 100644 --- a/lib/lotus/model/version.rb +++ b/lib/hanami/model/version.rb @@ -1,8 +1,8 @@ -module Lotus +module Hanami module Model # Defines the version # # @since 0.1.0 - VERSION = '0.5.2'.freeze + VERSION = '0.6.0'.freeze end end diff --git a/lib/lotus/repository.rb b/lib/hanami/repository.rb similarity index 77% rename from lib/lotus/repository.rb rename to lib/hanami/repository.rb index c32066cb..7b16b38d 100644 --- a/lib/lotus/repository.rb +++ b/lib/hanami/repository.rb @@ -1,7 +1,7 @@ -require 'lotus/utils/class_attribute' -require 'lotus/model/adapters/null_adapter' +require 'hanami/utils/class_attribute' +require 'hanami/model/adapters/null_adapter' -module Lotus +module Hanami # Mediates between the entities and the persistence layer, by offering an API # to query and execute commands on a database. # @@ -11,20 +11,20 @@ module Lotus # `Repository` suffix to the entity class name. # # @example - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity + # include Hanami::Entity # end # # # valid # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # # not valid for Article # class PostRepository - # include Lotus::Repository + # include Hanami::Repository # end # # Repository for an entity can be configured by setting # the `#repository` @@ -32,7 +32,7 @@ module Lotus # # @example # # PostRepository is repository for Article - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # collection :articles do # entity Article # repository PostRepository @@ -54,7 +54,7 @@ module Lotus # # * Isolates the persistence logic at a low level # - # Lotus::Model is shipped with two adapters: + # Hanami::Model is shipped with two adapters: # # * SqlAdapter # * MemoryAdapter @@ -66,7 +66,7 @@ module Lotus # leak storage API details outside of a repository. # # @example - # require 'lotus/model' + # require 'hanami/model' # # # This is bad for several reasons: # # @@ -103,7 +103,7 @@ module Lotus # ArticleRepository.most_recent_by_author(author) # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.most_recent_by_author(author, limit = 8) # query do @@ -115,7 +115,7 @@ module Lotus # # @since 0.1.0 # - # @see Lotus::Entity + # @see Hanami::Entity # @see http://martinfowler.com/eaaCatalog/repository.html # @see http://en.wikipedia.org/wiki/Dependency_inversion_principle module Repository @@ -124,49 +124,49 @@ module Repository # @since 0.1.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # # class UserRepository - # include Lotus::Repository + # include Hanami::Repository # end def self.included(base) base.class_eval do extend ClassMethods - include Lotus::Utils::ClassAttribute + include Hanami::Utils::ClassAttribute class_attribute :collection - self.adapter = Lotus::Model::Adapters::NullAdapter.new + self.adapter = Hanami::Model::Adapters::NullAdapter.new end end module ClassMethods # Assigns an adapter. # - # Lotus::Model is shipped with two adapters: + # Hanami::Model is shipped with two adapters: # # * SqlAdapter # * MemoryAdapter # # @param adapter [Object] an object that implements - # `Lotus::Model::Adapters::Abstract` interface + # `Hanami::Model::Adapters::Abstract` interface # # @since 0.1.0 # - # @see Lotus::Model::Adapters::SqlAdapter - # @see Lotus::Model::Adapters::MemoryAdapter + # @see Hanami::Model::Adapters::SqlAdapter + # @see Hanami::Model::Adapters::MemoryAdapter # # @example Memory adapter - # require 'lotus/model' - # require 'lotus/model/adapters/memory_adapter' + # require 'hanami/model' + # require 'hanami/model/adapters/memory_adapter' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # # ... # end # - # adapter = Lotus::Model::Adapters::MemoryAdapter.new(mapper) + # adapter = Hanami::Model::Adapters::MemoryAdapter.new(mapper) # # class UserRepository - # include Lotus::Repository + # include Hanami::Repository # end # # UserRepository.adapter = adapter @@ -175,17 +175,17 @@ module ClassMethods # # @example SQL adapter with a Sqlite database # require 'sqlite3' - # require 'lotus/model' - # require 'lotus/model/adapters/sql_adapter' + # require 'hanami/model' + # require 'hanami/model/adapters/sql_adapter' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # # ... # end # - # adapter = Lotus::Model::Adapters::SqlAdapter.new(mapper, 'sqlite://path/to/database.db') + # adapter = Hanami::Model::Adapters::SqlAdapter.new(mapper, 'sqlite://path/to/database.db') # # class UserRepository - # include Lotus::Repository + # include Hanami::Repository # end # # UserRepository.adapter = adapter @@ -194,17 +194,17 @@ module ClassMethods # # @example SQL adapter with a Postgres database # require 'pg' - # require 'lotus/model' - # require 'lotus/model/adapters/sql_adapter' + # require 'hanami/model' + # require 'hanami/model/adapters/sql_adapter' # - # mapper = Lotus::Model::Mapper.new do + # mapper = Hanami::Model::Mapper.new do # # ... # end # - # adapter = Lotus::Model::Adapters::SqlAdapter.new(mapper, 'postgres://host:port/database') + # adapter = Hanami::Model::Adapters::SqlAdapter.new(mapper, 'postgres://host:port/database') # # class UserRepository - # include Lotus::Repository + # include Hanami::Repository # end # # UserRepository.adapter = adapter @@ -226,17 +226,17 @@ def adapter # # @since 0.1.0 # - # @see Lotus::Repository#create - # @see Lotus::Repository#update + # @see Hanami::Repository#create + # @see Hanami::Repository#update # # @example With a non persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # - # article = Article.new(title: 'Introducing Lotus::Model') + # article = Article.new(title: 'Introducing Hanami::Model') # article.id # => nil # # persisted_article = ArticleRepository.persist(article) # creates a record @@ -244,20 +244,20 @@ def adapter # persisted_article.id # => 23 # # @example With a persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = ArticleRepository.find(23) # article.id # => 23 # - # article.title = 'Launching Lotus::Model' + # article.title = 'Launching Hanami::Model' # ArticleRepository.persist(article) # updates the record # # article = ArticleRepository.find(23) - # article.title # => "Launching Lotus::Model" + # article.title # => "Launching Hanami::Model" def persist(entity) _touch(entity) @adapter.persist(collection, entity) @@ -274,16 +274,16 @@ def persist(entity) # # @since 0.1.0 # - # @see Lotus::Repository#persist + # @see Hanami::Repository#persist # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # - # article = Article.new(title: 'Introducing Lotus::Model') + # article = Article.new(title: 'Introducing Hanami::Model') # article.id # => nil # # created_article = ArticleRepository.create(article) # creates a record @@ -311,46 +311,46 @@ def create(entity) # # @return [Object] the entity # - # @raise [Lotus::Model::NonPersistedEntityError] if the given entity + # @raise [Hanami::Model::NonPersistedEntityError] if the given entity # wasn't already persisted. # # @since 0.1.0 # - # @see Lotus::Repository#persist - # @see Lotus::Model::NonPersistedEntityError + # @see Hanami::Repository#persist + # @see Hanami::Model::NonPersistedEntityError # # @example With a persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = ArticleRepository.find(23) # article.id # => 23 - # article.title = 'Launching Lotus::Model' + # article.title = 'Launching Hanami::Model' # # ArticleRepository.update(article) # updates the record # # # # @example With a non persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # - # article = Article.new(title: 'Introducing Lotus::Model') + # article = Article.new(title: 'Introducing Hanami::Model') # article.id # => nil # - # ArticleRepository.update(article) # raises Lotus::Model::NonPersistedEntityError + # ArticleRepository.update(article) # raises Hanami::Model::NonPersistedEntityError def update(entity) if _persisted?(entity) _touch(entity) @adapter.update(collection, entity) else - raise Lotus::Model::NonPersistedEntityError + raise Hanami::Model::NonPersistedEntityError end end @@ -362,18 +362,18 @@ def update(entity) # # @return [Object] the entity # - # @raise [Lotus::Model::NonPersistedEntityError] if the given entity + # @raise [Hanami::Model::NonPersistedEntityError] if the given entity # wasn't already persisted. # # @since 0.1.0 # - # @see Lotus::Model::NonPersistedEntityError + # @see Hanami::Model::NonPersistedEntityError # # @example With a persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = ArticleRepository.find(23) @@ -384,21 +384,21 @@ def update(entity) # # # @example With a non persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # - # article = Article.new(title: 'Introducing Lotus::Model') + # article = Article.new(title: 'Introducing Hanami::Model') # article.id # => nil # - # ArticleRepository.delete(article) # raises Lotus::Model::NonPersistedEntityError + # ArticleRepository.delete(article) # raises Hanami::Model::NonPersistedEntityError def delete(entity) if _persisted?(entity) @adapter.delete(collection, entity) else - raise Lotus::Model::NonPersistedEntityError + raise Hanami::Model::NonPersistedEntityError end entity @@ -411,10 +411,10 @@ def delete(entity) # @since 0.1.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.all # => [ # ] @@ -433,10 +433,10 @@ def all # @since 0.1.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.find(23) # => # @@ -451,22 +451,22 @@ def find(id) # # @since 0.1.0 # - # @see Lotus::Repository#last + # @see Hanami::Repository#last # # @example With at least one persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.first # => # # # @example With an empty collection - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.first # => nil @@ -480,22 +480,22 @@ def first # # @since 0.1.0 # - # @see Lotus::Repository#last + # @see Hanami::Repository#last # # @example With at least one persisted entity - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.last # => # # # @example With an empty collection - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.last # => nil @@ -510,10 +510,10 @@ def last # @since 0.1.0 # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # ArticleRepository.clear # deletes all the records @@ -534,21 +534,21 @@ def clear # # @param options [Hash] options for transaction # - # @see Lotus::Model::Adapters::SqlAdapter#transaction - # @see Lotus::Model::Adapters::MemoryAdapter#transaction + # @see Hanami::Model::Adapters::SqlAdapter#transaction + # @see Hanami::Model::Adapters::MemoryAdapter#transaction # # @since 0.2.3 # # @example Basic usage with SQL adapter - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # end # # article = Article.new(title: 'Introducing transactions', @@ -578,26 +578,26 @@ def transaction(options = {}) # # @return [NilClass] # - # @raise [NotImplementedError] if current Lotus::Model adapter doesn't + # @raise [NotImplementedError] if current Hanami::Model adapter doesn't # implement `execute`. # - # @raise [Lotus::Model::InvalidCommandError] if the raw statement is invalid + # @raise [Hanami::Model::InvalidCommandError] if the raw statement is invalid # - # @see Lotus::Model::Adapters::Abstract#execute - # @see Lotus::Model::Adapters::SqlAdapter#execute + # @see Hanami::Model::Adapters::Abstract#execute + # @see Hanami::Model::Adapters::SqlAdapter#execute # # @since 0.3.1 # # @example Basic usage with SQL adapter - # require 'lotus/model' + # require 'hanami/model' # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.reset_comments_count # execute "UPDATE articles SET comments_count = 0" @@ -620,15 +620,15 @@ def execute(raw) # # @return [Enumerable,Array] the collection of raw records # - # @raise [NotImplementedError] if current Lotus::Model adapter doesn't + # @raise [NotImplementedError] if current Hanami::Model adapter doesn't # implement `fetch`. # - # @raise [Lotus::Model::InvalidQueryError] if the raw statement is invalid + # @raise [Hanami::Model::InvalidQueryError] if the raw statement is invalid # # @since 0.5.0 # # @example Basic Usage - # require 'lotus/model' + # require 'hanami/model' # # mapping do # collection :articles do @@ -638,12 +638,12 @@ def execute(raw) # end # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.all_raw # fetch("SELECT * FROM articles") @@ -654,7 +654,7 @@ def execute(raw) # # => [{:_id=>1, :user_id=>nil, :s_title=>"Art 1", :comments_count=>nil, :umapped_column=>nil}] # # @example Map A Value From Result Set - # require 'lotus/model' + # require 'hanami/model' # # mapping do # collection :articles do @@ -664,12 +664,12 @@ def execute(raw) # end # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.titles # fetch("SELECT s_title FROM articles").map do |article| @@ -678,10 +678,10 @@ def execute(raw) # end # end # - # ArticleRepository.titles # => ["Announcing Lotus v0.5.0"] + # ArticleRepository.titles # => ["Announcing Hanami v0.5.0"] # # @example Passing A Block - # require 'lotus/model' + # require 'hanami/model' # # mapping do # collection :articles do @@ -691,12 +691,12 @@ def execute(raw) # end # # class Article - # include Lotus::Entity + # include Hanami::Entity # attributes :title, :body # end # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.titles # result = [] @@ -709,7 +709,7 @@ def execute(raw) # end # end # - # ArticleRepository.titles # => ["Announcing Lotus v0.5.0"] + # ArticleRepository.titles # => ["Announcing Hanami v0.5.0"] def fetch(raw, &blk) @adapter.fetch(raw, &blk) end @@ -733,10 +733,10 @@ def fetch(raw, &blk) # All the queries are delegated to the current adapter, which is # responsible to implement a querying API. # - # Lotus::Model is shipped with two adapters: + # Hanami::Model is shipped with two adapters: # - # * SqlAdapter, which yields a Lotus::Model::Adapters::Sql::Query - # * MemoryAdapter, which yields a Lotus::Model::Adapters::Memory::Query + # * SqlAdapter, which yields a Hanami::Model::Adapters::Sql::Query + # * MemoryAdapter, which yields a Hanami::Model::Adapters::Memory::Query # # @param blk [Proc] a block of code that is executed in the context of a # query @@ -746,14 +746,14 @@ def fetch(raw, &blk) # @api public # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query - # @see Lotus::Model::Adapters::Memory::Query + # @see Hanami::Model::Adapters::Sql::Query + # @see Hanami::Model::Adapters::Memory::Query # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ArticleRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.most_recent_by_author(author, limit = 8) # query do @@ -804,13 +804,13 @@ def query(&blk) # @api public # @since 0.1.0 # - # @see Lotus::Model::Adapters::Sql::Query#negate! + # @see Hanami::Model::Adapters::Sql::Query#negate! # # @example - # require 'lotus/model' + # require 'hanami/model' # # class ProjectRepository - # include Lotus::Repository + # include Hanami::Repository # # def self.cool # query do @@ -838,7 +838,7 @@ def _persisted?(entity) # Update timestamps # - # @param entity [Object, Lotus::Entity] the entity + # @param entity [Object, Hanami::Entity] the entity # # @api private # @since 0.3.1 @@ -856,7 +856,7 @@ def _touch(entity) # Check if the given entity has the given timestamp # - # @param entity [Object, Lotus::Entity] the entity + # @param entity [Object, Hanami::Entity] the entity # @param timestamp [Symbol] the timestamp name # # @return [TrueClass,FalseClass] diff --git a/lib/lotus-model.rb b/lib/lotus-model.rb deleted file mode 100644 index c1e3b548..00000000 --- a/lib/lotus-model.rb +++ /dev/null @@ -1 +0,0 @@ -require 'lotus/model' diff --git a/test/entity_test.rb b/test/entity_test.rb index 5452e18a..c2a78247 100644 --- a/test/entity_test.rb +++ b/test/entity_test.rb @@ -1,14 +1,14 @@ require 'test_helper' -describe Lotus::Entity do +describe Hanami::Entity do before do class Car - include Lotus::Entity + include Hanami::Entity end class Book - include Lotus::Entity - include Lotus::Entity::DirtyTracking + include Hanami::Entity + include Hanami::Entity::DirtyTracking attributes :title, :author, :published, :tags end @@ -21,7 +21,7 @@ class CoolNonFictionBook < NonFictionBook end class Camera - include Lotus::Entity + include Hanami::Entity attr_accessor :analog end end diff --git a/test/error_test.rb b/test/error_test.rb index b7ff2d13..034d7144 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -1,25 +1,25 @@ require 'test_helper' -require_relative '../lib/lotus/model/migrator.rb' +require_relative '../lib/hanami/model/migrator.rb' -describe Lotus::Model::Error do +describe Hanami::Model::Error do it 'inherits from ::StandardError' do - Lotus::Model::Error.superclass.must_equal StandardError + Hanami::Model::Error.superclass.must_equal StandardError end it 'is parent to all custom exception' do - Lotus::Model::NonPersistedEntityError.superclass.must_equal Lotus::Model::Error - Lotus::Model::InvalidMappingError.superclass.must_equal Lotus::Model::Error - Lotus::Model::InvalidCommandError.superclass.must_equal Lotus::Model::Error - Lotus::Model::InvalidQueryError.superclass.must_equal Lotus::Model::Error - Lotus::Model::Adapters::DatabaseAdapterNotFound.superclass.must_equal Lotus::Model::Error - Lotus::Model::Adapters::NotSupportedError.superclass.must_equal Lotus::Model::Error - Lotus::Model::Adapters::DisconnectedAdapterError.superclass.must_equal Lotus::Model::Error - Lotus::Model::Adapters::NoAdapterError.superclass.must_equal Lotus::Model::Error - Lotus::Model::Config::AdapterNotFound.superclass.must_equal Lotus::Model::Error - Lotus::Model::NoMappingError.superclass.must_equal Lotus::Model::Error - Lotus::Model::Mapping::UnmappedCollectionError.superclass.must_equal Lotus::Model::Error - Lotus::Model::Mapping::EntityNotFound.superclass.must_equal Lotus::Model::Error - Lotus::Model::Mapping::RepositoryNotFound.superclass.must_equal Lotus::Model::Error - Lotus::Model::MigrationError.superclass.must_equal Lotus::Model::Error + Hanami::Model::NonPersistedEntityError.superclass.must_equal Hanami::Model::Error + Hanami::Model::InvalidMappingError.superclass.must_equal Hanami::Model::Error + Hanami::Model::InvalidCommandError.superclass.must_equal Hanami::Model::Error + Hanami::Model::InvalidQueryError.superclass.must_equal Hanami::Model::Error + Hanami::Model::Adapters::DatabaseAdapterNotFound.superclass.must_equal Hanami::Model::Error + Hanami::Model::Adapters::NotSupportedError.superclass.must_equal Hanami::Model::Error + Hanami::Model::Adapters::DisconnectedAdapterError.superclass.must_equal Hanami::Model::Error + Hanami::Model::Adapters::NoAdapterError.superclass.must_equal Hanami::Model::Error + Hanami::Model::Config::AdapterNotFound.superclass.must_equal Hanami::Model::Error + Hanami::Model::NoMappingError.superclass.must_equal Hanami::Model::Error + Hanami::Model::Mapping::UnmappedCollectionError.superclass.must_equal Hanami::Model::Error + Hanami::Model::Mapping::EntityNotFound.superclass.must_equal Hanami::Model::Error + Hanami::Model::Mapping::RepositoryNotFound.superclass.must_equal Hanami::Model::Error + Hanami::Model::MigrationError.superclass.must_equal Hanami::Model::Error end end diff --git a/test/fixtures.rb b/test/fixtures.rb index a11c0610..018dfaad 100644 --- a/test/fixtures.rb +++ b/test/fixtures.rb @@ -1,35 +1,35 @@ require 'sequel/extensions/pg_array' class User - include Lotus::Entity + include Hanami::Entity attributes :name, :age, :created_at, :updated_at end class Article - include Lotus::Entity - include Lotus::Entity::DirtyTracking + include Hanami::Entity + include Hanami::Entity::DirtyTracking attributes :user_id, :unmapped_attribute, :title, :comments_count, :tags end class Repository - include Lotus::Entity + include Hanami::Entity attributes :id, :name end class CustomUserRepository - include Lotus::Repository + include Hanami::Repository end class UserRepository - include Lotus::Repository + include Hanami::Repository end class UnmappedRepository - include Lotus::Repository + include Hanami::Repository end class ArticleRepository - include Lotus::Repository + include Hanami::Repository def self.rank query do @@ -77,9 +77,9 @@ def self.map_titles end [SQLITE_CONNECTION_STRING, POSTGRES_CONNECTION_STRING].each do |conn_string| - require 'lotus/utils/io' + require 'hanami/utils/io' - Lotus::Utils::IO.silence_warnings do + Hanami::Utils::IO.silence_warnings do DB = Sequel.connect(conn_string) end @@ -129,7 +129,7 @@ def self.map_titles end end -class PGArray < Lotus::Model::Coercer +class PGArray < Hanami::Model::Coercer def self.dump(value) ::Sequel.pg_array(value) rescue nil end @@ -140,7 +140,7 @@ def self.load(value) end #FIXME this should be passed by the framework internals. -MAPPER = Lotus::Model::Mapper.new do +MAPPER = Hanami::Model::Mapper.new do collection :users do entity User diff --git a/test/fixtures/20150611165922_create_authors.rb b/test/fixtures/20150611165922_create_authors.rb index 7deacc68..be78f063 100644 --- a/test/fixtures/20150611165922_create_authors.rb +++ b/test/fixtures/20150611165922_create_authors.rb @@ -1,6 +1,6 @@ # This file is intentionally placed outside of test/fixtures/migrations to # simulate a pending migration. -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :authors do primary_key :id diff --git a/test/fixtures/database_migrations/20150612081248_column_types.rb b/test/fixtures/database_migrations/20150612081248_column_types.rb index 32cd3284..2b14a256 100644 --- a/test/fixtures/database_migrations/20150612081248_column_types.rb +++ b/test/fixtures/database_migrations/20150612081248_column_types.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :column_types do column :integer1, Integer diff --git a/test/fixtures/database_migrations/20150612084656_default_values.rb b/test/fixtures/database_migrations/20150612084656_default_values.rb index f183cba7..10a99df5 100644 --- a/test/fixtures/database_migrations/20150612084656_default_values.rb +++ b/test/fixtures/database_migrations/20150612084656_default_values.rb @@ -1,8 +1,8 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :default_values do column :a, Integer, default: 23 - column :b, String, default: "Lotus" + column :b, String, default: "Hanami" column :c, Fixnum, default: -1 column :d, Bignum, default: 0 column :e, Float, default: 3.14 diff --git a/test/fixtures/database_migrations/20150612093458_null_constraints.rb b/test/fixtures/database_migrations/20150612093458_null_constraints.rb index ec317663..f6470f77 100644 --- a/test/fixtures/database_migrations/20150612093458_null_constraints.rb +++ b/test/fixtures/database_migrations/20150612093458_null_constraints.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :null_constraints do column :a, Integer diff --git a/test/fixtures/database_migrations/20150612093810_column_indexes.rb b/test/fixtures/database_migrations/20150612093810_column_indexes.rb index 3ebaca02..80601123 100644 --- a/test/fixtures/database_migrations/20150612093810_column_indexes.rb +++ b/test/fixtures/database_migrations/20150612093810_column_indexes.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :column_indexes do column :a, Integer diff --git a/test/fixtures/database_migrations/20150612094740_primary_keys.rb b/test/fixtures/database_migrations/20150612094740_primary_keys.rb index efe4dbb5..ba903265 100644 --- a/test/fixtures/database_migrations/20150612094740_primary_keys.rb +++ b/test/fixtures/database_migrations/20150612094740_primary_keys.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :primary_keys_1 do primary_key :id diff --git a/test/fixtures/database_migrations/20150612115204_foreign_keys.rb b/test/fixtures/database_migrations/20150612115204_foreign_keys.rb index 4b0d79fd..8583259a 100644 --- a/test/fixtures/database_migrations/20150612115204_foreign_keys.rb +++ b/test/fixtures/database_migrations/20150612115204_foreign_keys.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :artists do primary_key :id diff --git a/test/fixtures/database_migrations/20150612122233_table_constraints.rb b/test/fixtures/database_migrations/20150612122233_table_constraints.rb index 86657ab2..105b5cce 100644 --- a/test/fixtures/database_migrations/20150612122233_table_constraints.rb +++ b/test/fixtures/database_migrations/20150612122233_table_constraints.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :table_constraints do column :age, Integer diff --git a/test/fixtures/database_migrations/20150612124205_table_alterations.rb b/test/fixtures/database_migrations/20150612124205_table_alterations.rb index 37ed6592..334414bc 100644 --- a/test/fixtures/database_migrations/20150612124205_table_alterations.rb +++ b/test/fixtures/database_migrations/20150612124205_table_alterations.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do change do create_table :songs do column :title, String diff --git a/test/fixtures/migrations/20150610133853_create_books.rb b/test/fixtures/migrations/20150610133853_create_books.rb index 8a7f64a5..bfba9ab5 100644 --- a/test/fixtures/migrations/20150610133853_create_books.rb +++ b/test/fixtures/migrations/20150610133853_create_books.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do up do create_table :books do primary_key :id diff --git a/test/fixtures/migrations/20150610141017_add_price_to_books.rb b/test/fixtures/migrations/20150610141017_add_price_to_books.rb index 7cd45ca4..bb09e55c 100644 --- a/test/fixtures/migrations/20150610141017_add_price_to_books.rb +++ b/test/fixtures/migrations/20150610141017_add_price_to_books.rb @@ -1,4 +1,4 @@ -Lotus::Model.migration do +Hanami::Model.migration do up do add_column :books, :price, 'integer', default: 100 end diff --git a/test/integration/configuration_test.rb b/test/integration/configuration_test.rb index cc2402a6..402d72ca 100644 --- a/test/integration/configuration_test.rb +++ b/test/integration/configuration_test.rb @@ -2,7 +2,7 @@ describe 'Configuration DSL' do before do - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :memory, uri: 'memory://localhost' mapping do @@ -16,11 +16,11 @@ end end - Lotus::Model.load! + Hanami::Model.load! end after do - Lotus::Model.unload! + Hanami::Model.unload! end describe 'when creating new user' do @@ -41,7 +41,7 @@ describe "when a repository isn't mapped" do it 'raises an error when try to use it' do - exception = -> { UnmappedRepository.find(1) }.must_raise(Lotus::Model::Adapters::NoAdapterError) + exception = -> { UnmappedRepository.find(1) }.must_raise(Hanami::Model::Adapters::NoAdapterError) exception.message.must_equal( "Cannot invoke `find' on repository. "\ "Please check if `adapter' and `mapping' are set, "\ @@ -52,15 +52,15 @@ describe 'when mapping is not set' do before do - Lotus::Model.unload! + Hanami::Model.unload! - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :memory, uri: 'memory://localhost' end end it 'raises an error when try to use it' do - exception = -> { Lotus::Model.load! }.must_raise(Lotus::Model::NoMappingError) + exception = -> { Hanami::Model.load! }.must_raise(Hanami::Model::NoMappingError) exception.message.must_equal("Mapping is missing. Please check your framework configuration.") end end diff --git a/test/integration/migration/memory_test.rb b/test/integration/migration/memory_test.rb index 6e9a8e29..1dba174b 100644 --- a/test/integration/migration/memory_test.rb +++ b/test/integration/migration/memory_test.rb @@ -1,28 +1,28 @@ require 'test_helper' -require 'lotus/model/migrator' +require 'hanami/model/migrator' describe 'Memory Database Migration' do - let(:adapter_prefix) { 'jdbc:' if Lotus::Utils.jruby? } + let(:adapter_prefix) { 'jdbc:' if Hanami::Utils.jruby? } # Unfornatelly we need to explicitly include `::memory:` for JDBC # https://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/jdbc/sqlite.rb#L61 # - let(:adapter_sufix) { Lotus::Utils.jruby? ? ':memory:' : '/' } + let(:adapter_sufix) { Hanami::Utils.jruby? ? ':memory:' : '/' } before do - Lotus::Model.unload! + Hanami::Model.unload! end after do - Lotus::Model::Migrator.drop rescue nil - Lotus::Model.unload! + Hanami::Model::Migrator.drop rescue nil + Hanami::Model.unload! end describe 'SQLite In Memory' do before do @uri = uri = "#{ adapter_prefix }sqlite:#{ adapter_sufix }" - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: uri migrations __dir__ + '/../../fixtures/migrations' end @@ -34,7 +34,7 @@ describe "create" do it "does nothing" do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create connection = Sequel.connect(@uri) connection.tables.must_be :empty? @@ -43,11 +43,11 @@ describe "drop" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "does nothing" do - Lotus::Model::Migrator.drop + Hanami::Model::Migrator.drop connection = Sequel.connect(@uri) connection.tables.must_be :empty? @@ -56,22 +56,22 @@ describe "migrate" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations" do before do @migrations_root = migrations_root = Pathname.new(__dir__ + '/../../fixtures/empty_migrations') - Lotus::Model.configure do + Hanami::Model.configure do migrations migrations_root end - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "it doesn't alter database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end end end diff --git a/test/integration/migration/mysql_test.rb b/test/integration/migration/mysql_test.rb index f06df768..ec85cf1d 100644 --- a/test/integration/migration/mysql_test.rb +++ b/test/integration/migration/mysql_test.rb @@ -1,30 +1,30 @@ require 'test_helper' -require 'lotus/model/migrator' +require 'hanami/model/migrator' describe 'Mysql database migrations' do - let(:adapter_prefix) { 'jdbc:' if Lotus::Utils.jruby? } + let(:adapter_prefix) { 'jdbc:' if Hanami::Utils.jruby? } let(:db_prefix) { name.gsub(/[^\w]/, '_') } let(:random_token) { SecureRandom.hex(4) } before do - Lotus::Model.unload! + Hanami::Model.unload! end after do - Lotus::Model::Migrator.drop rescue nil - Lotus::Model.unload! + Hanami::Model::Migrator.drop rescue nil + Hanami::Model.unload! end ['mysql', 'mysql2'].each do |scheme| describe "MySQL" do - let(:adapter) { Lotus::Utils.jruby? ? 'mysql' : scheme } + let(:adapter) { Hanami::Utils.jruby? ? 'mysql' : scheme } before do @database = "#{ db_prefix }_#{ random_token }" @uri = uri = "#{ adapter_prefix }#{ adapter }://localhost/#{ @database }?user=#{ MYSQL_USER }" - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: uri migrations __dir__ + '/../../fixtures/migrations' end @@ -32,7 +32,7 @@ describe "create" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "creates the database" do @@ -42,7 +42,7 @@ it 'raises error if database is busy' do Sequel.connect(@uri).tables - exception = -> { Lotus::Model::Migrator.create }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.create }.must_raise Hanami::Model::MigrationError exception.message.must_include 'Database creation failed' exception.message.must_include 'There is 1 other session using the database' end @@ -50,39 +50,39 @@ describe "drop" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "drops the database" do - Lotus::Model::Migrator.drop + Hanami::Model::Migrator.drop -> { Sequel.connect(@uri).tables }.must_raise Sequel::DatabaseConnectionError end it "raises error if database doesn't exist" do - Lotus::Model::Migrator.drop # remove the first time + Hanami::Model::Migrator.drop # remove the first time - exception = -> { Lotus::Model::Migrator.drop }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.drop }.must_raise Hanami::Model::MigrationError exception.message.must_equal "Cannot find database: #{ @database }" end end describe "migrate" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations" do before do @migrations_root = migrations_root = Pathname.new(__dir__ + '/../../fixtures/empty_migrations') - Lotus::Model.configure do + Hanami::Model.configure do migrations migrations_root end end it "it doesn't alter database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.must_be :empty? @@ -91,7 +91,7 @@ describe "when migrations are present" do it "migrates the database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -130,11 +130,11 @@ describe "when migrations are ran twice" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "doesn't alter the schema" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -144,11 +144,11 @@ describe "migrate down" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "migrates the database" do - Lotus::Model::Migrator.migrate(version: '20150610133853') + Hanami::Model::Migrator.migrate(version: '20150610133853') connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -190,16 +190,16 @@ migrations_root.mkpath FileUtils.cp_r(fixtures_root, migrations_root) - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri migrations migrations_root.join('migrations') schema migrations_root.join('schema-mysql.sql') end - Lotus::Model::Migrator.create - Lotus::Model::Migrator.apply + Hanami::Model::Migrator.create + Hanami::Model::Migrator.apply end it "migrates to latest version" do @@ -250,8 +250,8 @@ migrations_root.mkpath FileUtils.cp_r(fixtures_root, migrations_root) - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri migrations migrations_root.join('migrations') @@ -266,7 +266,7 @@ FileUtils.cp 'test/fixtures/20150611165922_create_authors.rb', @migrations_root.join('migrations/20150611165922_create_authors.rb') - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.prepare connection.tables.must_include(:schema_migrations) connection.tables.must_include(:books) @@ -280,7 +280,7 @@ @migrations_root.join('migrations/20150611165922_create_authors.rb').delete rescue nil @migrations_root.join('schema-mysql.sql').delete rescue nil - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.prepare connection = Sequel.connect(@uri) connection.tables.must_include(:schema_migrations) @@ -288,8 +288,8 @@ end it "drops the database and recreate it" do - Lotus::Model::Migrator.create - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.create + Hanami::Model::Migrator.prepare connection = Sequel.connect(@uri) connection.tables.must_include(:schema_migrations) @@ -299,23 +299,23 @@ describe "version" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations were ran" do it "returns nil" do - version = Lotus::Model::Migrator.version + version = Hanami::Model::Migrator.version version.must_be_nil end end describe "with migrations" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "returns current database version" do - version = Lotus::Model::Migrator.version + version = Hanami::Model::Migrator.version version.must_equal "20150610141017" end end diff --git a/test/integration/migration/postgres_test.rb b/test/integration/migration/postgres_test.rb index 0c147ca5..01abff47 100644 --- a/test/integration/migration/postgres_test.rb +++ b/test/integration/migration/postgres_test.rb @@ -1,18 +1,18 @@ require 'test_helper' -require 'lotus/model/migrator' +require 'hanami/model/migrator' describe 'PostgreSQL Database migrations' do - let(:adapter_prefix) { 'jdbc:' if Lotus::Utils.jruby? } + let(:adapter_prefix) { 'jdbc:' if Hanami::Utils.jruby? } let(:db_prefix) { name.gsub(/[^\w]/, '_') } let(:random_token) { SecureRandom.hex(4) } before do - Lotus::Model.unload! + Hanami::Model.unload! end after do - Lotus::Model::Migrator.drop rescue nil - Lotus::Model.unload! + Hanami::Model::Migrator.drop rescue nil + Hanami::Model.unload! end describe "PostgreSQL" do @@ -20,7 +20,7 @@ @database = "#{ db_prefix }_#{ random_token }" @uri = uri = "#{ adapter_prefix }postgresql://127.0.0.1/#{ @database }?user=#{ POSTGRES_USER }" - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: uri migrations __dir__ + '/../../fixtures/migrations' end @@ -32,7 +32,7 @@ describe "create" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "creates the database" do @@ -42,7 +42,7 @@ it 'raises error if database is busy' do Sequel.connect(@uri).tables - exception = -> { Lotus::Model::Migrator.create }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.create }.must_raise Hanami::Model::MigrationError exception.message.must_include 'createdb: database creation failed' exception.message.must_include 'There is 1 other session using the database' end @@ -50,24 +50,24 @@ describe "drop" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "drops the database" do - Lotus::Model::Migrator.drop + Hanami::Model::Migrator.drop -> { Sequel.connect(@uri).tables }.must_raise Sequel::DatabaseConnectionError end it "raises error if database doesn't exist" do - Lotus::Model::Migrator.drop # remove the first time - exception = -> { Lotus::Model::Migrator.drop }.must_raise Lotus::Model::MigrationError + Hanami::Model::Migrator.drop # remove the first time + exception = -> { Hanami::Model::Migrator.drop }.must_raise Hanami::Model::MigrationError exception.message.must_equal "Cannot find database: #{ @database }" end it 'raises error if database is busy' do Sequel.connect(@uri).tables - exception = -> { Lotus::Model::Migrator.drop }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.drop }.must_raise Hanami::Model::MigrationError exception.message.must_include 'dropdb: database removal failed' exception.message.must_include 'There is 1 other session using the database' end @@ -85,7 +85,7 @@ end it "raises MigrationError on create" do - exception = -> { Lotus::Model::Migrator.create }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.create }.must_raise Hanami::Model::MigrationError exception.message.must_equal "No such file or directory - createdb" end end @@ -93,20 +93,20 @@ describe "migrate" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations" do before do @migrations_root = migrations_root = Pathname.new(__dir__ + '/../../fixtures/empty_migrations') - Lotus::Model.configure do + Hanami::Model.configure do migrations migrations_root end end it "it doesn't alter database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.must_be :empty? @@ -115,7 +115,7 @@ describe "when migrations are present" do it "migrates the database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -154,11 +154,11 @@ describe "when migrations are ran twice" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "doesn't alter the schema" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -168,11 +168,11 @@ describe "migrate down" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "migrates the database" do - Lotus::Model::Migrator.migrate(version: '20150610133853') + Hanami::Model::Migrator.migrate(version: '20150610133853') connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -214,16 +214,16 @@ migrations_root.mkpath FileUtils.cp_r(fixtures_root, migrations_root) - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri migrations migrations_root.join('migrations') schema migrations_root.join('schema-postgres.sql') end - Lotus::Model::Migrator.create - Lotus::Model::Migrator.apply + Hanami::Model::Migrator.create + Hanami::Model::Migrator.apply end it "migrates to latest version" do @@ -298,8 +298,8 @@ migrations_root.mkpath FileUtils.cp_r(fixtures_root, migrations_root) - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri migrations migrations_root.join('migrations') @@ -314,7 +314,7 @@ FileUtils.cp 'test/fixtures/20150611165922_create_authors.rb', @migrations_root.join('migrations/20150611165922_create_authors.rb') - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.prepare connection.tables.must_include(:schema_migrations) connection.tables.must_include(:books) @@ -328,15 +328,15 @@ @migrations_root.join('migrations/20150611165922_create_authors.rb').delete rescue nil @migrations_root.join('schema-postgres.sql').delete rescue nil - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.prepare connection = Sequel.connect(@uri) connection.tables.must_equal [:schema_migrations, :books] end it "drops the database and recreate it" do - Lotus::Model::Migrator.create - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.create + Hanami::Model::Migrator.prepare connection = Sequel.connect(@uri) connection.tables.must_include(:schema_migrations) @@ -346,23 +346,23 @@ describe "version" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations were ran" do it "returns nil" do - version = Lotus::Model::Migrator.version + version = Hanami::Model::Migrator.version version.must_be_nil end end describe "with migrations" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "returns current database version" do - version = Lotus::Model::Migrator.version + version = Hanami::Model::Migrator.version version.must_equal "20150610141017" end end diff --git a/test/integration/migration/sqlite_test.rb b/test/integration/migration/sqlite_test.rb index e563cc8a..b13f2ec9 100644 --- a/test/integration/migration/sqlite_test.rb +++ b/test/integration/migration/sqlite_test.rb @@ -1,16 +1,16 @@ require 'test_helper' -require 'lotus/model/migrator' +require 'hanami/model/migrator' describe 'Filesystem SQLite Database migrations' do - let(:adapter_prefix) { 'jdbc:' if Lotus::Utils.jruby? } + let(:adapter_prefix) { 'jdbc:' if Hanami::Utils.jruby? } before do - Lotus::Model.unload! + Hanami::Model.unload! end after do - Lotus::Model::Migrator.drop rescue nil - Lotus::Model.unload! + Hanami::Model::Migrator.drop rescue nil + Hanami::Model.unload! end describe "SQLite filesystem" do @@ -18,7 +18,7 @@ @database = Pathname.new("#{ __dir__ }/../../../tmp/create-#{ SecureRandom.hex }.sqlite3").expand_path @uri = uri = "#{ adapter_prefix }sqlite://#{ @database }" - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: uri migrations __dir__ + '/../../fixtures/migrations' end @@ -26,7 +26,7 @@ describe "create" do it "creates the database" do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create assert File.exist?(@database), "Expected database #{ @database } to exist" end @@ -35,14 +35,14 @@ @database = '/usr/bin/create.sqlite3' @uri = uri = "#{ adapter_prefix }sqlite://#{ @database }" - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri end end it "raises an error" do - exception = -> { Lotus::Model::Migrator.create }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.create }.must_raise Hanami::Model::MigrationError exception.message.must_equal "Permission denied: /usr/bin/create.sqlite3" end end @@ -50,40 +50,40 @@ describe "drop" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "drops the database" do - Lotus::Model::Migrator.drop + Hanami::Model::Migrator.drop assert !File.exist?(@database), "Expected database #{ @database } to NOT exist" end it "raises error if database doesn't exist" do - Lotus::Model::Migrator.drop # remove the first time + Hanami::Model::Migrator.drop # remove the first time - exception = -> { Lotus::Model::Migrator.drop }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.drop }.must_raise Hanami::Model::MigrationError exception.message.must_equal "Cannot find database: #{ @database }" end end describe "migrate" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations" do before do @migrations_root = migrations_root = Pathname.new(__dir__ + '/../../fixtures/empty_migrations') - Lotus::Model.configure do + Hanami::Model.configure do migrations migrations_root end - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end it "it doesn't alter database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.must_be :empty? @@ -92,7 +92,7 @@ describe "when migrations are present" do it "migrates the database" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -131,11 +131,11 @@ describe "when migrations are ran twice" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "doesn't alter the schema" do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -145,11 +145,11 @@ describe "migrate down" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "migrates the database" do - Lotus::Model::Migrator.migrate(version: '20150610133853') + Hanami::Model::Migrator.migrate(version: '20150610133853') connection = Sequel.connect(@uri) connection.tables.wont_be :empty? @@ -191,19 +191,19 @@ migrations_root.mkpath FileUtils.cp_r(fixtures_root, migrations_root) - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri migrations migrations_root.join('migrations') schema migrations_root.join('schema-sqlite.sql') end - Lotus::Model::Migrator.apply + Hanami::Model::Migrator.apply end after do - Lotus::Model.unload! + Hanami::Model.unload! end it "migrates to latest version" do @@ -236,8 +236,8 @@ migrations_root.mkpath FileUtils.cp_r(fixtures_root, migrations_root) - Lotus::Model.unload! - Lotus::Model.configure do + Hanami::Model.unload! + Hanami::Model.configure do adapter type: :sql, uri: uri migrations migrations_root.join('migrations') @@ -248,12 +248,12 @@ it "creates database, loads schema and migrate" do # Simulate already existing schema.sql, without existing database and pending migrations connection = Sequel.connect(@uri) - Lotus::Model::Migrator::Adapter.for(connection).dump + Hanami::Model::Migrator::Adapter.for(connection).dump FileUtils.cp 'test/fixtures/20150611165922_create_authors.rb', @migrations_root.join('migrations/20150611165922_create_authors.rb') - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.prepare connection.tables.must_equal [:schema_migrations, :books, :authors] @@ -263,15 +263,15 @@ it "works even if schema doesn't exist" do # Simulate no database, no schema and pending migrations FileUtils.rm_f @migrations_root.join('schema-sqlite.sql') - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.prepare connection = Sequel.connect(@uri) connection.tables.must_equal [:schema_migrations, :books] end it "drops the database and recreate it" do - Lotus::Model::Migrator.create - Lotus::Model::Migrator.prepare + Hanami::Model::Migrator.create + Hanami::Model::Migrator.prepare connection = Sequel.connect(@uri) connection.tables.must_include(:schema_migrations) @@ -281,23 +281,23 @@ describe "version" do before do - Lotus::Model::Migrator.create + Hanami::Model::Migrator.create end describe "when no migrations were ran" do it "returns nil" do - version = Lotus::Model::Migrator.version + version = Hanami::Model::Migrator.version version.must_be_nil end end describe "with migrations" do before do - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.migrate end it "returns current database version" do - version = Lotus::Model::Migrator.version + version = Hanami::Model::Migrator.version version.must_equal "20150610141017" end end diff --git a/test/integration/migration_test.rb b/test/integration/migration_test.rb index fc2a40ab..cbb5369e 100644 --- a/test/integration/migration_test.rb +++ b/test/integration/migration_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -require 'lotus/model/migrator' +require 'hanami/model/migrator' -describe "Lotus::Model.migration" do - let(:adapter_prefix) { 'jdbc:' if Lotus::Utils.jruby? } +describe "Hanami::Model.migration" do + let(:adapter_prefix) { 'jdbc:' if Hanami::Utils.jruby? } describe "SQLite" do before do @@ -10,17 +10,17 @@ @schema = schema_path = Pathname.new("#{ __dir__ }/../../tmp/schema.sql").expand_path @uri = uri = "#{ adapter_prefix }sqlite://#{ @database }" - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: uri migrations __dir__ + '/../fixtures/database_migrations' schema schema_path end - Lotus::Model::Migrator.create - Lotus::Model::Migrator.migrate + Hanami::Model::Migrator.create + Hanami::Model::Migrator.migrate @connection = Sequel.connect(@uri) - Lotus::Model::Migrator::Adapter.for(@connection).dump + Hanami::Model::Migrator::Adapter.for(@connection).dump end after(:each) do @@ -29,7 +29,7 @@ end after(:each) do - Lotus::Model.unload! + Hanami::Model.unload! @connection.disconnect end @@ -291,8 +291,8 @@ name.must_equal :b options.fetch(:allow_null).must_equal true - options.fetch(:default).must_equal "'Lotus'" - options.fetch(:ruby_default).must_equal "Lotus" + options.fetch(:default).must_equal "'Hanami'" + options.fetch(:ruby_default).must_equal "Hanami" options.fetch(:type).must_equal :string options.fetch(:db_type).must_equal "varchar(255)" options.fetch(:primary_key).must_equal false @@ -494,14 +494,14 @@ describe "File system" do before do - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :file_system, uri: "file:///db/test417_development" end end describe "connection" do it "return error" do - exception = -> { Lotus::Model::Migrator.create }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.create }.must_raise Hanami::Model::MigrationError exception.message.must_include "Current adapter (file_system) doesn't support SQL database operations." end end @@ -509,14 +509,14 @@ describe "Memory" do before do - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :memory, uri: "memory://localhost" end end describe "connection" do it "return error" do - exception = -> { Lotus::Model::Migrator.create }.must_raise Lotus::Model::MigrationError + exception = -> { Hanami::Model::Migrator.create }.must_raise Hanami::Model::MigrationError exception.message.must_include "Current adapter (memory) doesn't support SQL database operations." end end diff --git a/test/integration/repository_test.rb b/test/integration/repository_test.rb index 60823488..4b25c434 100644 --- a/test/integration/repository_test.rb +++ b/test/integration/repository_test.rb @@ -1,19 +1,19 @@ require 'test_helper' -describe Lotus::Repository do +describe Hanami::Repository do let(:user1) { User.new(name: 'L') } let(:user2) { User.new(name: 'MG') } let(:users) { [user1, user2] } - let(:article1) { Article.new(user_id: user1.id, title: 'Introducing Lotus::Model', comments_count: '23') } + let(:article1) { Article.new(user_id: user1.id, title: 'Introducing Hanami::Model', comments_count: '23') } let(:article2) { Article.new(user_id: user1.id, title: 'Thread safety', comments_count: '42') } let(:article3) { Article.new(user_id: user2.id, title: 'Love Relationships', comments_count: '4') } { - memory: [Lotus::Model::Adapters::MemoryAdapter, nil, MAPPER], - file_system: [Lotus::Model::Adapters::FileSystemAdapter, FILE_SYSTEM_CONNECTION_STRING, MAPPER], - sqlite: [Lotus::Model::Adapters::SqlAdapter, SQLITE_CONNECTION_STRING, MAPPER], - postgres: [Lotus::Model::Adapters::SqlAdapter, POSTGRES_CONNECTION_STRING, MAPPER], + memory: [Hanami::Model::Adapters::MemoryAdapter, nil, MAPPER], + file_system: [Hanami::Model::Adapters::FileSystemAdapter, FILE_SYSTEM_CONNECTION_STRING, MAPPER], + sqlite: [Hanami::Model::Adapters::SqlAdapter, SQLITE_CONNECTION_STRING, MAPPER], + postgres: [Hanami::Model::Adapters::SqlAdapter, POSTGRES_CONNECTION_STRING, MAPPER], }.each do |adapter_name, (adapter,uri,mapper)| describe "with #{ adapter_name } adapter" do before do @@ -68,7 +68,7 @@ if adapter_name == :postgres it 'should use custom coercers' do - article = Article.new(title: 'Coercer', tags: tags = ['ruby', 'lotus']) + article = Article.new(title: 'Coercer', tags: tags = ['ruby', 'hanami']) article = ArticleRepository.persist(article) article.tags.must_equal tags @@ -96,7 +96,7 @@ # Ensure we're updating sufficiently later of the creation, we can get realy close dates in # concurrent platforms like jRuby - sleep 2 if Lotus::Utils.jruby? + sleep 2 if Hanami::Utils.jruby? end it 'should return that entity' do @@ -184,7 +184,7 @@ # Ensure we're updating sufficiently later of the creation, we can get realy close dates in # concurrent platforms like jRuby - sleep 2 if Lotus::Utils.jruby? + sleep 2 if Hanami::Utils.jruby? end it 'updates entities' do @@ -203,7 +203,7 @@ end it 'raises an error when not persisted' do - -> { UserRepository.update(user2) }.must_raise(Lotus::Model::NonPersistedEntityError) + -> { UserRepository.update(user2) }.must_raise(Hanami::Model::NonPersistedEntityError) end end @@ -220,7 +220,7 @@ end it 'raises error when the given entity is not persisted' do - -> { UserRepository.delete(user2) }.must_raise(Lotus::Model::NonPersistedEntityError) + -> { UserRepository.delete(user2) }.must_raise(Hanami::Model::NonPersistedEntityError) end end @@ -410,7 +410,7 @@ def to_int describe 'missing timestamps attribute' do describe '.persist' do before do - @article = ArticleRepository.persist(Article.new(title: 'Lotus', comments_count: '4')) + @article = ArticleRepository.persist(Article.new(title: 'Hanami', comments_count: '4')) @article.instance_eval do def created_at @created_at @@ -444,8 +444,8 @@ def updated_at describe "with sql adapter" do before do - UserRepository.adapter = Lotus::Model::Adapters::SqlAdapter.new(MAPPER, SQLITE_CONNECTION_STRING) - ArticleRepository.adapter = Lotus::Model::Adapters::SqlAdapter.new(MAPPER, SQLITE_CONNECTION_STRING) + UserRepository.adapter = Hanami::Model::Adapters::SqlAdapter.new(MAPPER, SQLITE_CONNECTION_STRING) + ArticleRepository.adapter = Hanami::Model::Adapters::SqlAdapter.new(MAPPER, SQLITE_CONNECTION_STRING) UserRepository.collection = :users ArticleRepository.collection = :articles @@ -555,8 +555,8 @@ def updated_at describe "with memory adapter" do before do - UserRepository.adapter = Lotus::Model::Adapters::MemoryAdapter.new(MAPPER, nil) - ArticleRepository.adapter = Lotus::Model::Adapters::MemoryAdapter.new(MAPPER, nil) + UserRepository.adapter = Hanami::Model::Adapters::MemoryAdapter.new(MAPPER, nil) + ArticleRepository.adapter = Hanami::Model::Adapters::MemoryAdapter.new(MAPPER, nil) UserRepository.collection = :users ArticleRepository.collection = :articles diff --git a/test/integration/validations_compatibility_test.rb b/test/integration/validations_compatibility_test.rb index fb1a2023..f07bddea 100644 --- a/test/integration/validations_compatibility_test.rb +++ b/test/integration/validations_compatibility_test.rb @@ -1,11 +1,11 @@ require 'test_helper' -require 'lotus/validations' +require 'hanami/validations' -describe 'Lotus::Validations compatibility' do +describe 'Hanami::Validations compatibility' do before do class Product - include Lotus::Entity - include Lotus::Validations + include Hanami::Entity + include Hanami::Validations attribute :price, type: Integer attributes :price diff --git a/test/migrator/connection_test.rb b/test/migrator/connection_test.rb index 8e7e719a..d415ccbd 100644 --- a/test/migrator/connection_test.rb +++ b/test/migrator/connection_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -require 'lotus/model/migrator/connection' +require 'hanami/model/migrator/connection' -describe Lotus::Model::Migrator::Connection do - let(:connection) { Lotus::Model::Migrator::Connection.new(adapter_connection) } +describe Hanami::Model::Migrator::Connection do + let(:connection) { Hanami::Model::Migrator::Connection.new(adapter_connection) } let(:adapter_connection) do OpenStruct.new( diff --git a/test/model/adapters/abstract_test.rb b/test/model/adapters/abstract_test.rb index 55927264..eb1bc406 100644 --- a/test/model/adapters/abstract_test.rb +++ b/test/model/adapters/abstract_test.rb @@ -1,7 +1,7 @@ require 'test_helper' -describe Lotus::Model::Adapters::Abstract do - let(:adapter) { Lotus::Model::Adapters::Abstract.new(mapper) } +describe Hanami::Model::Adapters::Abstract do + let(:adapter) { Hanami::Model::Adapters::Abstract.new(mapper) } let(:mapper) { Object.new } let(:entity) { Object.new } let(:query) { Object.new } @@ -81,7 +81,7 @@ describe '#connection_string' do it 'raises error' do - -> { adapter.connection_string }.must_raise Lotus::Model::Adapters::NotSupportedError + -> { adapter.connection_string }.must_raise Hanami::Model::Adapters::NotSupportedError end end end diff --git a/test/model/adapters/file_system_adapter_test.rb b/test/model/adapters/file_system_adapter_test.rb index cf5c43b5..6f7c58db 100644 --- a/test/model/adapters/file_system_adapter_test.rb +++ b/test/model/adapters/file_system_adapter_test.rb @@ -1,24 +1,24 @@ require 'test_helper' -describe Lotus::Model::Adapters::FileSystemAdapter do +describe Hanami::Model::Adapters::FileSystemAdapter do before do TestUser = Struct.new(:id, :name, :age) do - include Lotus::Entity + include Hanami::Entity end class TestUserRepository - include Lotus::Repository + include Hanami::Repository end TestDevice = Struct.new(:id) do - include Lotus::Entity + include Hanami::Entity end class TestDeviceRepository - include Lotus::Repository + include Hanami::Repository end - @mapper = Lotus::Model::Mapper.new do + @mapper = Hanami::Model::Mapper.new do collection :users do entity TestUser @@ -46,10 +46,10 @@ class TestDeviceRepository end.load! - @adapter = Lotus::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) + @adapter = Hanami::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) @adapter.clear(collection) - @verifier = Lotus::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) + @verifier = Hanami::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) end after do @@ -77,7 +77,7 @@ class TestDeviceRepository describe '#initialize' do before do - @adapter = Lotus::Model::Adapters::FileSystemAdapter.new(@mapper, uri) + @adapter = Hanami::Model::Adapters::FileSystemAdapter.new(@mapper, uri) end after do @@ -113,7 +113,7 @@ class TestDeviceRepository end # BUG - # See: https://github.com/lotus/model/issues/151 + # See: https://github.com/hanami/model/issues/151 describe 'when already present database' do before do data = Pathname.new(FILE_SYSTEM_CONNECTION_STRING) @@ -121,10 +121,10 @@ class TestDeviceRepository @user1 = TestUser.new(name: 'L') @user2 = TestUser.new(name: 'MG') - old_data = Lotus::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) + old_data = Hanami::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) @user1 = old_data.persist(collection, @user1) - @adapter = Lotus::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) + @adapter = Hanami::Model::Adapters::FileSystemAdapter.new(@mapper, FILE_SYSTEM_CONNECTION_STRING) end it 'reads the old data' do @@ -1172,7 +1172,7 @@ class TestDeviceRepository end it 'raises error' do - exception = -> { @adapter.create(collection, TestUser.new) }.must_raise Lotus::Model::Adapters::DisconnectedAdapterError + exception = -> { @adapter.create(collection, TestUser.new) }.must_raise Hanami::Model::Adapters::DisconnectedAdapterError exception.message.must_match "You have tried to perform an operation on a disconnected adapter" end end diff --git a/test/model/adapters/implementation_test.rb b/test/model/adapters/implementation_test.rb index 2709a4fd..3aee733f 100644 --- a/test/model/adapters/implementation_test.rb +++ b/test/model/adapters/implementation_test.rb @@ -1,9 +1,9 @@ require 'test_helper' -describe Lotus::Model::Adapters::Implementation do +describe Hanami::Model::Adapters::Implementation do before do - TestAdapter = Class.new(Lotus::Model::Adapters::Abstract) do - include Lotus::Model::Adapters::Implementation + TestAdapter = Class.new(Hanami::Model::Adapters::Abstract) do + include Hanami::Model::Adapters::Implementation end mapper = Object.new diff --git a/test/model/adapters/memory/query_test.rb b/test/model/adapters/memory/query_test.rb index 4d5787b0..48c90e76 100644 --- a/test/model/adapters/memory/query_test.rb +++ b/test/model/adapters/memory/query_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -describe Lotus::Model::Adapters::Memory::Query do +describe Hanami::Model::Adapters::Memory::Query do before do MockDataset = Struct.new(:records) do def all @@ -19,7 +19,7 @@ def deserialize(array) end collection = MockCollection.new - @query = Lotus::Model::Adapters::Memory::Query.new(dataset, collection) + @query = Hanami::Model::Adapters::Memory::Query.new(dataset, collection) end after do diff --git a/test/model/adapters/memory_adapter_test.rb b/test/model/adapters/memory_adapter_test.rb index 5f594911..2f840bfc 100644 --- a/test/model/adapters/memory_adapter_test.rb +++ b/test/model/adapters/memory_adapter_test.rb @@ -1,24 +1,24 @@ require 'test_helper' -describe Lotus::Model::Adapters::MemoryAdapter do +describe Hanami::Model::Adapters::MemoryAdapter do before do TestUser = Struct.new(:id, :name, :age) do - include Lotus::Entity + include Hanami::Entity end class TestUserRepository - include Lotus::Repository + include Hanami::Repository end TestDevice = Struct.new(:id) do - include Lotus::Entity + include Hanami::Entity end class TestDeviceRepository - include Lotus::Repository + include Hanami::Repository end - @mapper = Lotus::Model::Mapper.new do + @mapper = Hanami::Model::Mapper.new do collection :users do entity TestUser @@ -34,7 +34,7 @@ class TestDeviceRepository end end.load! - @adapter = Lotus::Model::Adapters::MemoryAdapter.new(@mapper) + @adapter = Hanami::Model::Adapters::MemoryAdapter.new(@mapper) end after do @@ -371,7 +371,7 @@ class TestDeviceRepository exception = -> { query = Proc.new { where { a > 32 } } @adapter.query(collection, &query).all - }.must_raise(Lotus::Model::InvalidQueryError) + }.must_raise(Hanami::Model::InvalidQueryError) exception.message.must_equal "Invalid query" end @@ -464,7 +464,7 @@ class TestDeviceRepository exception = -> { query = Proc.new { exclude { a > 32 } } @adapter.query(collection, &query).all - }.must_raise(Lotus::Model::InvalidQueryError) + }.must_raise(Hanami::Model::InvalidQueryError) exception.message.must_equal "Invalid query" end @@ -543,7 +543,7 @@ class TestDeviceRepository exception = -> { query = Proc.new { where(name: "MG").or { a > 31 } } @adapter.query(collection, &query).all - }.must_raise(Lotus::Model::InvalidQueryError) + }.must_raise(Hanami::Model::InvalidQueryError) exception.message.must_equal "Invalid query" end @@ -1214,7 +1214,7 @@ class TestDeviceRepository end it 'raises error' do - exception = -> { @adapter.create(collection, TestUser.new) }.must_raise Lotus::Model::Adapters::DisconnectedAdapterError + exception = -> { @adapter.create(collection, TestUser.new) }.must_raise Hanami::Model::Adapters::DisconnectedAdapterError exception.message.must_match "You have tried to perform an operation on a disconnected adapter" end end diff --git a/test/model/adapters/sql/command_test.rb b/test/model/adapters/sql/command_test.rb index 20d7f74c..78f8ebf6 100644 --- a/test/model/adapters/sql/command_test.rb +++ b/test/model/adapters/sql/command_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -describe Lotus::Model::Adapters::Sql::Command do +describe Hanami::Model::Adapters::Sql::Command do let(:collection) { Object.new } let(:query) do query = Object.new @@ -10,56 +10,56 @@ end before do - @command = Lotus::Model::Adapters::Sql::Command.new(query) + @command = Hanami::Model::Adapters::Sql::Command.new(query) end describe '#create' do describe 'when a Sequel::ForeignKeyConstraintViolation is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:insert) do |_| raise ::Sequel::ForeignKeyConstraintViolation.new('fkey constraint error') end - exception = -> { @command.create(Object.new) }.must_raise(Lotus::Model::Error) + exception = -> { @command.create(Object.new) }.must_raise(Hanami::Model::Error) exception.message.must_equal('fkey constraint error') end end describe 'when a Sequel::CheckConstraintViolation is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:insert) do |_| raise ::Sequel::CheckConstraintViolation.new('check constraint error') end - exception = -> { @command.create(Object.new) }.must_raise(Lotus::Model::Error) + exception = -> { @command.create(Object.new) }.must_raise(Hanami::Model::Error) exception.message.must_equal('check constraint error') end end describe 'when a Sequel::NotNullConstraintViolation is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:insert) do |_| raise ::Sequel::NotNullConstraintViolation.new('not null constraint error') end - exception = -> { @command.create(Object.new) }.must_raise(Lotus::Model::Error) + exception = -> { @command.create(Object.new) }.must_raise(Hanami::Model::Error) exception.message.must_equal('not null constraint error') end end describe 'when a Sequel::UniqueConstraintViolation is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:insert) do |_| raise ::Sequel::UniqueConstraintViolation.new('unique constraint error') end - exception = -> { @command.create(Object.new) }.must_raise(Lotus::Model::Error) + exception = -> { @command.create(Object.new) }.must_raise(Hanami::Model::Error) exception.message.must_equal('unique constraint error') end end describe 'when a Sequel::DatabaseError is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:insert) do |_| raise ::Sequel::DatabaseError.new('db error') end - exception = -> { @command.create(Object.new) }.must_raise(Lotus::Model::Error) + exception = -> { @command.create(Object.new) }.must_raise(Hanami::Model::Error) exception.message.must_equal('db error') end end @@ -77,11 +77,11 @@ describe '#update' do describe 'when a Sequel::DatabaseError is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:update) do |_| raise Sequel::DatabaseError.new('db error') end - exception = -> { @command.update(Object.new) }.must_raise(Lotus::Model::Error) + exception = -> { @command.update(Object.new) }.must_raise(Hanami::Model::Error) exception.message.must_equal('db error') end end @@ -99,11 +99,11 @@ describe '#delete' do describe 'when a Sequel::DatabaseError is raised' do - it 'raises Lotus::Model::Error exception' do + it 'raises Hanami::Model::Error exception' do collection.define_singleton_method(:delete) do raise Sequel::DatabaseError.new('db error') end - exception = -> { @command.delete }.must_raise(Lotus::Model::Error) + exception = -> { @command.delete }.must_raise(Hanami::Model::Error) exception.message.must_equal('db error') end end diff --git a/test/model/adapters/sql/consoles/mysql_test.rb b/test/model/adapters/sql/consoles/mysql_test.rb index 21a1183f..3882785b 100644 --- a/test/model/adapters/sql/consoles/mysql_test.rb +++ b/test/model/adapters/sql/consoles/mysql_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -require 'lotus/model/adapters/sql/consoles/mysql' +require 'hanami/model/adapters/sql/consoles/mysql' -describe Lotus::Model::Adapters::Sql::Consoles::Mysql do - let(:console) { Lotus::Model::Adapters::Sql::Consoles::Mysql.new(uri) } +describe Hanami::Model::Adapters::Sql::Consoles::Mysql do + let(:console) { Hanami::Model::Adapters::Sql::Consoles::Mysql.new(uri) } describe '#connection_string' do let(:uri) { URI.parse('mysql://username:password@localhost:1234/foo_development') } diff --git a/test/model/adapters/sql/consoles/postgresql_test.rb b/test/model/adapters/sql/consoles/postgresql_test.rb index 9477f0a2..76479b78 100644 --- a/test/model/adapters/sql/consoles/postgresql_test.rb +++ b/test/model/adapters/sql/consoles/postgresql_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -require 'lotus/model/adapters/sql/consoles/postgresql' +require 'hanami/model/adapters/sql/consoles/postgresql' -describe Lotus::Model::Adapters::Sql::Consoles::Postgresql do - let(:console) { Lotus::Model::Adapters::Sql::Consoles::Postgresql.new(uri) } +describe Hanami::Model::Adapters::Sql::Consoles::Postgresql do + let(:console) { Hanami::Model::Adapters::Sql::Consoles::Postgresql.new(uri) } describe '#connection_string' do let(:uri) { URI.parse('postgres://username:password@localhost:1234/foo_development') } diff --git a/test/model/adapters/sql/consoles/sqlite_test.rb b/test/model/adapters/sql/consoles/sqlite_test.rb index 460dcd12..685d577f 100644 --- a/test/model/adapters/sql/consoles/sqlite_test.rb +++ b/test/model/adapters/sql/consoles/sqlite_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -require 'lotus/model/adapters/sql/consoles/sqlite' +require 'hanami/model/adapters/sql/consoles/sqlite' -describe Lotus::Model::Adapters::Sql::Consoles::Sqlite do - let(:console) { Lotus::Model::Adapters::Sql::Consoles::Sqlite.new(uri) } +describe Hanami::Model::Adapters::Sql::Consoles::Sqlite do + let(:console) { Hanami::Model::Adapters::Sql::Consoles::Sqlite.new(uri) } describe '#connection_string' do describe 'with shell ok database uri' do diff --git a/test/model/adapters/sql/query_test.rb b/test/model/adapters/sql/query_test.rb index bb369055..3a4cc5e5 100644 --- a/test/model/adapters/sql/query_test.rb +++ b/test/model/adapters/sql/query_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -describe Lotus::Model::Adapters::Sql::Query do +describe Hanami::Model::Adapters::Sql::Query do before do - @query = Lotus::Model::Adapters::Sql::Query.new(collection) + @query = Hanami::Model::Adapters::Sql::Query.new(collection) end let(:collection) { [] } diff --git a/test/model/adapters/sql_adapter_test.rb b/test/model/adapters/sql_adapter_test.rb index 7c49986e..44de9b2d 100644 --- a/test/model/adapters/sql_adapter_test.rb +++ b/test/model/adapters/sql_adapter_test.rb @@ -1,58 +1,58 @@ require 'test_helper' -describe Lotus::Model::Adapters::SqlAdapter do +describe Hanami::Model::Adapters::SqlAdapter do before do class TestUser - include Lotus::Entity + include Hanami::Entity attributes :country_id, :name, :age end class TestUserRepository - include Lotus::Repository + include Hanami::Repository end class TestDevice - include Lotus::Entity + include Hanami::Entity attributes :u_id end class TestDeviceRepository - include Lotus::Repository + include Hanami::Repository end class TestOrder - include Lotus::Entity + include Hanami::Entity attributes :user_id, :total end class TestOrderRepository - include Lotus::Repository + include Hanami::Repository end class TestAge - include Lotus::Entity + include Hanami::Entity attributes :value, :label end class TestAgeRepository - include Lotus::Repository + include Hanami::Repository end class TestCountry - include Lotus::Entity + include Hanami::Entity attributes :code, :country_id end class TestCountryRepository - include Lotus::Repository + include Hanami::Repository end - @mapper = Lotus::Model::Mapper.new do + @mapper = Hanami::Model::Mapper.new do collection :users do entity TestUser @@ -94,7 +94,7 @@ class TestCountryRepository end end.load! - @adapter = Lotus::Model::Adapters::SqlAdapter.new(@mapper, SQLITE_CONNECTION_STRING) + @adapter = Hanami::Model::Adapters::SqlAdapter.new(@mapper, SQLITE_CONNECTION_STRING) @adapter.clear(collection) end @@ -133,19 +133,19 @@ class TestCountryRepository describe '#initialize' do it 'raises an error when the given URI refers to a non registered database adapter' do -> { - Lotus::Model::Adapters::SqlAdapter.new(@mapper, 'oracle://host') - }.must_raise(Lotus::Model::Adapters::DatabaseAdapterNotFound) + Hanami::Model::Adapters::SqlAdapter.new(@mapper, 'oracle://host') + }.must_raise(Hanami::Model::Adapters::DatabaseAdapterNotFound) end it 'raises an error when the given URI refers to an unknown database adapter' do -> { - Lotus::Model::Adapters::SqlAdapter.new(@mapper, 'unknown://host') - }.must_raise(Lotus::Model::Adapters::DatabaseAdapterNotFound) + Hanami::Model::Adapters::SqlAdapter.new(@mapper, 'unknown://host') + }.must_raise(Hanami::Model::Adapters::DatabaseAdapterNotFound) end it 'raises an error when the given URI is malformed' do -> { - Lotus::Model::Adapters::SqlAdapter.new(@mapper, 'unknown_db:host') + Hanami::Model::Adapters::SqlAdapter.new(@mapper, 'unknown_db:host') }.must_raise(URI::InvalidURIError) end @@ -153,7 +153,7 @@ class TestCountryRepository spy = nil after_connect_spy_proc = Proc.new { spy = true } - adapter = Lotus::Model::Adapters::SqlAdapter.new(@mapper, + adapter = Hanami::Model::Adapters::SqlAdapter.new(@mapper, SQLITE_CONNECTION_STRING, after_connect: after_connect_spy_proc) # Sequel lazily connects @@ -421,7 +421,7 @@ class TestCountryRepository exception = -> { query = Proc.new { where { a > 31 } } @adapter.query(collection, &query).all - }.must_raise(Lotus::Model::InvalidQueryError) + }.must_raise(Hanami::Model::InvalidQueryError) exception.message.wont_be_nil end @@ -496,7 +496,7 @@ class TestCountryRepository exception = -> { query = Proc.new { exclude{ a > 32 } } @adapter.query(collection, &query).all - }.must_raise(Lotus::Model::InvalidQueryError) + }.must_raise(Hanami::Model::InvalidQueryError) exception.message.wont_be_nil end @@ -579,7 +579,7 @@ class TestCountryRepository query = Proc.new { where(name: name1).or(n: name2) } @adapter.query(collection, &query).all - }.must_raise(Lotus::Model::InvalidQueryError) + }.must_raise(Hanami::Model::InvalidQueryError) exception.message.wont_be_nil end @@ -1280,7 +1280,7 @@ class TestCountryRepository it 'raises an exception when invalid sql is provided' do raw = "UPDATE users SET foo=22" - -> { @adapter.execute(raw) }.must_raise Lotus::Model::InvalidCommandError + -> { @adapter.execute(raw) }.must_raise Hanami::Model::InvalidCommandError end end @@ -1314,7 +1314,7 @@ class TestCountryRepository # In theory `execute` yields result set in a block # https://github.com/jeremyevans/sequel/blob/54fa82326d3319d9aca4409c07f79edc09da3837/lib/sequel/adapters/sqlite.rb#L126-L129 # - # Would be interesting in future to wrap these results into Lotus result_sets, independent from + # Would be interesting in future to wrap these results into Hanami result_sets, independent from # Sequel adapter # records = [] @@ -1328,7 +1328,7 @@ class TestCountryRepository it 'raises an exception when an invalid sql is provided' do raw = "SELECT foo FROM users" - -> { @adapter.fetch(raw) }.must_raise Lotus::Model::InvalidQueryError + -> { @adapter.fetch(raw) }.must_raise Hanami::Model::InvalidQueryError end end @@ -1388,7 +1388,7 @@ class TestCountryRepository end it 'raises error' do - exception = -> { @adapter.create(collection, user1) }.must_raise Lotus::Model::Adapters::DisconnectedAdapterError + exception = -> { @adapter.create(collection, user1) }.must_raise Hanami::Model::Adapters::DisconnectedAdapterError exception.message.must_match "You have tried to perform an operation on a disconnected adapter" end end diff --git a/test/model/adapters/sql_joins_test.rb b/test/model/adapters/sql_joins_test.rb index f788a288..75e2f538 100644 --- a/test/model/adapters/sql_joins_test.rb +++ b/test/model/adapters/sql_joins_test.rb @@ -1,59 +1,59 @@ require 'test_helper' -require 'lotus/model/migrator' +require 'hanami/model/migrator' describe 'SQL joins test' do before do class TestUser - include Lotus::Entity + include Hanami::Entity attributes :country_id, :name, :age end class TestUserRepository - include Lotus::Repository + include Hanami::Repository end class TestDevice - include Lotus::Entity + include Hanami::Entity attributes :u_id end class TestDeviceRepository - include Lotus::Repository + include Hanami::Repository end class TestOrder - include Lotus::Entity + include Hanami::Entity attributes :user_id, :total end class TestOrderRepository - include Lotus::Repository + include Hanami::Repository end class TestAge - include Lotus::Entity + include Hanami::Entity attributes :value, :label end class TestAgeRepository - include Lotus::Repository + include Hanami::Repository end class TestCountry - include Lotus::Entity + include Hanami::Entity attributes :code, :country_id end class TestCountryRepository - include Lotus::Repository + include Hanami::Repository end - @mapper = Lotus::Model::Mapper.new do + @mapper = Hanami::Model::Mapper.new do collection :users do entity TestUser @@ -95,7 +95,7 @@ class TestCountryRepository end end.load! - @adapter = Lotus::Model::Adapters::SqlAdapter.new(@mapper, SQLITE_CONNECTION_STRING) + @adapter = Hanami::Model::Adapters::SqlAdapter.new(@mapper, SQLITE_CONNECTION_STRING) end after do diff --git a/test/model/coercer_test.rb b/test/model/coercer_test.rb index bcc003fd..302348c8 100644 --- a/test/model/coercer_test.rb +++ b/test/model/coercer_test.rb @@ -1,15 +1,15 @@ require 'test_helper' -describe Lotus::Model::Coercer do +describe Hanami::Model::Coercer do describe '.load' do it 'raises error' do - -> { Lotus::Model::Coercer.load(23) }.must_raise NotImplementedError + -> { Hanami::Model::Coercer.load(23) }.must_raise NotImplementedError end end describe '.dump' do it 'raises error' do - -> { Lotus::Model::Coercer.dump(23) }.must_raise NotImplementedError + -> { Hanami::Model::Coercer.dump(23) }.must_raise NotImplementedError end end end diff --git a/test/model/config/adapter_test.rb b/test/model/config/adapter_test.rb index fded5691..c180fff8 100644 --- a/test/model/config/adapter_test.rb +++ b/test/model/config/adapter_test.rb @@ -1,40 +1,40 @@ require 'test_helper' -describe Lotus::Model::Config::Adapter do +describe Hanami::Model::Config::Adapter do describe 'initialize' do it 'sets other adapater options' do after_connect_proc = -> {} - config = Lotus::Model::Config::Adapter.new(type: :memory, uri: nil, after_connect: after_connect_proc) + config = Hanami::Model::Config::Adapter.new(type: :memory, uri: nil, after_connect: after_connect_proc) config.options.must_equal({after_connect: after_connect_proc}) end end describe '#build' do - let(:mapper) { Lotus::Model::Mapper.new } + let(:mapper) { Hanami::Model::Mapper.new } let(:adapter) { config.build(mapper) } describe 'given adapter type is memory' do - let(:config) { Lotus::Model::Config::Adapter.new(type: :memory) } + let(:config) { Hanami::Model::Config::Adapter.new(type: :memory) } it 'instantiates memory adapter' do adapter = config.build(mapper) - adapter.must_be_kind_of Lotus::Model::Adapters::MemoryAdapter + adapter.must_be_kind_of Hanami::Model::Adapters::MemoryAdapter end end describe 'given adapter type is SQL' do - let(:config) { Lotus::Model::Config::Adapter.new(type: :sql, uri: SQLITE_CONNECTION_STRING) } + let(:config) { Hanami::Model::Config::Adapter.new(type: :sql, uri: SQLITE_CONNECTION_STRING) } it 'instantiates SQL adapter' do adapter = config.build(mapper) - adapter.must_be_kind_of Lotus::Model::Adapters::SqlAdapter + adapter.must_be_kind_of Hanami::Model::Adapters::SqlAdapter end end describe 'given adapter type is not found' do - let(:config) { Lotus::Model::Config::Adapter.new(type: :redis, uri: 'redis://not_exist') } + let(:config) { Hanami::Model::Config::Adapter.new(type: :redis, uri: 'redis://not_exist') } it 'raises an error' do -> { config.build(mapper) }.must_raise(LoadError) @@ -42,11 +42,11 @@ end describe 'given adapter class is not found' do - let(:config) { Lotus::Model::Config::Adapter.new(type: :redis, uri: SQLITE_CONNECTION_STRING) } + let(:config) { Hanami::Model::Config::Adapter.new(type: :redis, uri: SQLITE_CONNECTION_STRING) } it 'raises an error' do config.stub(:load_adapter, nil) do - -> { config.build(mapper) }.must_raise(Lotus::Model::Config::AdapterNotFound) + -> { config.build(mapper) }.must_raise(Hanami::Model::Config::AdapterNotFound) end end end diff --git a/test/model/config/mapper_test.rb b/test/model/config/mapper_test.rb index ddd201e2..ff139d66 100644 --- a/test/model/config/mapper_test.rb +++ b/test/model/config/mapper_test.rb @@ -1,17 +1,17 @@ require 'test_helper' -describe Lotus::Model::Config::Mapper do +describe Hanami::Model::Config::Mapper do describe '#initialize' do describe 'when no block or file path is given' do it 'raises error' do - exception = -> { Lotus::Model::Config::Mapper.new }.must_raise Lotus::Model::InvalidMappingError + exception = -> { Hanami::Model::Config::Mapper.new }.must_raise Hanami::Model::InvalidMappingError exception.message.must_equal 'You must specify a block or a file.' end end describe "when a block is given" do it 'converts block to proc and save in an instance' do - config = Lotus::Model::Config::Mapper.new do + config = Hanami::Model::Config::Mapper.new do collection :users do entity User @@ -26,7 +26,7 @@ describe "when a path is given" do it 'stores the path to mapping file' do - config = Lotus::Model::Config::Mapper.new('test/fixtures/mapping') + config = Hanami::Model::Config::Mapper.new('test/fixtures/mapping') config.instance_variable_get(:@path).must_equal Pathname.new("#{Dir.pwd}/test/fixtures/mapping") end end @@ -35,7 +35,7 @@ describe '#to_proc' do describe 'when block is given' do it 'returns the proc of the block' do - config = Lotus::Model::Config::Mapper.new do + config = Hanami::Model::Config::Mapper.new do collection :users do entity User @@ -50,7 +50,7 @@ describe 'when a file is given' do it 'reads the content of the file and return a proc of content' do - config = Lotus::Model::Config::Mapper.new('test/fixtures/mapping') + config = Hanami::Model::Config::Mapper.new('test/fixtures/mapping') assert config.to_proc.is_a?(Proc) end @@ -58,7 +58,7 @@ describe 'when an invalid file is given' do it 'raises error' do - exception = -> { Lotus::Model::Config::Mapper.new('test/fixtures/invalid').to_proc }.must_raise ArgumentError + exception = -> { Hanami::Model::Config::Mapper.new('test/fixtures/invalid').to_proc }.must_raise ArgumentError exception.message.must_equal 'You must specify a valid filepath.' end end diff --git a/test/model/configuration_test.rb b/test/model/configuration_test.rb index 7b4906f7..76522404 100644 --- a/test/model/configuration_test.rb +++ b/test/model/configuration_test.rb @@ -1,7 +1,7 @@ require 'test_helper' -describe Lotus::Model::Configuration do - let(:configuration) { Lotus::Model::Configuration.new } +describe Hanami::Model::Configuration do + let(:configuration) { Hanami::Model::Configuration.new } describe '#adapter_config' do it 'defaults to an empty set' do @@ -13,11 +13,11 @@ configuration.adapter(type: :sql, uri: SQLITE_CONNECTION_STRING) adapter_config = configuration.adapter_config - adapter_config.must_be_instance_of Lotus::Model::Config::Adapter + adapter_config.must_be_instance_of Hanami::Model::Config::Adapter adapter_config.uri.must_equal SQLITE_CONNECTION_STRING end - if Lotus::Utils.jruby? + if Hanami::Utils.jruby? it 'avoids duplication' do configuration.adapter(type: :sql, uri: 'jdbc:sqlite:uri') configuration.adapter(type: :memory, uri: 'memory://uri') @@ -61,7 +61,7 @@ configuration.load! adapter = configuration.instance_variable_get(:@adapter) - adapter.must_be_instance_of Lotus::Model::Adapters::MemoryAdapter + adapter.must_be_instance_of Hanami::Model::Adapters::MemoryAdapter end it 'instantiates the registered adapter (file system)' do @@ -69,7 +69,7 @@ configuration.load! adapter = configuration.instance_variable_get(:@adapter) - adapter.must_be_instance_of Lotus::Model::Adapters::FileSystemAdapter + adapter.must_be_instance_of Hanami::Model::Adapters::FileSystemAdapter end it 'instantiates the registered adapter (sql)' do @@ -77,7 +77,7 @@ configuration.load! adapter = configuration.instance_variable_get(:@adapter) - adapter.must_be_instance_of Lotus::Model::Adapters::SqlAdapter + adapter.must_be_instance_of Hanami::Model::Adapters::SqlAdapter end it 'builds collections from mapping' do @@ -85,7 +85,7 @@ configuration.load! collection = configuration.mapper.collection(:users) - collection.must_be_kind_of Lotus::Model::Mapping::Collection + collection.must_be_kind_of Hanami::Model::Mapping::Collection collection.name.must_equal :users end end @@ -103,7 +103,7 @@ end mapper_config = configuration.instance_variable_get(:@mapper_config) - mapper_config.must_be_instance_of Lotus::Model::Config::Mapper + mapper_config.must_be_instance_of Hanami::Model::Config::Mapper end end @@ -112,13 +112,13 @@ configuration.mapping 'test/fixtures/mapping' mapper_config = configuration.instance_variable_get(:@mapper_config) - mapper_config.must_be_instance_of Lotus::Model::Config::Mapper + mapper_config.must_be_instance_of Hanami::Model::Config::Mapper end end describe "when block and path are not given" do it 'raise error' do - exception = -> { configuration.mapping }.must_raise Lotus::Model::InvalidMappingError + exception = -> { configuration.mapping }.must_raise Hanami::Model::InvalidMappingError exception.message.must_equal 'You must specify a block or a file.' end end @@ -189,7 +189,7 @@ it 'resets mapper' do configuration.instance_variable_get(:@mapper_config).must_be_nil - configuration.mapper.must_be_instance_of Lotus::Model::NullMapper + configuration.mapper.must_be_instance_of Hanami::Model::NullMapper end it 'resets migrations' do diff --git a/test/model/mapper_test.rb b/test/model/mapper_test.rb index d7c48d36..2daeb65d 100644 --- a/test/model/mapper_test.rb +++ b/test/model/mapper_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -describe Lotus::Model::Mapper do +describe Hanami::Model::Mapper do before do - @mapper = Lotus::Model::Mapper.new + @mapper = Hanami::Model::Mapper.new end describe '#initialize' do @@ -16,7 +16,7 @@ class FakeCoercer end it 'uses the given coercer' do - mapper = Lotus::Model::Mapper.new(FakeCoercer) do + mapper = Hanami::Model::Mapper.new(FakeCoercer) do collection :articles do end end @@ -25,19 +25,19 @@ class FakeCoercer end it 'executes the given block' do - mapper = Lotus::Model::Mapper.new do + mapper = Hanami::Model::Mapper.new do collection :articles do entity Article end end.load! - mapper.collection(:articles).must_be_kind_of Lotus::Model::Mapping::Collection + mapper.collection(:articles).must_be_kind_of Hanami::Model::Mapping::Collection end end describe '#collections' do before do - @mapper = Lotus::Model::Mapper.new do + @mapper = Hanami::Model::Mapper.new do collection :teas do end end @@ -47,7 +47,7 @@ class FakeCoercer name, collection = @mapper.collections.first name.must_equal :teas - collection.must_be_kind_of Lotus::Model::Mapping::Collection + collection.must_be_kind_of Hanami::Model::Mapping::Collection end end @@ -61,7 +61,7 @@ class FakeCoercer @mapper.load! collection = @mapper.collection(:users) - collection.must_be_kind_of Lotus::Model::Mapping::Collection + collection.must_be_kind_of Hanami::Model::Mapping::Collection collection.name.must_equal :users end end @@ -79,14 +79,14 @@ class FakeCoercer it 'returns the collection' do collection = @mapper.collection(:users) - collection.must_be_kind_of(Lotus::Model::Mapping::Collection) + collection.must_be_kind_of(Hanami::Model::Mapping::Collection) collection.name.must_equal :users end end describe 'and the collection is missing' do it 'raises an error' do - -> { @mapper.collection(:unknown) }.must_raise(Lotus::Model::Mapping::UnmappedCollectionError) + -> { @mapper.collection(:unknown) }.must_raise(Hanami::Model::Mapping::UnmappedCollectionError) end end end diff --git a/test/model/mapping/coercers_test.rb b/test/model/mapping/coercers_test.rb index ba0e4bd0..183abd09 100644 --- a/test/model/mapping/coercers_test.rb +++ b/test/model/mapping/coercers_test.rb @@ -2,197 +2,197 @@ SIGNATURE_METHODS = %w(load dump).freeze -describe Lotus::Model::Mapping::Coercers::Array do +describe Hanami::Model::Mapping::Coercers::Array do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into an array' do - actual = Lotus::Model::Mapping::Coercers::Array.__send__(m, 1) + actual = Hanami::Model::Mapping::Coercers::Array.__send__(m, 1) actual.must_equal [1] end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Array.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Array.__send__(m, nil) actual.must_be_nil end it 'preserves data structure' do - actual = Lotus::Model::Mapping::Coercers::Array.__send__(m, expected = [['lotus-controller', '~> 0.4'], ['lotus-view', '~> 0.4']]) + actual = Hanami::Model::Mapping::Coercers::Array.__send__(m, expected = [['hanami-controller', '~> 0.4'], ['hanami-view', '~> 0.4']]) actual.must_equal expected end end end end -describe Lotus::Model::Mapping::Coercers::Boolean do +describe Hanami::Model::Mapping::Coercers::Boolean do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a boolean' do - actual = Lotus::Model::Mapping::Coercers::Boolean.__send__(m, '1') + actual = Hanami::Model::Mapping::Coercers::Boolean.__send__(m, '1') actual.must_equal true end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Boolean.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Boolean.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::Date do +describe Hanami::Model::Mapping::Coercers::Date do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a date' do - actual = Lotus::Model::Mapping::Coercers::Date.__send__(m, Date.today) + actual = Hanami::Model::Mapping::Coercers::Date.__send__(m, Date.today) actual.must_equal Date.today end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Date.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Date.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::DateTime do +describe Hanami::Model::Mapping::Coercers::DateTime do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a datetime' do - actual = Lotus::Model::Mapping::Coercers::DateTime.__send__(m, DateTime.now) + actual = Hanami::Model::Mapping::Coercers::DateTime.__send__(m, DateTime.now) actual.to_s.must_equal DateTime.now.to_s end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::DateTime.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::DateTime.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::Float do +describe Hanami::Model::Mapping::Coercers::Float do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a float' do - actual = Lotus::Model::Mapping::Coercers::Float.__send__(m, 1) + actual = Hanami::Model::Mapping::Coercers::Float.__send__(m, 1) actual.must_equal 1.0 end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Float.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Float.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::Hash do +describe Hanami::Model::Mapping::Coercers::Hash do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a hash' do - actual = Lotus::Model::Mapping::Coercers::Hash.__send__(m, []) + actual = Hanami::Model::Mapping::Coercers::Hash.__send__(m, []) actual.must_equal({}) end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Hash.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Hash.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::Integer do +describe Hanami::Model::Mapping::Coercers::Integer do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into an integer' do - actual = Lotus::Model::Mapping::Coercers::Integer.__send__(m, '23') + actual = Hanami::Model::Mapping::Coercers::Integer.__send__(m, '23') actual.must_equal 23 end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Integer.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Integer.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::BigDecimal do +describe Hanami::Model::Mapping::Coercers::BigDecimal do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a BigDecimal' do - actual = Lotus::Model::Mapping::Coercers::BigDecimal.__send__(m, '23') + actual = Hanami::Model::Mapping::Coercers::BigDecimal.__send__(m, '23') actual.must_equal BigDecimal.new(23) end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::BigDecimal.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::BigDecimal.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::Set do +describe Hanami::Model::Mapping::Coercers::Set do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a set' do - actual = Lotus::Model::Mapping::Coercers::Set.__send__(m, [1,1]) + actual = Hanami::Model::Mapping::Coercers::Set.__send__(m, [1,1]) actual.must_equal Set.new([1]) end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Set.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Set.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::String do +describe Hanami::Model::Mapping::Coercers::String do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a string' do - actual = Lotus::Model::Mapping::Coercers::String.__send__(m, 12) + actual = Hanami::Model::Mapping::Coercers::String.__send__(m, 12) actual.must_equal '12' end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::String.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::String.__send__(m, nil) actual.must_be_nil end end end end -describe Lotus::Model::Mapping::Coercers::Symbol do +describe Hanami::Model::Mapping::Coercers::Symbol do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a symbol' do - actual = Lotus::Model::Mapping::Coercers::Symbol.__send__(m, 'wat') + actual = Hanami::Model::Mapping::Coercers::Symbol.__send__(m, 'wat') actual.must_equal :wat end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Symbol.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Symbol.__send__(m, nil) actual.must_equal nil end end end end -describe Lotus::Model::Mapping::Coercers::Time do +describe Hanami::Model::Mapping::Coercers::Time do SIGNATURE_METHODS.each do |m| describe ".#{ m }" do it 'converts the input into a string' do - actual = Lotus::Model::Mapping::Coercers::Time.__send__(m, 0) + actual = Hanami::Model::Mapping::Coercers::Time.__send__(m, 0) actual.must_equal Time.at(0) end it 'returns nil when nil is given' do - actual = Lotus::Model::Mapping::Coercers::Time.__send__(m, nil) + actual = Hanami::Model::Mapping::Coercers::Time.__send__(m, nil) actual.must_be_nil end end diff --git a/test/model/mapping/collection_coercer_test.rb b/test/model/mapping/collection_coercer_test.rb index f696d96d..9cbf8081 100644 --- a/test/model/mapping/collection_coercer_test.rb +++ b/test/model/mapping/collection_coercer_test.rb @@ -1,9 +1,9 @@ require 'test_helper' -describe Lotus::Model::Mapping::CollectionCoercer do +describe Hanami::Model::Mapping::CollectionCoercer do let(:entity) { User.new(name: 'Tyrion Lannister') } - let(:collection) { Lotus::Model::Mapping::Collection.new(:users, Lotus::Model::Mapping::CollectionCoercer) } - let(:coercer) { Lotus::Model::Mapping::CollectionCoercer.new(collection) } + let(:collection) { Hanami::Model::Mapping::Collection.new(:users, Hanami::Model::Mapping::CollectionCoercer) } + let(:coercer) { Hanami::Model::Mapping::CollectionCoercer.new(collection) } before do collection.entity(User) @@ -19,7 +19,7 @@ describe 'new record' do # Bug: - # https://github.com/lotus/model/issues/155 + # https://github.com/hanami/model/issues/155 it 'ignores unset values' do entity = User.new(name: 'Daenerys Targaryen') coercer.to_record(entity).must_equal(name: 'Daenerys Targaryen') diff --git a/test/model/mapping/collection_test.rb b/test/model/mapping/collection_test.rb index d9df5240..95f06627 100644 --- a/test/model/mapping/collection_test.rb +++ b/test/model/mapping/collection_test.rb @@ -1,8 +1,8 @@ require 'test_helper' -describe Lotus::Model::Mapping::Collection do +describe Hanami::Model::Mapping::Collection do before do - @collection = Lotus::Model::Mapping::Collection.new(:users, Lotus::Model::Mapping::CollectionCoercer) + @collection = Hanami::Model::Mapping::Collection.new(:users, Hanami::Model::Mapping::CollectionCoercer) end describe '#initialize' do @@ -11,11 +11,11 @@ end it 'assigns the coercer class' do - @collection.coercer_class.must_equal Lotus::Model::Mapping::CollectionCoercer + @collection.coercer_class.must_equal Hanami::Model::Mapping::CollectionCoercer end it 'executes the given block' do - collection = Lotus::Model::Mapping::Collection.new(:users, Lotus::Model::Mapping::CollectionCoercer) do + collection = Hanami::Model::Mapping::Collection.new(:users, Hanami::Model::Mapping::CollectionCoercer) do entity User end @@ -112,17 +112,17 @@ end it 'defines an attribute' do - @collection.attributes[:id].must_equal Lotus::Model::Mapping::Attribute.new(:id, Integer, {}) + @collection.attributes[:id].must_equal Hanami::Model::Mapping::Attribute.new(:id, Integer, {}) end it 'defines a mapped attribute' do - @collection.attributes[:name].must_equal Lotus::Model::Mapping::Attribute.new(:name, String, as: :t_name) + @collection.attributes[:name].must_equal Hanami::Model::Mapping::Attribute.new(:name, String, as: :t_name) end end describe '#load!' do before do - @adapter = Lotus::Model::Adapters::SqlAdapter.new(nil, SQLITE_CONNECTION_STRING) + @adapter = Hanami::Model::Adapters::SqlAdapter.new(nil, SQLITE_CONNECTION_STRING) @collection.entity('User') @collection.repository('UserRepository') @collection.adapter = @adapter @@ -143,30 +143,30 @@ end it 'instantiates coercer' do - @collection.instance_variable_get(:@coercer).must_be_instance_of Lotus::Model::Mapping::CollectionCoercer + @collection.instance_variable_get(:@coercer).must_be_instance_of Hanami::Model::Mapping::CollectionCoercer end describe 'when entity class does not exist' do before do - @collection = Lotus::Model::Mapping::Collection.new(:users, Lotus::Model::Mapping::CollectionCoercer) + @collection = Hanami::Model::Mapping::Collection.new(:users, Hanami::Model::Mapping::CollectionCoercer) @collection.entity('NonExistingUser') @collection.repository('UserRepository') end it 'raises error' do - -> { @collection.load! }.must_raise(Lotus::Model::Mapping::EntityNotFound) + -> { @collection.load! }.must_raise(Hanami::Model::Mapping::EntityNotFound) end end describe 'when repository class does not exist' do before do - @collection = Lotus::Model::Mapping::Collection.new(:users, Lotus::Model::Mapping::CollectionCoercer) + @collection = Hanami::Model::Mapping::Collection.new(:users, Hanami::Model::Mapping::CollectionCoercer) @collection.entity('User') @collection.repository('NonExistingUserRepository') end it 'raises error' do - -> { @collection.load! }.must_raise(Lotus::Model::Mapping::RepositoryNotFound) + -> { @collection.load! }.must_raise(Hanami::Model::Mapping::RepositoryNotFound) end end end diff --git a/test/model_test.rb b/test/model_test.rb index 5f1264a1..ae92bc11 100644 --- a/test/model_test.rb +++ b/test/model_test.rb @@ -1,19 +1,19 @@ require 'test_helper' -describe Lotus::Model do +describe Hanami::Model do before do - Lotus::Model.unload! + Hanami::Model.unload! end describe '.configuration' do it 'exposes class configuration' do - Lotus::Model.configuration.must_be_kind_of(Lotus::Model::Configuration) + Hanami::Model.configuration.must_be_kind_of(Hanami::Model::Configuration) end end describe '.duplicate' do before do - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: 'postgres://localhost/database' mapping do @@ -27,14 +27,14 @@ end module Duplicated - Model = Lotus::Model.duplicate(self) + Model = Hanami::Model.duplicate(self) end module DuplicatedConfigure - Model = Lotus::Model.duplicate(self) do + Model = Hanami::Model.duplicate(self) do reset! - if Lotus::Utils.jruby? + if Hanami::Utils.jruby? adapter type: :sql, uri: 'jdbc:sqlite:path/database.sqlite3' else adapter type: :sql, uri: 'sqlite3://path/database.sqlite3' @@ -44,17 +44,17 @@ module DuplicatedConfigure end after do - Lotus::Model.configuration.reset! + Hanami::Model.configuration.reset! Object.send(:remove_const, :Duplicated) Object.send(:remove_const, :DuplicatedConfigure) end # Bug - # See https://github.com/lotus/model/issues/154 + # See https://github.com/hanami/model/issues/154 it 'duplicates the configuration of the framework' do actual = Duplicated::Model.configuration - assert actual == Lotus::Model::Configuration.new + assert actual == Hanami::Model::Configuration.new end it 'duplicates a namespace for entity' do @@ -65,7 +65,7 @@ module DuplicatedConfigure assert defined?(Duplicated::Repository), 'Duplicated::Repository expected' end - if Lotus::Utils.jruby? + if Hanami::Utils.jruby? it 'optionally accepts a block to configure the duplicated module' do configuration = DuplicatedConfigure::Model.configuration @@ -84,23 +84,23 @@ module DuplicatedConfigure describe '.configure' do after do - Lotus::Model.unload! + Hanami::Model.unload! end it 'returns self' do - returning = Lotus::Model.configure { } - returning.must_equal(Lotus::Model) + returning = Hanami::Model.configure { } + returning.must_equal(Hanami::Model) end describe '.adapter' do before do - Lotus::Model.configure do + Hanami::Model.configure do adapter type: :sql, uri: 'postgres://localhost/database' end end it 'allows to register SQL adapter configuration' do - adapter_config = Lotus::Model.configuration.adapter_config + adapter_config = Hanami::Model.configuration.adapter_config adapter_config.type.must_equal :sql adapter_config.uri.must_equal 'postgres://localhost/database' end @@ -108,7 +108,7 @@ module DuplicatedConfigure describe '.mapping' do before do - Lotus::Model.configure do + Hanami::Model.configure do mapping do collection :users do entity User @@ -121,8 +121,8 @@ module DuplicatedConfigure end it 'configures the global persistence mapper' do - mapper_config = Lotus::Model.configuration.instance_variable_get(:@mapper_config) - mapper_config.must_be_instance_of Lotus::Model::Config::Mapper + mapper_config = Hanami::Model.configuration.instance_variable_get(:@mapper_config) + mapper_config.must_be_instance_of Hanami::Model::Config::Mapper end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 86d421ff..6484c2aa 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -18,11 +18,11 @@ require 'minitest/autorun' $:.unshift 'lib' -require 'lotus/utils' -require 'lotus-model' -require 'lotus/model/adapters/memory_adapter' -require 'lotus/model/adapters/file_system_adapter' -require 'lotus/model/adapters/sql_adapter' +require 'hanami/utils' +require 'hanami-model' +require 'hanami/model/adapters/memory_adapter' +require 'hanami/model/adapters/file_system_adapter' +require 'hanami/model/adapters/sql_adapter' db = Pathname.new(__dir__).join('../tmp/db') db.dirname.mkpath # create directory if not exist @@ -34,9 +34,9 @@ filesystem.rmtree if filesystem.exist? filesystem.dirname.mkpath # recreate directory -postgres_database = "lotus_model_test" +postgres_database = "hanami_model_test" -if Lotus::Utils.jruby? +if Hanami::Utils.jruby? require 'jdbc/sqlite3' require 'jdbc/postgres' Jdbc::SQLite3.load_driver @@ -57,7 +57,7 @@ MYSQL_USER = 'travis' else POSTGRES_USER = `whoami`.strip - MYSQL_USER = 'lotus' + MYSQL_USER = 'hanami' end system "dropdb #{ postgres_database }" rescue nil @@ -65,7 +65,7 @@ sleep 1 require 'fixtures' -Lotus::Model::Configuration.class_eval do +Hanami::Model::Configuration.class_eval do def ==(other) other.kind_of?(self.class) && other.adapter == adapter && diff --git a/test/version_test.rb b/test/version_test.rb index d7a93189..ea2abaa7 100644 --- a/test/version_test.rb +++ b/test/version_test.rb @@ -1,7 +1,7 @@ require 'test_helper' -describe Lotus::Model::VERSION do +describe Hanami::Model::VERSION do it 'returns current version' do - Lotus::Model::VERSION.must_equal '0.5.2' + Hanami::Model::VERSION.must_equal '0.6.0' end end