attr_defaults 0.1.0
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 +7 -0
- data/lib/attr_defaults.rb +39 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a0747e0de5b5134e0a25fa6014077a20d52df36
|
4
|
+
data.tar.gz: 4185137327658ac6193ff0dea7ba0273c7c7f143
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 524bc9a8615fcdd4eb36f8af8f94f19a7f83d31792b72a47c39aa7eff426534d10c5a420f56888eef531cf63c73232959d0f1c916fbda2d5a987352f8fb16880
|
7
|
+
data.tar.gz: c8a96e0e9810d991c9152b9ee45a85bf0f2fd9803614fb2fe9ddb55c17a63d03cd30f678650ff799009a040a44818e8362fc66066141a0f7d8c4d35afc818fbe
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module AttrDefaults
|
2
|
+
module Initialize
|
3
|
+
def initialize
|
4
|
+
defaults = class << self.class
|
5
|
+
@attr_defaults
|
6
|
+
end
|
7
|
+
|
8
|
+
unless defaults.nil?
|
9
|
+
defaults.each do |attrs,default|
|
10
|
+
attrs.each do |attr|
|
11
|
+
instance_variable_set :"@#{attr}", default.call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def included klass
|
21
|
+
klass.prepend Initialize
|
22
|
+
|
23
|
+
class << klass
|
24
|
+
[:attr, :attr_writer, :attr_reader, :attr_accessor].each do |method|
|
25
|
+
define_method method do |*attrs, &block|
|
26
|
+
super *attrs
|
27
|
+
|
28
|
+
unless block.nil?
|
29
|
+
defaults = class << self
|
30
|
+
@attr_defaults ||= {}
|
31
|
+
end
|
32
|
+
|
33
|
+
defaults[attrs] = block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attr_defaults
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle King
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Mixin to specify defaults for Ruby's `attr` methods
|
14
|
+
email: kylejking@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/attr_defaults.rb
|
20
|
+
homepage: https://github.com/kylekyle/attr_defaults
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Adds defaults to attr methods
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|