lexically 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/README.md +59 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lexically.gemspec +28 -0
- data/lib/lexically/version.rb +3 -0
- data/lib/lexically.rb +52 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2d4aac4d5ffb689a1df08eb2ec6c6dc9bce2dcad59ef7b33d0645369fcece99c
|
4
|
+
data.tar.gz: 61b0769a5b0cfcb36a6eed2c18b2cb4af057731a763a2cf67efa15941d90b7e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9cfa79bf3018987d99662361d03bb61e4487b659525469a83f5d7060b6b02d256b8cdb5d56e6f295c644c510a3c418740bb17916dde8777985f873290f1f9da7
|
7
|
+
data.tar.gz: 113cd7bd53fbd620d798a304b7458865c7143cfecb023f7cf0c67cd1a16c17fd014f29edb25476422bf26e48c959867763d6fff745b50f35b81d19cdc4b3fbe4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lexically (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.13.0)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.17)
|
17
|
+
lexically!
|
18
|
+
minitest (~> 5.0)
|
19
|
+
rake (~> 10.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.17.2
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Lexically
|
2
|
+
|
3
|
+
Using the refinements mechanism, This gem allows you to mark methods with the visibility like `private`, but it's more like Java's or PHP's `private`. i.e. `lexically` defined class cannot be called from derived class.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'lexically'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install lexically
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Include the `Lexically` module into your class, and define methods under lexically block with `using`.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class C
|
27
|
+
include Lexically
|
28
|
+
|
29
|
+
using lexically {
|
30
|
+
def lexical_method
|
31
|
+
:foo
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
def public_api
|
36
|
+
lexical_method
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class D < C
|
41
|
+
def derived
|
42
|
+
lexical_method
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
C.new.public_api #=> :foo
|
47
|
+
C.new.lexical_method #=> raises NameError
|
48
|
+
D.new.lexical_method #=> raises NameError because the D is derived class
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
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.
|
54
|
+
|
55
|
+
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).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nonowarn/lexically.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lexically"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lexically.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "lexically/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lexically"
|
8
|
+
spec.version = Lexically::VERSION
|
9
|
+
spec.authors = ["nonowarn"]
|
10
|
+
spec.email = ["nonowarn@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides "lexically" visibility to classes or modules}
|
13
|
+
spec.description = %q{Using refinements mechanisms, this module provides defning methods cannot be called from outside of the classes or modules}
|
14
|
+
spec.homepage = "http://nonowarn.jp"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
end
|
data/lib/lexically.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "lexically/version"
|
2
|
+
|
3
|
+
# Provides `lexically` method by including this module. Methods
|
4
|
+
# defined inside of `lexically`-block have similar visibility to
|
5
|
+
# private method, But it's not called fron derived classes
|
6
|
+
#
|
7
|
+
# @example Basic usage
|
8
|
+
# class C
|
9
|
+
# include Lexically
|
10
|
+
# using lexically {
|
11
|
+
# def lexical_method
|
12
|
+
# :foo
|
13
|
+
# end
|
14
|
+
# }
|
15
|
+
# def public_api
|
16
|
+
# lexical_method
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# class D < C
|
21
|
+
# def derived
|
22
|
+
# lexical_method
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# C.new.public_api #=> :foo
|
27
|
+
# C.new.lexical_method #=> raises NameError
|
28
|
+
# D.new.lexical_method #=> raises NameError because the D is derived class
|
29
|
+
module Lexically
|
30
|
+
|
31
|
+
def self.included(base)
|
32
|
+
base.extend(ClassMethods)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
module ClassMethods
|
37
|
+
|
38
|
+
# Returns a refinement refines the class itself.
|
39
|
+
#
|
40
|
+
# The refinement creates its scope cannot be visible from the
|
41
|
+
# outside of the class.
|
42
|
+
#
|
43
|
+
# @return [Module]
|
44
|
+
def lexically(&block)
|
45
|
+
klass = self
|
46
|
+
Module.new {
|
47
|
+
refine klass, &block
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lexically
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nonowarn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Using refinements mechanisms, this module provides defning methods cannot
|
56
|
+
be called from outside of the classes or modules
|
57
|
+
email:
|
58
|
+
- nonowarn@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lexically.gemspec
|
71
|
+
- lib/lexically.rb
|
72
|
+
- lib/lexically/version.rb
|
73
|
+
homepage: http://nonowarn.jp
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Provides "lexically" visibility to classes or modules
|
95
|
+
test_files: []
|