https://github.com/krisleech/inverse-attr
Macro to create inverted attributes
https://github.com/krisleech/inverse-attr
Last synced: 11 months ago
JSON representation
Macro to create inverted attributes
- Host: GitHub
- URL: https://github.com/krisleech/inverse-attr
- Owner: krisleech
- Created: 2013-04-15T15:10:32.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2015-02-04T09:40:23.000Z (over 11 years ago)
- Last Synced: 2025-03-17T04:44:46.128Z (about 1 year ago)
- Language: Ruby
- Size: 145 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# InverseAttr
[](http://badge.fury.io/rb/inverse-attr)
[](https://codeclimate.com/github/krisleech/inverse-attr)
[](https://travis-ci.org/krisleech/inverse-attr)
[](https://coveralls.io/r/krisleech/inverse-attr?branch=master)
Provides a macro which adds methods to return the inverse of another.
## Installation
```ruby
gem 'inverse_attr'
```
## Usage
```ruby
class Lesson
include InverseAttr
def published?
false
end
attr_inverse :published?
end
lesson = Lesson.new
lesson.not_published? # => true
```
You can specify the name of the inverted attribute by passing a second argument:
```ruby
attr_inverse :published?, :draft?
```
Don't want to put the include at the top of your classes?
```ruby
Object.class_eval { include InverseAttr }
```
or more selectively:
```ruby
ActiveRecord::Base.class_eval { include InverseAttr }
```
## License
Copyright (c) 2013 Kris Leech
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.