husky 0.4.1 → 0.4.2

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: 12b94059675b908cc9af20daf28df777f197733f
4
- data.tar.gz: 221725a9ccd1d0cab1338d4ede143e361c20bc0f
3
+ metadata.gz: 4c41bb95e59ad9b0b2b65042b56014623fef5b7e
4
+ data.tar.gz: bcb31362d91d1172647d631905c8a051757d8f71
5
5
  SHA512:
6
- metadata.gz: 3ac816efc4da042e0dc287d6543ea3faa2cc0a22929ff22d1a19c973b218d026b77ba2f45267ab71c39b31c576eb3e3dbb8e4f92fd4208eef15952a289d50138
7
- data.tar.gz: c9d567442a2349e8f934a67d970ced7ea026c0a74afd423089745ccea021f764a38d54ae40da140aa0bf1620fae9fe2330f55a9eb29411c04457f4943a6862ed
6
+ metadata.gz: 4b6c405cbea1bb6ac5ec07bee2c2789c235f7e58a079324dfc6a502118569f9861814c24368bb15dbc322ed7fe15be11dfc5c6ca53b9f5ffff2003abfa551e02
7
+ data.tar.gz: acad03874d6bab7f0983d14359556751ead6207c44a7ceba73f09c6a648b2f8539f4dc9fa80d3261eb21307403a9b0e37c590853d89fd67058dd4079b675a902
@@ -1,29 +1,47 @@
1
- require 'forwardable'
1
+ require 'delegate'
2
2
 
3
3
  module Husky
4
4
 
5
- class Entity
6
- extend Forwardable
5
+ class Entity < SimpleDelegator
7
6
 
8
7
  class << self
9
8
 
10
- def fields(*field_names)
11
- field_names.each do |field_name|
12
- def_delegators :_data, field_name
13
- def_delegators :_data, "#{field_name}="
14
- end
15
- end
16
-
17
9
  def wrap(items)
18
10
  items.map { |item| new(item) }
19
11
  end
20
12
 
13
+ def new_from_hash(hash)
14
+ raise hash_error(hash) unless hash.is_a? Hash
15
+ instance = allocate
16
+ instance.initialize_from_hash(hash)
17
+ instance
18
+ end
19
+
20
+ private
21
+
22
+ def hash_error(hash)
23
+ "Entity#initialize_from_hash expects a hash as an argument, and you provided a #{hash.class.name} (#=> #{hash})."
24
+ end
25
+
21
26
  end
22
27
 
23
- attr_reader :_data
28
+ attr_reader :object
29
+
30
+ def initialize(object)
31
+ @object = object
32
+ super
33
+ end
24
34
 
25
- def initialize(_data)
26
- @_data = _data
35
+ def initialize_from_hash(post_data)
36
+ post_data.each_pair do |key, value|
37
+ instance_variable_set("@#{key}", value)
38
+ end
39
+
40
+ post_data.each_pair do |key, value|
41
+ self.class.send(:define_method, key) do
42
+ instance_variable_get("@#{key}")
43
+ end
44
+ end
27
45
  end
28
46
 
29
47
  end
@@ -1,3 +1,3 @@
1
1
  module Husky
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: husky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Fiser