fuck_off 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -33
- data/lib/fuck_off/version.rb +1 -1
- data/lib/fuck_off.rb +15 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a67207419febceae48c360ec1b4238cfd0dfebe73cdec3f900edd7bcd64dceb
|
4
|
+
data.tar.gz: 7f828dabfe4af21804686614ab5d6b40e16c5c78c8c69411479790dfb55d9ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf7026868c4f279df6d2503368de40888986607390c059054073aefdf8d032ce91e8f6105fbd61b93e4ea1a43bcbc016f91c8e422738adf1958204b2dfe898f4
|
7
|
+
data.tar.gz: b814c7b794811f180ed73229ded453b710b0363c979ab94c599b4eff87738a34f6bb1f70d4b70510e2c35d9c8beace275a3541898dd16c7a45350320b113154f
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
To prevent use of your private API, this gem allow you to mark methods as being `fucking_private` and/or `fucking_final`.
|
2
|
+
|
2
3
|
```ruby
|
3
4
|
class Example
|
4
5
|
include FuckOff
|
@@ -11,45 +12,22 @@ class Example
|
|
11
12
|
"Bar"
|
12
13
|
end
|
13
14
|
end
|
14
|
-
|
15
|
-
Example.new.send(:foo) # raises a FuckOff::NoMethodError
|
16
|
-
Example.define_method(:bar) { "New bar" } # raises a FuckOff::NameError
|
17
15
|
```
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
Add this line to your application's Gemfile:
|
17
|
+
If you try to call a `fucking_private` method anyway, it will raise a `NoMethodError`.
|
22
18
|
|
23
19
|
```ruby
|
24
|
-
|
20
|
+
Example.new.send(:foo) # raises a FuckOff::NoMethodError
|
25
21
|
```
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
$ bundle install
|
30
|
-
|
31
|
-
Or install it yourself as:
|
32
|
-
|
33
|
-
$ gem install fuck_off
|
34
|
-
|
35
|
-
## Usage
|
23
|
+
If you try to redefine a `fucking_final` method, it will raise a `NameError`.
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
-
|
43
|
-
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
-
|
45
|
-
## Contributing
|
46
|
-
|
47
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fuck_off. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/fuck_off/blob/master/CODE_OF_CONDUCT.md).
|
48
|
-
|
49
|
-
## License
|
25
|
+
```ruby
|
26
|
+
Example.define_method(:bar) { "New bar" } # raises a FuckOff::NameError
|
27
|
+
```
|
50
28
|
|
51
|
-
|
29
|
+
Yes, this is a joke. But it also kind of [works](https://github.com/joeldrapper/fuck_off/blob/main/test/fuck_off_test.rb).
|
52
30
|
|
53
|
-
##
|
31
|
+
## Prior art
|
54
32
|
|
55
|
-
|
33
|
+
[I told you it was private](https://github.com/fxn/i-told-you-it-was-private)
|
data/lib/fuck_off/version.rb
CHANGED
data/lib/fuck_off.rb
CHANGED
@@ -11,11 +11,23 @@ module FuckOff
|
|
11
11
|
def fucking_private_methods
|
12
12
|
if defined? @fucking_private_methods
|
13
13
|
@fucking_private_methods
|
14
|
+
elsif superclass.respond_to? :fucking_private_methods
|
15
|
+
@fucking_private_methods = superclass.fucking_private_methods
|
14
16
|
else
|
15
17
|
@fucking_private_methods = {}
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
def fucking_final_methods
|
22
|
+
if defined? @fucking_final_methods
|
23
|
+
@fucking_final_methods
|
24
|
+
elsif superclass.respond_to? :fucking_final_methods
|
25
|
+
@fucking_final_methods = superclass.fucking_final_methods
|
26
|
+
else
|
27
|
+
@fucking_final_methods = {}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
19
31
|
def fucking_private(method_name)
|
20
32
|
fucking_private_methods[method_name] = true
|
21
33
|
private method_name
|
@@ -23,13 +35,13 @@ module FuckOff
|
|
23
35
|
end
|
24
36
|
|
25
37
|
def fucking_final(method_name)
|
26
|
-
|
38
|
+
fucking_final_methods[method_name] = true
|
27
39
|
method_name
|
28
40
|
end
|
29
41
|
|
30
42
|
def method_added(method_name)
|
31
|
-
if
|
32
|
-
raise FuckOff::NameError, "Fuck you"
|
43
|
+
if fucking_final_methods[method_name]
|
44
|
+
raise FuckOff::NameError, "Fuck you!"
|
33
45
|
else
|
34
46
|
super
|
35
47
|
end
|