clavatar 0.0.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 +7 -0
- data/lib/clavatar.rb +30 -0
- data/lib/version.rb +4 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1febd4c690ded4fd22e7254a28782040032b313
|
4
|
+
data.tar.gz: e11f9aebe3f5f98e6a9e8778523b0a83067ac13a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7364ce18a9d5bb2bd45ce3320719f620f00fc6ed91062bce5e43f7f0b873f43d0f5d814c6e079d576eccb3fc660c6a8c4059d9af6a0558e46f8d8cc536d7bb3
|
7
|
+
data.tar.gz: db6ddcb13abb1d0665499a2a569c3752f1de14ffb3d5f894094c14bb5d3dea30408fc1ba9391aa6639868dfb7a9f30aa9f3ad38d6588938ef128e5c30c4d33cd
|
data/lib/clavatar.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
# Clavatar module
|
4
|
+
module Clavatar
|
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
|
9
|
+
else
|
10
|
+
klass = Object.const_set klass_name, Class.new(klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
args = {}
|
14
|
+
accessible_attr = []
|
15
|
+
example.instance_variables.each do |attr|
|
16
|
+
attr = attr.to_s.sub('@', '').to_sym
|
17
|
+
if example.respond_to? ("#{attr}=")
|
18
|
+
accessible_attr << attr
|
19
|
+
else
|
20
|
+
args[attr] = hash[attr]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
instance = klass.new args
|
25
|
+
accessible_attr.each do |attr|
|
26
|
+
instance.send("#{attr}=", hash[attr])
|
27
|
+
end
|
28
|
+
return instance
|
29
|
+
end
|
30
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clavatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Han
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Class avatar which convert a hash to an object
|
14
|
+
email: hex0cter@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/clavatar.rb
|
20
|
+
- lib/version.rb
|
21
|
+
homepage: https://github.com/hex0cter/clavatar
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.14.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Class avatar which convert a hash to an object
|
45
|
+
test_files: []
|