private_attrs 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0fb676e3a2421949cc5239dbfaa58ac40fb923d3
4
+ data.tar.gz: 1861e9c782a3ddf2b5305272909a97cec6466a64
5
+ SHA512:
6
+ metadata.gz: 1bbd4825cc9b1639bf6bc0a70c32e83214fa8bc91e9d575c60b4e4406ee5fb6ce7bc83f140859bd874776fa6c2d0e4f35c39f77919ae524369c7c74c46c7bd28
7
+ data.tar.gz: 0dc6a09deb3a24a3f54f0297180cc1a34017a112cbe17b48cb7fb98a0923948ac6013913d018c922f1c29a1f39f87191a245d19b2d69e5be1639908e8cd46e30
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in private_attrs.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ private_attrs (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.0)
12
+ pry (0.11.3)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+ rspec (3.7.0)
17
+ rspec-core (~> 3.7.0)
18
+ rspec-expectations (~> 3.7.0)
19
+ rspec-mocks (~> 3.7.0)
20
+ rspec-core (3.7.1)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-expectations (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-mocks (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-support (3.7.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ private_attrs!
36
+ pry
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Zach Colon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # PrivateAttrs
2
+
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/09bf301b78287db6e51b/maintainability)](https://codeclimate.com/github/wzcolon/private_attrs/maintainability)
4
+
5
+ Adds a few to Ruby's Clss object to allow for private attr
6
+ readers/writers/accessors.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'private_attrs'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install private_attrs
23
+
24
+ ## Usage
25
+
26
+ Inside any class object you can now define private attr methods.
27
+
28
+ ```
29
+ class Crocodile
30
+
31
+ private_attr_reader :temper
32
+
33
+ def intialize(temper)
34
+ @temper = temper
35
+ end
36
+ end
37
+
38
+ Crocodile.new('angry').temper # => NoMethodError "private method 'temper' called for ...
39
+ ```
40
+
41
+ ### Why
42
+
43
+ In short, because existing patterns to do this are ugly. This particular
44
+ pattern violates 'the scissor rule' of coding in that there is not a clear
45
+ separation between public and private methods.
46
+
47
+
48
+ ```
49
+ class Crocodile
50
+
51
+ private
52
+
53
+ attr_reader :temper
54
+
55
+ public
56
+
57
+ attr_reader :asleep
58
+
59
+ def initialize(temper)
60
+ @temper = temper
61
+ end
62
+
63
+ def bites?
64
+ if angry? && !asleep?
65
+ end
66
+
67
+ private
68
+
69
+ def angry?
70
+ temper == 'angry'
71
+ end
72
+
73
+ def asleep?
74
+ current_time = Time.now
75
+ (current_time.hour >= 17) and (current_time.hour <= 21)
76
+ end
77
+ end
78
+ ```
79
+
80
+ This use case is better but still not ideal as we want all of our attrs
81
+ methods definded at the top of any given class.
82
+
83
+ ```
84
+ class Truck
85
+
86
+ attr_reader :transmission_type
87
+ attr_reader :weight
88
+
89
+ def initialize(wheel_count:, transmission_type:, weight:)
90
+ @wheel_count = wheel_count
91
+ @transmission_type = transmission_type
92
+ @weight = weight
93
+ end
94
+
95
+ def oversized
96
+ wheel_count > 4
97
+ end
98
+
99
+ def driver_must_shift?
100
+ transmission_type == :manual
101
+ end
102
+
103
+ private
104
+
105
+ attr_reader :wheel_count
106
+ end
107
+ ```
108
+
109
+ Other patterns are even worse...
110
+ ```
111
+ class Pet
112
+
113
+ attr_accessor :species
114
+ private :species
115
+ private :species=
116
+
117
+ attr_reader :hairy
118
+ private :hairy
119
+
120
+ def initialize(species, hairy)
121
+ #...
122
+ end
123
+ end
124
+ ```
125
+
126
+ ## License
127
+
128
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "private_attrs"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ module AttrMethods
2
+ def self.included(base)
3
+ base.class_eval do
4
+ def self.private_attr_reader(*args)
5
+ args.each do |arg|
6
+ private
7
+ attr_reader arg.to_sym
8
+ public
9
+ end
10
+ end
11
+
12
+ def self.private_attr_writer(*args)
13
+ private
14
+ args.each do |arg|
15
+ attr_writer arg.to_sym
16
+ end
17
+ public
18
+ end
19
+
20
+ def self.private_attr_accessor(*args)
21
+ private
22
+ args.each do |arg|
23
+ attr_accessor arg.to_sym
24
+ end
25
+ public
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module PrivateAttrs
2
+ class Config
3
+ def self.add_private_attrs!
4
+ self.superclass.send(:include, AttrMethods)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module PrivateAttrs
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'private_attrs/version'
2
+ require 'private_attrs/config'
3
+ require 'private_attrs/attr_methods'
4
+
5
+ module PrivateAttrs
6
+ PrivateAttrs::Config.add_private_attrs!
7
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "private_attrs/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "private_attrs"
8
+ spec.version = PrivateAttrs::VERSION
9
+ spec.authors = ["Zach Colon"]
10
+ spec.email = ["zcolon80@gmail.com"]
11
+
12
+ spec.summary = %q{Adds private attr methods to Class object}
13
+ spec.description = %q{Adds private attr methods to Class object}
14
+ spec.homepage = "https://github.com/wzcolon/private_attrs"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "pry"
37
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: private_attrs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Zach Colon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-03 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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Adds private attr methods to Class object
70
+ email:
71
+ - zcolon80@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/private_attrs.rb
87
+ - lib/private_attrs/attr_methods.rb
88
+ - lib/private_attrs/config.rb
89
+ - lib/private_attrs/version.rb
90
+ - private_attrs.gemspec
91
+ homepage: https://github.com/wzcolon/private_attrs
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.11
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Adds private attr methods to Class object
116
+ test_files: []