usable 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -2
- data/Gemfile +5 -2
- data/README.md +11 -11
- data/Rakefile +5 -1
- data/lib/usable/version.rb +1 -1
- data/lib/usable.rb +6 -7
- data/usable.gemspec +3 -1
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e971571c1349c6977b3e0d8050536a2d1d75f76
|
4
|
+
data.tar.gz: cc1dcf9e4678b7ae565e3a4e8bcb111b5253b853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c23c4aefe50a4cec3a8ee7232ecaf7f84f5f1d71a5f1f33fe7212cb08581c4301ebd6143fa3ccaa839691c0f2ce171d88d39af9bb6f0ff035733c07d6d3bec
|
7
|
+
data.tar.gz: 5cce2ae60678d9ce8cd1ac1230d84c27d53ca77338cedc31cd5ab3fbb676d0bb840cf1ea8e7cff3edaa1b983172d319655292d7a76091cc3fda2661c9e6179b3
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Usable [![Gem Version](https://badge.fury.io/rb/usable.svg)](http://badge.fury.io/rb/usable)
|
1
|
+
# Usable [![Gem Version](https://badge.fury.io/rb/usable.svg)](http://badge.fury.io/rb/usable) [![Build Status](https://travis-ci.org/ridiculous/usable.svg)](https://travis-ci.org/ridiculous/usable) [![Code Climate](https://codeclimate.com/github/ridiculous/usable/badges/gpa.svg)](https://codeclimate.com/github/ridiculous/usable)
|
2
2
|
|
3
3
|
A simple way to mount and configure your modules. Usable gives you control over which methods are included, and a simple
|
4
4
|
interface to help you call dynamic methods with confidence.
|
@@ -31,13 +31,13 @@ model = Model.new
|
|
31
31
|
model.save_version # => "Saving up to 10 versions to custom_versions"
|
32
32
|
model.destroy_version # => NoMethodError: undefined method `destroy_version' for #<Model:...
|
33
33
|
```
|
34
|
-
|
34
|
+
`Model` now has a `#save_versions` method but no `#destroy_version` method.
|
35
35
|
|
36
36
|
## Confidently calling methods
|
37
37
|
|
38
|
-
We should all be writing [confident code](http://www.confidentruby.com/)
|
39
|
-
|
40
|
-
will
|
38
|
+
We should all be writing [confident code](http://www.confidentruby.com/), which is why you might want to call configurable
|
39
|
+
methods through the `usable_method` class level function. Methods passed in with the `:only` option
|
40
|
+
will _always_ return `nil` when called. Thus, the confidence.
|
41
41
|
|
42
42
|
Here's the same example as above, rewritten to call methods through the Usable interface:
|
43
43
|
|
@@ -46,11 +46,11 @@ Model.usable_method(model, :save_version).call # => "Saving up to 10 versions
|
|
46
46
|
Model.usable_method(model, :destroy_version).call # => nil
|
47
47
|
```
|
48
48
|
|
49
|
-
## Separate
|
49
|
+
## Separate the _included_ module from the _configurable_ methods
|
50
50
|
|
51
|
-
Sometimes you want to define methods on
|
52
|
-
|
53
|
-
conflicts will be resolved by giving precedence to the parent module.
|
51
|
+
Sometimes you want to define methods on a module and have them always be included. To do this, define a module named
|
52
|
+
`UsableSpec` in the scope of the module you are mounting. `Usable` will detect this and use he "spec" module to configure
|
53
|
+
the available methods. Any naming conflicts will be resolved by giving precedence to the parent module.
|
54
54
|
|
55
55
|
For example:
|
56
56
|
|
@@ -64,7 +64,7 @@ module Mixin
|
|
64
64
|
"always here"
|
65
65
|
end
|
66
66
|
|
67
|
-
# @description Usable will apply the :only to just the methods defined by this module
|
67
|
+
# @description Usable will apply the :only option to just the methods defined by this module
|
68
68
|
module UsableSpec
|
69
69
|
def from_spec
|
70
70
|
"can be excluded"
|
@@ -87,7 +87,7 @@ Example.new.name # => "defined by Mixin"
|
|
87
87
|
Example.ancestors # => [Example, Mixin, Example::MixinUsableSpecUsed, Object, Kernel, BasicObject] (ruby -v 2.3.0)
|
88
88
|
```
|
89
89
|
|
90
|
-
|
90
|
+
Notice that Usable assigns the modified module to a constant with the same name as the given module, but with "Used" appended.
|
91
91
|
The main module and the spec were both included, but `Mixin` was not modified, so it didn't need a new name.
|
92
92
|
|
93
93
|
## Installation
|
data/Rakefile
CHANGED
data/lib/usable/version.rb
CHANGED
data/lib/usable.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'ostruct'
|
2
|
+
require 'delegate'
|
3
|
+
require 'usable/version'
|
4
|
+
require 'usable/mod_extender'
|
5
|
+
require 'usable/config'
|
4
6
|
|
5
7
|
module Usable
|
6
8
|
|
7
|
-
autoload :ModExtender, 'usable/mod_extender'
|
8
|
-
autoload :Config, 'usable/config'
|
9
|
-
|
10
9
|
def usable_config
|
11
10
|
@usable_config ||= Config.new
|
12
11
|
end
|
@@ -42,7 +41,7 @@ module Usable
|
|
42
41
|
mod_name = mod.name ? mod.name.split('::').last : "UsableMod#{Time.now.strftime('%s')}"
|
43
42
|
const_name = "#{mod_name}Used"
|
44
43
|
mod = mod.call if mod.respond_to? :call
|
45
|
-
remove_const const_name if const_defined? const_name
|
44
|
+
remove_const const_name if const_defined? const_name, false
|
46
45
|
const_set const_name, mod
|
47
46
|
usable_config.modules << mod
|
48
47
|
send :include, mod
|
data/usable.gemspec
CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 2.0.0'
|
23
|
+
|
22
24
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
26
|
spec.add_development_dependency 'rspec', '>= 3.2', '< 4'
|
25
|
-
spec.add_development_dependency 'rspec-scaffold', '>= 1.0', '< 2'
|
27
|
+
# spec.add_development_dependency 'rspec-scaffold', '>= 1.0', '< 2'
|
26
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
@@ -58,26 +58,6 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '4'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rspec-scaffold
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '1.0'
|
68
|
-
- - "<"
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '2'
|
71
|
-
type: :development
|
72
|
-
prerelease: false
|
73
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '1.0'
|
78
|
-
- - "<"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '2'
|
81
61
|
description: A simple way to mount and configure your modules. Usable gives you control
|
82
62
|
over which methods are included.
|
83
63
|
email:
|
@@ -113,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
93
|
requirements:
|
114
94
|
- - ">="
|
115
95
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
96
|
+
version: 2.0.0
|
117
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
98
|
requirements:
|
119
99
|
- - ">="
|