Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dux/clean-annotations
Define annotatable attribute names, assign them to methods or classes, add callbacks to non-Rails classes. Void of dependencies.
https://github.com/dux/clean-annotations
Last synced: about 2 months ago
JSON representation
Define annotatable attribute names, assign them to methods or classes, add callbacks to non-Rails classes. Void of dependencies.
- Host: GitHub
- URL: https://github.com/dux/clean-annotations
- Owner: dux
- License: mit
- Created: 2019-12-09T14:00:07.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T07:40:04.000Z (over 3 years ago)
- Last Synced: 2024-04-26T20:20:33.841Z (8 months ago)
- Language: Ruby
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clean annotations - annotate ruby methods and classes
Define annotatable attribute names and assign them to methods or classes, add callbacks to non-Rails classes. Void of dependencies.
# INFO
Deprecated and split in 3 libs, please use
* https://github.com/dux/class-cattr - Class attributes
* https://github.com/dux/class-mattr - Class method attributes
* https://github.com/dux/class-callbacks - Class callbacks## Installation and usage
to install
`gem install clean-annotations`
or in Gemfile
`gem 'clean-annotations'`
and to use
`require 'clean-annotations'`
### Dependency
None
## Class attributes
```
class A
class_attribute :layout, 'default'
class_attribute(:time) { Time.now }
endclass B < A
layout 'main'
endclass C < B
time '11:55'
endfor func in [:layout, :time]
for klass in [A, B, C]
puts "> %s = %s" % ["#{klass}.#{func}".ljust(8), klass.send(func)]
end
end# A.layout = default
# B.layout = main
# C.layout = main
# A.time = 2019-10-28 18:07:33 +0100
# B.time = 2019-10-28 18:07:33 +0100
# C.time = 11:55
```## Class Callbacks
```
class Foo
define_callback :beforebefore do
endbefore :method_name
end# instance = new
# instance.run_callback :before
# instance.run_callback :before, @arg
```## Method attributes
```
class Foo
method_attr :name
method_attr :param do |field, type=String, opts={}|
opts[:name] = field
opts[:type] ||= String
opts
end
endclass Foo
name "Test method desc 1"
name "Test method desc 2"
param :email, :email
def test
# ...
end
end# Foo.method_attr
# {
# test: {
# name: [
# ["Test method desc 1"],
# ["Test method desc 2"]
# ],
# param: [
# {
# name: :email,
# type: String
# }
# ]
# }
# }
```## Rescue from
Standard Rails like `rescue_from`. You capture errors by executing in `resolve_rescue_from`
```ruby
class RescueParent
include RescueFromErrorrescue_from :all do
# ...
endrescue_from NoMethodError do
# ...
end
endclass RescueTest
def some_method
resolve_rescue_from do
triger_no_method_error
end
end
end
```## Development
After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/solnic/clean-annotations.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
[Contributor Covenant](http://contributor-covenant.org) code of conduct.## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).