creatable 2.1.0 → 2.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +27 -4
- data/lib/creatable.rb +2 -2
- data/lib/creatable/{instance_methods.rb → class_methods.rb} +5 -2
- data/lib/creatable/version.rb +1 -1
- metadata +3 -4
- data/_config.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c329dfc34d0517b100f5f53dcd1d56997ff21ded
|
4
|
+
data.tar.gz: 332be29fed1620fbb6cfea7fd6b6fce9904b6ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e112941a632494e7c0ea34bff9e0b56751726d75fa4ecbb1a6f74efc31908a0efb168067784713cd53558de8602a836c845709f456d70f8b53a5ff84daa49ca
|
7
|
+
data.tar.gz: e65394e04cfe7df279f5c4d583615fd5fbf81c86291b84171566ee3abe241408b1120d912eeb746c8e009e2e83cfeff5728181787d86dc0ee12cbdc8fc730bc9
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -20,12 +20,12 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
gem install creatable
|
22
22
|
|
23
|
-
## Usage
|
23
|
+
## Class Usage
|
24
24
|
|
25
25
|
``` ruby
|
26
26
|
class A
|
27
|
-
#
|
28
|
-
|
27
|
+
# include the class
|
28
|
+
include Creatable
|
29
29
|
|
30
30
|
# add an attribute (will default to accessor)
|
31
31
|
attribute name: 'an_attribute'
|
@@ -44,6 +44,29 @@ class A
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
+
## Instance Usage
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
i = A.create an_attribute: 'this'
|
51
|
+
|
52
|
+
# pass a block to create for it to be processed during initialize
|
53
|
+
# note that you have to accept an argument in the block to get the object
|
54
|
+
# you want to change.
|
55
|
+
i = A.create(an_attribute: 'this') { |obj| obj.an_attribute = 'that' }
|
56
|
+
|
57
|
+
# a hash of the current attributes.
|
58
|
+
i.attributes
|
59
|
+
|
60
|
+
# an array of the names
|
61
|
+
i.attribute_names
|
62
|
+
|
63
|
+
# The current values of all attributes as a hash
|
64
|
+
i.to_parameters
|
65
|
+
|
66
|
+
# creating a new object from parameters
|
67
|
+
A.create i.to_parameters
|
68
|
+
```
|
69
|
+
|
47
70
|
## Development
|
48
71
|
|
49
72
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -52,4 +75,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
52
75
|
|
53
76
|
## Contributing
|
54
77
|
|
55
|
-
Bug reports and pull requests are welcome on GitHub at [
|
78
|
+
Bug reports and pull requests are welcome on GitHub at [github.com](https://github.com/erniebrodeur/creatable).
|
data/lib/creatable.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "creatable/version"
|
2
|
-
require 'creatable/
|
2
|
+
require 'creatable/class_methods'
|
3
3
|
|
4
4
|
# Main module you include in your class
|
5
5
|
module Creatable
|
@@ -7,7 +7,7 @@ module Creatable
|
|
7
7
|
# @param [Object] object
|
8
8
|
# @return [Void]
|
9
9
|
def self.included(object)
|
10
|
-
object.extend
|
10
|
+
object.extend ClassMethods
|
11
11
|
end
|
12
12
|
|
13
13
|
# Returns the hash of built attributes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Creatable
|
2
2
|
# Class methods that get mixed in.
|
3
|
-
module
|
3
|
+
module ClassMethods
|
4
4
|
# Returns the list of attributes attatched to this object
|
5
5
|
# @return [Array] the current attributes
|
6
6
|
def attributes
|
@@ -45,8 +45,11 @@ module Creatable
|
|
45
45
|
object = new
|
46
46
|
names = attributes.map { |e| e[:name].to_sym }
|
47
47
|
args.each do |k, v|
|
48
|
-
object.instance_variable_set "@#{k}".to_sym, v if names.include? k
|
48
|
+
object.instance_variable_set "@#{k}".to_sym, v if names.include? k.to_sym
|
49
49
|
end
|
50
|
+
|
51
|
+
yield(object) if block_given?
|
52
|
+
|
50
53
|
object
|
51
54
|
end
|
52
55
|
|
data/lib/creatable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: creatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Brodeur
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -239,12 +239,11 @@ files:
|
|
239
239
|
- LICENSE
|
240
240
|
- README.md
|
241
241
|
- Rakefile
|
242
|
-
- _config.yml
|
243
242
|
- bin/console
|
244
243
|
- bin/setup
|
245
244
|
- creatable.gemspec
|
246
245
|
- lib/creatable.rb
|
247
|
-
- lib/creatable/
|
246
|
+
- lib/creatable/class_methods.rb
|
248
247
|
- lib/creatable/version.rb
|
249
248
|
homepage: https://github.com/erniebrodeur/creatable
|
250
249
|
licenses: []
|
data/_config.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
theme: jekyll-theme-midnight
|