clavatar 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/clavatar.rb +6 -5
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1febd4c690ded4fd22e7254a28782040032b313
4
- data.tar.gz: e11f9aebe3f5f98e6a9e8778523b0a83067ac13a
3
+ metadata.gz: 8bf8acd0bef190c30df6f83601381a111eb9995b
4
+ data.tar.gz: b39b837348b64a8830e81fdb1592f397e91ce4d4
5
5
  SHA512:
6
- metadata.gz: e7364ce18a9d5bb2bd45ce3320719f620f00fc6ed91062bce5e43f7f0b873f43d0f5d814c6e079d576eccb3fc660c6a8c4059d9af6a0558e46f8d8cc536d7bb3
7
- data.tar.gz: db6ddcb13abb1d0665499a2a569c3752f1de14ffb3d5f894094c14bb5d3dea30408fc1ba9391aa6639868dfb7a9f30aa9f3ad38d6588938ef128e5c30c4d33cd
6
+ metadata.gz: 5e0d642c1a5e629c2452028c74b4ddd87447a11c61ddf0b8d1b23006df762c8fe3019391a7609be792d37f94bc470741f803d117bf87da53819aa878c005605f
7
+ data.tar.gz: 49fe7d4193bf09212b0da64c6271216f05dbe1cbe995bbea453b48db6ede0249eec54da3fd6a152be121b30aefd7ff0fb42d35f8c594ced31fb62683be0ddfc7
data/lib/clavatar.rb CHANGED
@@ -3,11 +3,12 @@ require 'ostruct'
3
3
  # Clavatar module
4
4
  module Clavatar
5
5
  def self.cast(hash, klass, example)
6
- klass_name = "#{klass}Avatar"
7
- if Object.const_defined? klass_name
8
- klass = Object.const_get klass_name
6
+ name_space = klass.respond_to?(:parent) ? klass.parent : Object
7
+ klass_name = "#{klass.name.split('::').last}Avatar"
8
+ if name_space.const_defined? klass_name
9
+ klass = name_space.const_get klass_name
9
10
  else
10
- klass = Object.const_set klass_name, Class.new(klass)
11
+ klass = name_space.const_set klass_name, Class.new(klass)
11
12
  end
12
13
 
13
14
  args = {}
@@ -21,7 +22,7 @@ module Clavatar
21
22
  end
22
23
  end
23
24
 
24
- instance = klass.new args
25
+ instance = klass.new args.merge(hash)
25
26
  accessible_attr.each do |attr|
26
27
  instance.send("#{attr}=", hash[attr])
27
28
  end
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Clavatar gem version
2
2
  module Clavatar
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clavatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Han