attr_defaultable 0.0.1 → 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 +4 -4
- data/README.md +30 -3
- data/Rakefile +16 -0
- data/lib/attr_defaultable/version.rb +1 -1
- data/lib/extend_attr_defaultable.rb +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff37f551cddbe51c450c7d5097a2c243d10e01de
|
4
|
+
data.tar.gz: cfba85ed78f6acbda0c144883b8f698bbf129d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be4f222217699198cef48a510c2630f0042392e3f31d3277a27b1ef2e0d8ec8c6c5dad41872b10d245c9f2f405be3e7f8cf8b8900343a0980203778cd29a6e50
|
7
|
+
data.tar.gz: 8ebff3673df74a1e633eacc8db5b9ea03985fa29dfb30a1f815542f7df762ac7918079d8b2e97ac2e427b5765505a20d4a98ff73da1624db21692a6e008e6ecc
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AttrDefaultable
|
2
2
|
|
3
|
-
|
3
|
+
Easily add attributes with default values to your classes.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -8,6 +8,10 @@ Add this line to your application's Gemfile:
|
|
8
8
|
|
9
9
|
gem 'attr_defaultable'
|
10
10
|
|
11
|
+
To optionally slip attr_defaultable into Module so it is available without extending:
|
12
|
+
|
13
|
+
gem 'attr_defaultable', require: 'extend_attr_defaultable'
|
14
|
+
|
11
15
|
And then execute:
|
12
16
|
|
13
17
|
$ bundle
|
@@ -18,11 +22,34 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
```ruby
|
26
|
+
class Example
|
27
|
+
extend AttrDefaultable
|
28
|
+
attr_defaultable :foo, -> { 'bar' }
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
This will create a getter/setter pair for your variable `foo`. If the setter is not used before the getter
|
33
|
+
the proc given will be called and it's result used to set the value of `foo`.
|
34
|
+
|
35
|
+
Very useful for creating dependency definitions with protected default values that are evaluated just in time.
|
36
|
+
|
37
|
+
## Alternate Usage
|
38
|
+
|
39
|
+
By using the alternate gem declaration in your Gemfile or manually
|
40
|
+
requiring `extend_attr_defaultable` early in your application, you can avoid the explicit `extend`
|
41
|
+
in your class.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class Example
|
45
|
+
attr_defaultable :foo, -> { 'bar' }
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
22
49
|
|
23
50
|
## Contributing
|
24
51
|
|
25
|
-
1. Fork it ( http://github.com
|
52
|
+
1. Fork it ( http://github.com/Originate/attr_defaultable/fork )
|
26
53
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
54
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
55
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -4,3 +4,19 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task :default => :spec
|
7
|
+
|
8
|
+
task :extended_console do
|
9
|
+
require 'irb'
|
10
|
+
require 'irb/completion'
|
11
|
+
require 'extend_attr_defaultable'
|
12
|
+
ARGV.clear
|
13
|
+
IRB.start
|
14
|
+
end
|
15
|
+
|
16
|
+
task :console do
|
17
|
+
require 'irb'
|
18
|
+
require 'irb/completion'
|
19
|
+
require 'attr_defaultable'
|
20
|
+
ARGV.clear
|
21
|
+
IRB.start
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_defaultable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexpeachey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- attr_defaultable.gemspec
|
70
70
|
- lib/attr_defaultable.rb
|
71
71
|
- lib/attr_defaultable/version.rb
|
72
|
+
- lib/extend_attr_defaultable.rb
|
72
73
|
- spec/attr_defaultable_spec.rb
|
73
74
|
- spec/spec_helper.rb
|
74
75
|
homepage: https://github.com/Originate/attr_defaultable
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.2.
|
95
|
+
rubygems_version: 2.2.2
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: An additional attr macro for default values.
|