inverse_attr 0.0.2

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: ea65cec0119cc46f7ebf1dd08140c8fb48d7acf7
4
+ data.tar.gz: 25e5095c8fee47f09f7c0c77d43401a81c91b6ac
5
+ SHA512:
6
+ metadata.gz: 987526b4f1bf0b2e04759f7cdb8db6efe87e920395532bc5a0065d138a6656416b4384aee620cb9f8b1247af74047240caaf6efd19ad5192eae63457ee1188db
7
+ data.tar.gz: e2db8e6a2a1175af17effbec183a4f593c895d218b42ff091e9d735b86195656d41c642fb27cca744d6da94502b1a9a7b561049ba1762c55e276d8e855df7bea
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ bundler_args: --without=extras
3
+ script: rspec spec
4
+ rvm:
5
+ - '2.1.5'
6
+ - jruby
7
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake', '~> 10.3.0'
6
+ gem 'rspec', '~> 3.0.0'
7
+ gem 'coveralls', require: false
8
+
9
+ group :extras do
10
+ gem 'flay'
11
+ gem 'pry'
12
+ gem 'yard'
13
+ end
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # InverseAttr
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/inverse-attr.png)](http://badge.fury.io/rb/inverse-attr)
4
+ [![Code Climate](https://codeclimate.com/github/krisleech/inverse-attr.png)](https://codeclimate.com/github/krisleech/inverse-attr)
5
+ [![Build Status](https://travis-ci.org/krisleech/inverse-attr.png?branch=master)](https://travis-ci.org/krisleech/inverse-attr)
6
+ [![Coverage Status](https://coveralls.io/repos/krisleech/inverse-attr/badge.png?branch=master)](https://coveralls.io/r/krisleech/inverse-attr?branch=master)
7
+
8
+ Provides a macro which adds methods to return the inverse of another.
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ gem 'inverse_attr'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ class Lesson
20
+ include InverseAttr
21
+
22
+ def published?
23
+ false
24
+ end
25
+
26
+ attr_inverse :published?
27
+ end
28
+
29
+ lesson = Lesson.new
30
+
31
+ lesson.not_published? # => true
32
+ ```
33
+
34
+ You can specify the name of the inverted attribute by passing a second argument:
35
+
36
+ ```ruby
37
+ attr_inverse :published?, :draft?
38
+ ```
39
+
40
+ Don't want to put the include at the top of your classes?
41
+
42
+ ```ruby
43
+ Object.class_eval { include InverseAttr }
44
+ ```
45
+
46
+ or more selectively:
47
+
48
+ ```ruby
49
+ ActiveRecord::Base.class_eval { include InverseAttr }
50
+ ```
51
+
52
+ ## License
53
+
54
+ Copyright (c) 2013 Kris Leech
55
+
56
+ MIT License
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ "Software"), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
72
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
73
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
74
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
75
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/inverse_attr/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kris Leech"]
6
+ gem.email = ["kris.leech@gmail.com"]
7
+ gem.description = "Macro to add inverted attributes to Ruby objects"
8
+ gem.summary = "Macro to add inverted attributes to Ruby objects"
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "inverse_attr"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = InverseAttr::VERSION
17
+ end
@@ -0,0 +1,18 @@
1
+ require "inverse_attr/version"
2
+
3
+ module InverseAttr
4
+ def self.included(recipient)
5
+ recipient.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def inverted_attr(source_attr, target_attr = nil)
10
+ target_attr ||= "not_#{source_attr}"
11
+ define_method target_attr do
12
+ !send(source_attr)
13
+ end
14
+ end
15
+
16
+ private :inverted_attr
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module InverseAttr
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'inverse_attr'
2
+
3
+ describe InverseAttr do
4
+
5
+ let(:klass) do
6
+ Class.new do
7
+ include InverseAttr
8
+
9
+ def published?
10
+ true
11
+ end
12
+ end
13
+ end
14
+
15
+ subject { klass.new }
16
+
17
+ describe 'inverted_attr' do
18
+ it 'is not public' do
19
+ expect(klass).not_to respond_to(:inverted_attr)
20
+ end
21
+
22
+ context 'given :published?' do
23
+ before { klass.class_eval { inverted_attr :published? } }
24
+
25
+ it 'provides not_published?' do
26
+ expect(subject).to respond_to(:not_published?)
27
+ end
28
+
29
+ it 'not_published? returns inverse of published?' do
30
+ expect(subject.not_published?).to eq !subject.published?
31
+ end
32
+ end
33
+
34
+ context 'given :published? and :draft?' do
35
+ before { klass.class_eval { inverted_attr :published?, :draft? } }
36
+
37
+ it 'provides draft?' do
38
+ expect(subject).to respond_to(:draft?)
39
+ end
40
+
41
+ it 'draft? return inverse of published?' do
42
+ expect(subject.draft?).to eq !subject.published?
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+
13
+ config.filter_run :focus
14
+ config.run_all_when_everything_filtered = true
15
+
16
+ config.warnings = true
17
+
18
+ if config.files_to_run.one?
19
+ config.default_formatter = 'doc'
20
+ end
21
+
22
+ config.order = :random
23
+
24
+ Kernel.srand config.seed
25
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inverse_attr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Macro to add inverted attributes to Ruby objects
14
+ email:
15
+ - kris.leech@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".ruby-version"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - README.md
26
+ - Rakefile
27
+ - inverse_attr.gemspec
28
+ - lib/inverse_attr.rb
29
+ - lib/inverse_attr/version.rb
30
+ - spec/inverse_attr_spec.rb
31
+ - spec/spec_helper.rb
32
+ homepage: ''
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.2.2
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Macro to add inverted attributes to Ruby objects
55
+ test_files:
56
+ - spec/inverse_attr_spec.rb
57
+ - spec/spec_helper.rb
58
+ has_rdoc: