Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joker1007/abstriker
https://github.com/joker1007/abstriker
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/joker1007/abstriker
- Owner: joker1007
- License: mit
- Created: 2018-01-25T13:10:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-04T17:56:40.000Z (over 5 years ago)
- Last Synced: 2024-10-18T22:04:25.657Z (20 days ago)
- Language: Ruby
- Size: 22.5 KB
- Stars: 26
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Abstriker
[![Build Status](https://travis-ci.org/joker1007/abstriker.svg?branch=master)](https://travis-ci.org/joker1007/abstriker)
[![Gem Version](https://badge.fury.io/rb/abstriker.svg)](https://badge.fury.io/rb/abstriker)This gem adds `abstract` syntax. that is similar to Java's one.
`abstract` modified method requires subclass implementation.If subclass does not implement `abstract` method, raise `Abstriker::NotImplementedError`.
`Abstriker::NotImplementedError` is currently subclass of `::NotImplementedError`.This gem is pseudo static code analyzer by `TracePoint` and `Ripper`.
it detect abstract violation when class(module) is defined, not runtime.
### My similar gems
- [finalist](https://github.com/joker1007/finalist) (`final` implementation)
- [overrider](https://github.com/joker1007/overrider) (`override` implementation)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'abstriker'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install abstriker
## Usage
```ruby
class A1
extend Abstrikerabstract def foo
end
endclass A3 < A1
def foo
end
end # => OKclass A2 < A1
end # => raiseClass.new(A1) do
end # => raise
```### for Production
If you want to disable Abstriker, write `Abstriker.disable = true` at first line.
If Abstriker is disabled, TracePoint never runs, and so there is no overhead of VM instruction.### Examples
#### include module
```ruby
module B1
extend Abstrikerabstract def foo
end
endclass B2
include B1
end # => raiseModule.new do
include B1
end # => raise
```#### include module outer class definition
```ruby
module A1
extend Abstrikerabstract def foo
end
endclass A2;
endA2.include(A1) # => raise
```#### extend module
```ruby
module C1
extend Abstrikerabstract def foo
end
endclass C3
extend C1def self.foo
end
end # => OKclass C2
extend C1
end # raise
```#### singleton class
```ruby
class D1
extend Abstrikerclass << self
abstract def foo
end
end
endclass D3 < D1
def self.foo
end
end # => OKclass D2 < D1
end # => raiseClass.new(D1) do
end # => raise```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/abstriker.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).