freyja 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/freyja/base.rb +25 -4
- data/lib/freyja/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6a7b8de4b0382de4e7c66cfe731448619e210b1
|
4
|
+
data.tar.gz: 6a422a739eb93b7720e09dd5113d52e293ac8ab7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60b00780ae04677841518ff88ee83796a4f182818afbd5d990e792aa32e54c8ff25ee888d8a31c810cb8d915ec150ba90a3c5ec5d4ed54fa53f7cbf717939b7d
|
7
|
+
data.tar.gz: fceb24bac57703487d74d3b490c3f3e13219d8633daa88ef37df107c83ae322bd9af18a0fecc589e933cf3318b3b6b07dddcea9e39630dcd8c58608a92b8425f
|
data/lib/freyja/base.rb
CHANGED
@@ -10,6 +10,22 @@ class Freyja::Base
|
|
10
10
|
@attributes = args
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.defaults
|
14
|
+
@defaults
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.set_default(attribute, value)
|
18
|
+
make_sure_defaults_is_set
|
19
|
+
|
20
|
+
@defaults[attribute] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.default(attribute)
|
24
|
+
make_sure_defaults_is_set
|
25
|
+
|
26
|
+
defaults[attribute]
|
27
|
+
end
|
28
|
+
|
13
29
|
def self.has_one(attribute, translator = nil)
|
14
30
|
@has_one ||= []
|
15
31
|
@has_one << {
|
@@ -53,7 +69,7 @@ class Freyja::Base
|
|
53
69
|
if self.respond_to?(attr)
|
54
70
|
result[attr] = send(attr)
|
55
71
|
else
|
56
|
-
result[attr] = source[attr]
|
72
|
+
result[attr] = source[attr] || self.class.default(attr)
|
57
73
|
end
|
58
74
|
end
|
59
75
|
end
|
@@ -66,7 +82,7 @@ class Freyja::Base
|
|
66
82
|
if self.respond_to?(attr)
|
67
83
|
value = send(attr)
|
68
84
|
else
|
69
|
-
value = source[attr]
|
85
|
+
value = source[attr] || self.class.default(attr)
|
70
86
|
end
|
71
87
|
if value.present?
|
72
88
|
if association[:class]
|
@@ -89,7 +105,7 @@ class Freyja::Base
|
|
89
105
|
if self.respond_to?(attr)
|
90
106
|
value = send(attr)
|
91
107
|
else
|
92
|
-
value = source[attr]
|
108
|
+
value = source[attr] || self.class.default(attr)
|
93
109
|
end
|
94
110
|
if value.present?
|
95
111
|
if association[:class]
|
@@ -115,4 +131,9 @@ class Freyja::Base
|
|
115
131
|
end
|
116
132
|
end
|
117
133
|
|
118
|
-
|
134
|
+
private
|
135
|
+
|
136
|
+
def self.make_sure_defaults_is_set
|
137
|
+
@defaults ||= HashWithIndifferentAccess.new
|
138
|
+
end
|
139
|
+
end
|
data/lib/freyja/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freyja
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanislav Spiridonov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.4.5
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Freyja, Njord`s daughter
|