nicefn 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0ff36475e312f9c4f1350f373aa12776882903c5e5fe4dd24966a94f1fe4d11
4
- data.tar.gz: 1772fbde10fa53f54e4cf9efcf2a9f90f66fa704abc8d43acac82c1cadde314a
3
+ metadata.gz: e03ec93935d8b40ddc5ceffef20c30b035be2bd2572f2b87ec737cac6a24aadf
4
+ data.tar.gz: 515e7361e679913a80207e6fc525259f2c1a02fb63aa9f9372b313402944f54e
5
5
  SHA512:
6
- metadata.gz: c53b68a7efb922503b48e43ded843a1994e4dc8fbc728d7c41ebefb195bdc0448f0c3c0217c80760f8312d7709827f4962134663ec393e4d0fce3ca661cf99b6
7
- data.tar.gz: 59fffb76daf69a3ea5e981cbb45970c2e98361fa2222374c3759378b099942d5b2f253645449905cb360e68e6ae2cdd6cfed0e9064afe37fc4cb0f5b7a1951a0
6
+ metadata.gz: 0e409ae0b12141cf1cdf8fd08bbde73b193630ba468cffe4431feb7d7c651c04f2f68a10d60d6c3992f79391c6721d8cf05898b3dbc0f24d095123cbf523d79c
7
+ data.tar.gz: 92f7c01db2a87d5de7008cca4dfcdd8b7c182e9ccdf33e0c947e8eedd5f7cd9364c5a049ebe36b878bf3acd1255883baa14be1033dd144bae6cee20a3e3efe9e
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/README.md CHANGED
@@ -1,18 +1,38 @@
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.
1
+ [![Gem Version](https://badge.fury.io/rb/nicefn.svg)](https://rubygems.org/gems/nicefn)
2
+ [![Gem Downloads](https://ruby-gem-downloads-badge.herokuapp.com/nicefn?color=brightgreen&type=total)](https://rubygems.org/gems/nicefn)
3
+ [![Build Status](https://travis-ci.org/afaur/ruby-nicefn.svg?branch=master)](https://travis-ci.org/afaur/ruby-nicefn)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/6e10f0a9ac5b168e8821/maintainability)](https://codeclimate.com/github/afaur/ruby-nicefn/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/6e10f0a9ac5b168e8821/test_coverage)](https://codeclimate.com/github/afaur/ruby-nicefn/test_coverage)
6
+
7
+ ### Overview
8
+ Here's a way to write functions (with visibility modification) in a single line of ruby.
9
+ ```rb
10
+ ...
11
+ fp(:priv) { |greet| puts greet }
12
+ ...
13
+ ```
14
+ This will automatically declare a function with private visibility. Which will
15
+ make it like you had actually wrote:
16
+ ```rb
17
+ ...
18
+ private
8
19
 
9
- ## Project Structure
10
- Running `make` will default to running the tests inside `tst` folder against the
11
- examples inside the `exa` folder.
20
+ def priv(greet)
21
+ puts greet
22
+ end
23
+ ...
24
+ ```
12
25
 
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.
26
+ ### Example (Main Scope)
27
+ If you want to write short one-liners in the main scope you need not add this gem
28
+ to your project. It is much quicker and simpler to do:
29
+ ```rb
30
+ alias fn define_singleton_method
31
+
32
+ fn(:test) { puts “hello” }
33
+
34
+ test # <= prints "hello" to stdout
35
+ ```
16
36
 
17
37
  ### Example (Regular Classes)
18
38
  Provided below is an example class with `public`, `private`, and `protected` methods:
@@ -20,59 +40,74 @@ Provided below is an example class with `public`, `private`, and `protected` met
20
40
  class Inst
21
41
  attr_writer :person
22
42
 
43
+ def self.set_klass_property(value)
44
+ @@klass_property = value
45
+ end
46
+
47
+ def self.print_klass_property()
48
+ puts @@klass_property
49
+ end
50
+
23
51
  def test_priv(greet)
24
- priv "#{greet}"
52
+ priv greet
25
53
  end
26
54
 
27
55
  def test_share(greet, inst)
28
56
  inst.share greet
29
57
  end
30
58
 
31
- private
59
+ private
60
+
32
61
  def priv(greet)
33
62
  puts "#{greet} #{@person}"
34
63
  end
35
64
 
36
- protected
65
+ protected
66
+
37
67
  def share(greet)
38
68
  puts "#{greet} #{@person}"
39
69
  end
40
70
  end
41
71
  ```
42
- If we use `nicefn` on this class we can eliminate 10 lines of code inside of the
72
+ If we use `nicefn` on this class we can eliminate more than 12 lines of code (if
73
+ we add spaces around private and protected like rubocop suggests) inside of the
43
74
  class definition. This is because `private` and `protected` are handled by
44
75
  different functions (like `defp` in `elixir`).
45
76
 
46
- ### After Adding InstFn
77
+ ### After Adding Nicefn::Inst
47
78
  ```rb
48
79
  require 'nicefn'
49
80
 
50
81
  class Inst
51
- extend NiceFn::Inst
82
+ extend Nicefn::Inst
52
83
  attr_writer :person
53
84
 
54
- fn(:test_priv) {|greet| priv "#{greet}"}
55
- fn(:test_share) {|greet, inst| inst.share greet}
85
+ cm(:set_klass_property) { |value| @@klass_property = value }
86
+ cm(:print_klass_property) { puts @@klass_property }
56
87
 
57
- fp(:priv) {|greet| puts "#{greet} #{@person}"}
88
+ fn(:test_priv) { |greet| priv greet }
89
+ fn(:test_share) { |greet, inst| inst.share greet }
58
90
 
59
- fs(:share) {|greet| puts "#{greet} #{@person}"}
91
+ fp(:priv) { |greet| puts "#{greet} #{@person}" }
92
+
93
+ fs(:share) { |greet| puts "#{greet} #{@person}" }
60
94
  end
61
95
  ```
62
96
  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.
97
+ (**Since version 0.1.1**) Class methods are created using the `cm` function.
98
+ If you call `fp` you will get a `private` method, and `fs` will set a
99
+ `protected` (shared) method.
65
100
 
66
101
  ### Example (Singleton Classes)
67
- Provided below is an example of a singleton class that is made a singleton class
68
- by using extend self.
102
+ Provided below is an example of a `module` that is made a `singleton class` by using
103
+ `extend self`.
69
104
  ```rb
70
105
  module Sing
71
106
  extend self
72
107
  attr_writer :person
73
108
 
74
109
  def test_priv(greet)
75
- priv "#{greet}"
110
+ priv greet
76
111
  end
77
112
 
78
113
  private
@@ -81,21 +116,45 @@ private
81
116
  end
82
117
  end
83
118
  ```
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.
119
+ After we add `include Nicefn::Sing` to the module we can eliminate the need to
120
+ extend self as `Nicefn::Sing` will do it for us.
86
121
 
87
- ### After Adding SingFn
122
+ ### After Adding Nicefn::Sing
88
123
  ```rb
89
124
  require 'nicefn'
90
125
 
91
126
  module Sing
92
- include NiceFn::Sing
127
+ include Nicefn::Sing
93
128
  attr_writer :person
94
129
 
95
- fn(:test_priv) {|greet| priv greet}
96
- fp(:priv) {|greet| puts "#{greet} #{@person}"}
130
+ fn(:test_priv) { |greet| priv greet }
131
+ fp(:priv) { |greet| puts "#{greet} #{@person}" }
97
132
  end
98
133
  ```
99
134
  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
135
+ If you call `fp` you will get a `private` method. Since singletons classes can
101
136
  only act as one instance 'fs' is not a provided option.
137
+
138
+ ## Install Gem
139
+ You can run `bundle add nicefn --version '~> 0.1.0'`, or manually add a line
140
+ indicating how you would like to fetch the `gem` to your `Gemfile`:
141
+ ```rb
142
+ ...
143
+ # Download latest nicefn from default source
144
+ gem 'nicefn'
145
+
146
+ # Download nicefn from default source with version constraints
147
+ gem 'nicefn', '~> 0.1.0'
148
+
149
+ # Download nicefn from git with a specific version
150
+ gem 'nicefn', git: 'https://github.com/afaur/ruby-nicefn', tag: 'v0.1.0'
151
+ ...
152
+ ```
153
+
154
+ ## Project Structure
155
+ Running `make` will default to running the tests inside `tst` folder against the
156
+ examples inside the `exa` folder.
157
+
158
+ ## How To Use
159
+ Add `extend Nicefn::Inst` to the top of classes. You can also use `include
160
+ Nicefn::Sing` in a `module` to make it a singleton class with `nicefn` methods.
@@ -1,5 +1,19 @@
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 }
1
+ # Place the Inst module inside of a namespace
2
+ module Nicefn
3
+ # Adds one-liner instance method/fn declaration capabilities for classes
4
+ module Inst
5
+ define_method(:cm) { |func, &blk| define_singleton_method(func, &blk) }
6
+
7
+ define_method(:fn) { |func, &blk| define_method(func, &blk) }
8
+
9
+ define_method(:fp) do |func, &blk|
10
+ define_method(func, &blk)
11
+ private func
12
+ end
13
+
14
+ define_method(:fs) do |func, &blk|
15
+ define_method(func, &blk)
16
+ protected func
17
+ end
18
+ end
5
19
  end
@@ -1,3 +1,4 @@
1
+ # Namespace that ::Inst and ::Sing are added to
1
2
  module Nicefn
2
3
  end
3
4
 
@@ -1,8 +1,17 @@
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
- }
1
+ # Place the Sing module inside of a namespace
2
+ module Nicefn
3
+ # Add one-liner singleton method/fn declaration capabilities for a module
4
+ module Sing
5
+ extend self
6
+ define_method(:included) do |klass|
7
+ klass.extend klass
8
+
9
+ define_method(:fn) { |func, &blk| define_method(func, &blk) }
10
+
11
+ define_method(:fp) do |func, &blk|
12
+ define_method(func, &blk)
13
+ private func
14
+ end
15
+ end
16
+ end
8
17
  end
@@ -1,5 +1,5 @@
1
- dir = File.dirname(File.realpath(__FILE__))
2
- lib = File.join(dir, 'lib')
1
+ ver = '0.1.1'
2
+ lib = File.join(__dir__, 'lib')
3
3
 
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
@@ -7,26 +7,34 @@ require 'nicefn'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
9
  spec.name = 'nicefn'
10
- spec.version = "0.1.0"
10
+ spec.version = ver
11
11
  spec.authors = ['afaur']
12
12
  spec.email = ['zazu-app@googlegroups.com']
13
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
14
+ spec.summary = %(This gem adds an alternative way of specifying
15
+ one-liners in your project.)
16
+
17
+ spec.description = %(Elixir and javascript have the capability of making
16
18
  good looking one liners, but what about Ruby? We can definitely make an awful
17
19
  looking one by adding a ';'. If you want to start defining some better looking
18
20
  one-liners then add the 'nicefn' gem to your project. Since the implementation
19
21
  files are small and this project has no required deps. You should also feel free
20
22
  to copy and paste the implementation directly into your project in an effort to
21
- avoid extra gems.}
23
+ avoid extra gems.)
22
24
 
23
25
  spec.homepage = 'https://github.com/afaur/ruby-nicefn.git'
24
26
  spec.license = 'Unlicense'
25
27
 
26
28
  # 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)/}) }
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been
30
+ # added into git
31
+ spec.files = Dir.chdir(__dir__) do
32
+ # Get all tracked files from git as an array
33
+ git_files = `git ls-files -z`.split("\x0")
34
+ # Remove directories & files that the gem does not use
35
+ git_files
36
+ .reject { |f| f.match(%r{^(tst|exa|bin|pkg)/}) }
37
+ .reject { |f| ['Makefile', '.gitignore', '.travis.yml'].include? f }
30
38
  end
31
39
 
32
40
  spec.bindir = 'exe'
@@ -35,4 +43,6 @@ avoid extra gems.}
35
43
 
36
44
  spec.add_development_dependency 'bundler', '~> 1.16'
37
45
  spec.add_development_dependency 'rake', '~> 10.0'
46
+ spec.add_development_dependency 'simplecov', '~> 0.16', '>= 0.16.1'
47
+ spec.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.8'
38
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nicefn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - afaur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-11 00:00:00.000000000 Z
11
+ date: 2018-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,46 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.16'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.16.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.16'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.16.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: test-unit
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.2'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 3.2.8
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '3.2'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.2.8
41
81
  description: |-
42
82
  Elixir and javascript have the capability of making
43
83
  good looking one liners, but what about Ruby? We can definitely make an awful
@@ -52,25 +92,13 @@ executables: []
52
92
  extensions: []
53
93
  extra_rdoc_files: []
54
94
  files:
55
- - ".gitignore"
56
- - ".travis.yml"
57
95
  - Gemfile
58
- - Gemfile.lock
59
96
  - LICENSE
60
- - Makefile
61
97
  - 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
98
  - lib/inst.rb
68
99
  - lib/nicefn.rb
69
100
  - lib/sing.rb
70
101
  - nicefn.gemspec
71
- - pkg/example_project/Gemfile
72
- - pkg/example_project/Gemfile.lock
73
- - pkg/example_project/test.rb
74
102
  homepage: https://github.com/afaur/ruby-nicefn.git
75
103
  licenses:
76
104
  - Unlicense
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /spec/reports/
7
- /tmp/
@@ -1,8 +0,0 @@
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
@@ -1,11 +0,0 @@
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/Makefile DELETED
@@ -1,35 +0,0 @@
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/bin/test DELETED
@@ -1,30 +0,0 @@
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"
@@ -1,13 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem "nicefn", :path => "../../.."
@@ -1,17 +0,0 @@
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
@@ -1,16 +0,0 @@
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