nicefn 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a0ff36475e312f9c4f1350f373aa12776882903c5e5fe4dd24966a94f1fe4d11
4
+ data.tar.gz: 1772fbde10fa53f54e4cf9efcf2a9f90f66fa704abc8d43acac82c1cadde314a
5
+ SHA512:
6
+ metadata.gz: c53b68a7efb922503b48e43ded843a1994e4dc8fbc728d7c41ebefb195bdc0448f0c3c0217c80760f8312d7709827f4962134663ec393e4d0fce3ca661cf99b6
7
+ data.tar.gz: 59fffb76daf69a3ea5e981cbb45970c2e98361fa2222374c3759378b099942d5b2f253645449905cb360e68e6ae2cdd6cfed0e9064afe37fc4cb0f5b7a1951a0
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /spec/reports/
7
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.5.1
5
+
6
+ before_install: gem install bundler -v 1.16.5
7
+
8
+ script: make
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
data/Gemfile.lock ADDED
@@ -0,0 +1,11 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+
5
+ PLATFORMS
6
+ ruby
7
+
8
+ DEPENDENCIES
9
+
10
+ BUNDLED WITH
11
+ 1.16.5
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/Makefile ADDED
@@ -0,0 +1,35 @@
1
+ .PHONY: test
2
+
3
+ default: test_all
4
+
5
+ test_example_before_instance:
6
+ @./bin/test before inst
7
+
8
+ test_example_after_instance:
9
+ @./bin/test after inst
10
+
11
+ test_example_before_singleton:
12
+ @./bin/test before sing
13
+
14
+ test_example_after_singleton:
15
+ @./bin/test after sing
16
+
17
+ add_gem:
18
+ @cp pkg/Gemfile ./
19
+ @cp pkg/*.gemspec ./
20
+
21
+ rem_gem:
22
+ @rm Gemfile && rm nicefn.gemspec
23
+
24
+ test_example_project:
25
+ @make add_gem
26
+ @cd pkg/example_project && bundle install && bundle exec ruby test.rb
27
+ @rm pkg/example_project/Gemfile.lock
28
+ @make rem_gem
29
+
30
+ test_all:
31
+ @make test_example_before_instance
32
+ @make test_example_after_instance
33
+ @make test_example_before_singleton
34
+ @make test_example_after_singleton
35
+ @make test_example_project
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ ## Ruby Nicefn
2
+ Elixir and javascript have the capability of making good looking one liners, but
3
+ what about Ruby? We can definitely make an awful looking one by adding a ';'. If
4
+ you want to start defining some better looking one-liners then add the 'nicefn'
5
+ gem to your project. Since the implementation files are small and this project
6
+ has no required deps. You should also feel free to copy and paste the
7
+ implementation directly into your project in an effort to avoid extra gems.
8
+
9
+ ## Project Structure
10
+ Running `make` will default to running the tests inside `tst` folder against the
11
+ examples inside the `exa` folder.
12
+
13
+ ## How To Use
14
+ Add 'extend NiceFn::Inst' to the top of classes. You can also use 'include
15
+ NiceFn::Sing' in a `module` to make it a singleton class with `nicefn` methods.
16
+
17
+ ### Example (Regular Classes)
18
+ Provided below is an example class with `public`, `private`, and `protected` methods:
19
+ ```rb
20
+ class Inst
21
+ attr_writer :person
22
+
23
+ def test_priv(greet)
24
+ priv "#{greet}"
25
+ end
26
+
27
+ def test_share(greet, inst)
28
+ inst.share greet
29
+ end
30
+
31
+ private
32
+ def priv(greet)
33
+ puts "#{greet} #{@person}"
34
+ end
35
+
36
+ protected
37
+ def share(greet)
38
+ puts "#{greet} #{@person}"
39
+ end
40
+ end
41
+ ```
42
+ If we use `nicefn` on this class we can eliminate 10 lines of code inside of the
43
+ class definition. This is because `private` and `protected` are handled by
44
+ different functions (like `defp` in `elixir`).
45
+
46
+ ### After Adding InstFn
47
+ ```rb
48
+ require 'nicefn'
49
+
50
+ class Inst
51
+ extend NiceFn::Inst
52
+ attr_writer :person
53
+
54
+ fn(:test_priv) {|greet| priv "#{greet}"}
55
+ fn(:test_share) {|greet, inst| inst.share greet}
56
+
57
+ fp(:priv) {|greet| puts "#{greet} #{@person}"}
58
+
59
+ fs(:share) {|greet| puts "#{greet} #{@person}"}
60
+ end
61
+ ```
62
+ Calling `fn` with a function `name` and a block will give you a public method.
63
+ If you call 'fp' you will get a private method, and 'fs' will set a protected
64
+ (shared) method.
65
+
66
+ ### Example (Singleton Classes)
67
+ Provided below is an example of a singleton class that is made a singleton class
68
+ by using extend self.
69
+ ```rb
70
+ module Sing
71
+ extend self
72
+ attr_writer :person
73
+
74
+ def test_priv(greet)
75
+ priv "#{greet}"
76
+ end
77
+
78
+ private
79
+ def priv(greet)
80
+ puts "#{greet} #{@person}"
81
+ end
82
+ end
83
+ ```
84
+ After we add 'include NiceFn::Sing' to the module we can eliminate the need to
85
+ extend self as 'Sing' will do it for us.
86
+
87
+ ### After Adding SingFn
88
+ ```rb
89
+ require 'nicefn'
90
+
91
+ module Sing
92
+ include NiceFn::Sing
93
+ attr_writer :person
94
+
95
+ fn(:test_priv) {|greet| priv greet}
96
+ fp(:priv) {|greet| puts "#{greet} #{@person}"}
97
+ end
98
+ ```
99
+ Calling `fn` with a function `name` and a block will give you a public method.
100
+ If you call 'fp' you will get a private method. Since singletons classes can
101
+ only act as one instance 'fs' is not a provided option.
data/bin/test ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Capture stdout
4
+ $stdout = StringIO.new
5
+
6
+ # Enable test running
7
+ require 'test/unit'
8
+
9
+ # Set the name of the object type under test
10
+ object_type_under_test = ARGV[1] == "inst" ? "Instance" : "Singleton"
11
+
12
+ # Set the name of the example under test
13
+ example_under_test = ARGV[0] == "before" ? "Before" : "After"
14
+
15
+ # Define blue color code
16
+ blue_start, blue_end = "\e[36m", "\e[0m"
17
+
18
+ # Test running message
19
+ test_message = "Testing #{object_type_under_test}, #{example_under_test} Example"
20
+
21
+ # Display what test(s) we are currently running
22
+ STDOUT.puts "------------------------------------------------------------\n"
23
+ STDOUT.puts "#{blue_start} #{test_message} #{blue_end}"
24
+ STDOUT.puts "------------------------------------------------------------\n"
25
+
26
+ # Require file under test from argument
27
+ require_relative "../exa/#{ARGV[0]}/#{ARGV[1]}.rb"
28
+
29
+ # Require tests for the example under test
30
+ require_relative "../tst/#{ARGV[1]}.rb"
data/exa/after/inst.rb ADDED
@@ -0,0 +1,13 @@
1
+ require_relative '../../lib/nicefn.rb'
2
+
3
+ class Inst
4
+ extend Nicefn::Inst
5
+ attr_writer :person
6
+
7
+ fn(:test_priv) {|greet| priv "#{greet}"}
8
+ fn(:test_share) {|greet, inst| inst.share greet}
9
+
10
+ fp(:priv) {|greet| puts "#{greet} #{@person}"}
11
+
12
+ fs(:share) {|greet| puts "#{greet} #{@person}"}
13
+ end
data/exa/after/sing.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative '../../lib/nicefn.rb'
2
+
3
+ module Sing
4
+ include Nicefn::Sing
5
+ attr_writer :person
6
+
7
+ fn(:test_priv) {|greet| priv greet}
8
+ fp(:priv) {|greet| puts "#{greet} #{@person}"}
9
+ end
@@ -0,0 +1,21 @@
1
+ class Inst
2
+ attr_writer :person
3
+
4
+ def test_priv(greet)
5
+ priv "#{greet}"
6
+ end
7
+
8
+ def test_share(greet, inst)
9
+ inst.share greet
10
+ end
11
+
12
+ private
13
+ def priv(greet)
14
+ puts "#{greet} #{@person}"
15
+ end
16
+
17
+ protected
18
+ def share(greet)
19
+ puts "#{greet} #{@person}"
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Sing
2
+ extend self
3
+ attr_writer :person
4
+
5
+ def test_priv(greet)
6
+ priv "#{greet}"
7
+ end
8
+
9
+ private
10
+ def priv(greet)
11
+ puts "#{greet} #{@person}"
12
+ end
13
+ end
data/lib/inst.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Nicefn::Inst
2
+ define_method(:fn) {|func, &blk| define_method(func, &blk) }
3
+ define_method(:fp) {|func, &blk| define_method(func, &blk); private func }
4
+ define_method(:fs) {|func, &blk| define_method(func, &blk); protected func }
5
+ end
data/lib/nicefn.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Nicefn
2
+ end
3
+
4
+ require_relative './inst.rb'
5
+ require_relative './sing.rb'
data/lib/sing.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Nicefn::Sing
2
+ extend self
3
+ define_method(:included) {|klass|
4
+ klass.extend klass
5
+ define_method(:fn) {|func, &blk| define_method(func, &blk) }
6
+ define_method(:fp) {|func, &blk| define_method(func, &blk); private func }
7
+ }
8
+ end
data/nicefn.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ dir = File.dirname(File.realpath(__FILE__))
2
+ lib = File.join(dir, 'lib')
3
+
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'nicefn'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'nicefn'
10
+ spec.version = "0.1.0"
11
+ spec.authors = ['afaur']
12
+ spec.email = ['zazu-app@googlegroups.com']
13
+
14
+ spec.summary = %q{This gem adds an alternative way of specifying one-liners in your project.}
15
+ spec.description = %q{Elixir and javascript have the capability of making
16
+ good looking one liners, but what about Ruby? We can definitely make an awful
17
+ looking one by adding a ';'. If you want to start defining some better looking
18
+ one-liners then add the 'nicefn' gem to your project. Since the implementation
19
+ files are small and this project has no required deps. You should also feel free
20
+ to copy and paste the implementation directly into your project in an effort to
21
+ avoid extra gems.}
22
+
23
+ spec.homepage = 'https://github.com/afaur/ruby-nicefn.git'
24
+ spec.license = 'Unlicense'
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(dir) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(tst)/}) }
30
+ end
31
+
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.16'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "nicefn", :path => "../../.."
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: ../../..
3
+ specs:
4
+ nicefn (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ nicefn!
15
+
16
+ BUNDLED WITH
17
+ 1.16.5
@@ -0,0 +1,16 @@
1
+ require 'nicefn'
2
+
3
+ class Inst
4
+ extend Nicefn::Inst
5
+ fn(:test) {puts "hello from class instance"}
6
+ end
7
+
8
+ i = Inst.new
9
+ i.test
10
+
11
+ module Sing
12
+ include Nicefn::Sing
13
+ fn(:test) {puts "hello from singleton class"}
14
+ end
15
+
16
+ Sing.test
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nicefn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - afaur
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-11 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ description: |-
42
+ Elixir and javascript have the capability of making
43
+ good looking one liners, but what about Ruby? We can definitely make an awful
44
+ looking one by adding a ';'. If you want to start defining some better looking
45
+ one-liners then add the 'nicefn' gem to your project. Since the implementation
46
+ files are small and this project has no required deps. You should also feel free
47
+ to copy and paste the implementation directly into your project in an effort to
48
+ avoid extra gems.
49
+ email:
50
+ - zazu-app@googlegroups.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".gitignore"
56
+ - ".travis.yml"
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - LICENSE
60
+ - Makefile
61
+ - README.md
62
+ - bin/test
63
+ - exa/after/inst.rb
64
+ - exa/after/sing.rb
65
+ - exa/before/inst.rb
66
+ - exa/before/sing.rb
67
+ - lib/inst.rb
68
+ - lib/nicefn.rb
69
+ - lib/sing.rb
70
+ - nicefn.gemspec
71
+ - pkg/example_project/Gemfile
72
+ - pkg/example_project/Gemfile.lock
73
+ - pkg/example_project/test.rb
74
+ homepage: https://github.com/afaur/ruby-nicefn.git
75
+ licenses:
76
+ - Unlicense
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.7
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This gem adds an alternative way of specifying one-liners in your project.
98
+ test_files: []