creatable 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c83e3f19290c6508f5dd3440c16c4153ecdab7d
4
- data.tar.gz: d676eae79e326cf161399f709ec4e65edcb356f0
3
+ metadata.gz: c329dfc34d0517b100f5f53dcd1d56997ff21ded
4
+ data.tar.gz: 332be29fed1620fbb6cfea7fd6b6fce9904b6ffd
5
5
  SHA512:
6
- metadata.gz: 72cefaad2c05643ff0a09a72151bb5d726b8b751483e1581c8dbe27a4efa1432130b151c856e1a461f48d84e431cc5ad86c3a6f59a9904f117947201b3e32e11
7
- data.tar.gz: e897d53dc78f7ef879c8e074d9a9d79592bf841ad3dafb8b149c5549b86942407aa21080d63dc07f2aed9993f21683f5f7b8f6be948e047c453c5330ebb3431e
6
+ metadata.gz: 6e112941a632494e7c0ea34bff9e0b56751726d75fa4ecbb1a6f74efc31908a0efb168067784713cd53558de8602a836c845709f456d70f8b53a5ff84daa49ca
7
+ data.tar.gz: e65394e04cfe7df279f5c4d583615fd5fbf81c86291b84171566ee3abe241408b1120d912eeb746c8e009e2e83cfeff5728181787d86dc0ee12cbdc8fc730bc9
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ _config.yml
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
- # extend the class (not include)
28
- extend Creatable
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 [creatable](https://github.com/erniebrodeur/creatable).
78
+ Bug reports and pull requests are welcome on GitHub at [github.com](https://github.com/erniebrodeur/creatable).
@@ -1,5 +1,5 @@
1
1
  require "creatable/version"
2
- require 'creatable/instance_methods'
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 InstanceMethods
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 InstanceMethods
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
 
@@ -1,3 +1,3 @@
1
1
  module Creatable
2
- VERSION = '2.1.0'.freeze # VERSION
2
+ VERSION = '2.1.1'.freeze # VERSION
3
3
  end
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.0
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-13 00:00:00.000000000 Z
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/instance_methods.rb
246
+ - lib/creatable/class_methods.rb
248
247
  - lib/creatable/version.rb
249
248
  homepage: https://github.com/erniebrodeur/creatable
250
249
  licenses: []
@@ -1 +0,0 @@
1
- theme: jekyll-theme-midnight