modelish 0.2.0 → 0.2.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.
- data/CHANGELOG.md +6 -0
- data/lib/modelish/base.rb +26 -1
- data/lib/modelish/version.rb +1 -1
- data/modelish.gemspec +1 -1
- metadata +8 -7
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.2.1 (2012-3-8)
|
4
|
+
|
5
|
+
* Bug fix to make behavior predictable for translated properties when both the property
|
6
|
+
name and the translated property name are present in an initialization hash (issue #5).
|
7
|
+
* Modelish::Base#to_hash now processes the contents of Array-typed properties.
|
8
|
+
|
3
9
|
## 0.2.0 (2012-1-16)
|
4
10
|
|
5
11
|
* Added support for mapping the same input property name to multiple outputs. This means that
|
data/lib/modelish/base.rb
CHANGED
@@ -11,6 +11,26 @@ module Modelish
|
|
11
11
|
include Validations
|
12
12
|
extend Configuration
|
13
13
|
|
14
|
+
def initialize(attributes = {}, &block)
|
15
|
+
super(&block)
|
16
|
+
|
17
|
+
self.class.defaults.each_pair do |prop, value|
|
18
|
+
self[prop] = value
|
19
|
+
end
|
20
|
+
|
21
|
+
attributes.delete_if do |k,v|
|
22
|
+
if self.class.translations.keys.include?(k.to_sym)
|
23
|
+
self[k]=v
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end if attributes
|
27
|
+
|
28
|
+
attributes.each_pair do |att, value|
|
29
|
+
self[att] = value
|
30
|
+
end if attributes
|
31
|
+
end
|
32
|
+
|
33
|
+
|
14
34
|
# Creates a new attribute.
|
15
35
|
#
|
16
36
|
# @param [Symbol] name the name of the property
|
@@ -53,7 +73,12 @@ module Modelish
|
|
53
73
|
out = {}
|
54
74
|
self.class.properties.each do |p|
|
55
75
|
val = self.send(p)
|
56
|
-
|
76
|
+
if val.is_a?(Array)
|
77
|
+
out[p.to_s]||=[]
|
78
|
+
out[p.to_s].concat(val.collect{|x|x.respond_to?(:to_hash) ? x.to_hash : x})
|
79
|
+
else
|
80
|
+
out[p.to_s] = val.respond_to?(:to_hash) ? val.to_hash : val
|
81
|
+
end
|
57
82
|
end
|
58
83
|
out
|
59
84
|
end
|
data/lib/modelish/version.rb
CHANGED
data/modelish.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency('hashie', '
|
22
|
+
s.add_dependency('hashie', '1.0.0')
|
23
23
|
|
24
24
|
s.add_development_dependency('rspec','~> 2.5')
|
25
25
|
s.add_development_dependency('yard', '~> 0.6')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modelish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Maeve Revels
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-08 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,13 +24,14 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - "="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 23
|
30
30
|
segments:
|
31
31
|
- 1
|
32
32
|
- 0
|
33
|
-
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
34
35
|
type: :runtime
|
35
36
|
version_requirements: *id001
|
36
37
|
- !ruby/object:Gem::Dependency
|