id 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- id (0.0.4)
4
+ id (0.0.5)
5
5
  activesupport
6
6
 
7
7
  GEM
data/id.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'id'
3
- s.version = '0.0.5'
3
+ s.version = '0.0.6'
4
4
  s.date = '2013-03-28'
5
5
  s.summary = "Simple models based on hashes"
6
6
  s.description = "Developed at On The Beach Ltd. Contact russell.dunphy@onthebeach.co.uk"
@@ -1,3 +1,4 @@
1
1
  require_relative 'missing_attribute_error'
2
+ require_relative 'hashifier'
2
3
  require_relative 'model/all'
3
4
  require_relative 'model'
@@ -0,0 +1,23 @@
1
+ module Id
2
+ class Hashifier
3
+
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ def hashify
9
+ Hash[data.map { |k, v| [ k.to_s, as_data(v) ] }]
10
+ end
11
+
12
+ private
13
+
14
+ def as_data(v)
15
+ case v
16
+ when Id::Model then v.data
17
+ when Array then v.first.is_a?(Id::Model) ? v.map(&:data) : v
18
+ else v end
19
+ end
20
+
21
+ attr_reader :data
22
+ end
23
+ end
@@ -3,7 +3,7 @@ module Id
3
3
  attr_reader :data
4
4
 
5
5
  def initialize(data)
6
- @data = Hash[data.map { |k, v| [k.to_s, v.is_a?(Id::Model) ? v.data : v] }]
6
+ @data = Hashifier.new(data).hashify
7
7
  end
8
8
 
9
9
  def set(values)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -76,6 +76,7 @@ files:
76
76
  - id.gemspec
77
77
  - lib/id.rb
78
78
  - lib/id/all.rb
79
+ - lib/id/hashifier.rb
79
80
  - lib/id/missing_attribute_error.rb
80
81
  - lib/id/model.rb
81
82
  - lib/id/model/all.rb