rails_metadata 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_metadata.rb +5 -3
- data/lib/rails_metadata/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eab9f889c572c66734f4ba7e24344d144bf08e2
|
4
|
+
data.tar.gz: cb39206f27494433958fd58e88955768889a66a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 212044b980f026a62c62dea455a5e49cf4c77dd26af246c78ca8c42d424a5e1c082f379e1e4e8325a7cc4dde6731e86955af1f5df56616abed034b96ed8e613e
|
7
|
+
data.tar.gz: c03f8cb025b7009377f1998a983f954b97f5fd86403099162b9a37906264abc8ca3b7bf830cbf12da4c495ee0ffd8640be1c34d45dae237d68dacbe9362c5016
|
data/lib/rails_metadata.rb
CHANGED
@@ -6,19 +6,21 @@ module RailsMetadata
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
def metadata(name, type)
|
9
|
+
def metadata(name, type=nil)
|
10
10
|
define_method(name.to_s) do
|
11
11
|
self.metadata = {} unless self.metadata.present?
|
12
12
|
self.metadata[name]
|
13
13
|
end
|
14
14
|
define_method(name.to_s + '=') do |val|
|
15
15
|
val = case type
|
16
|
-
when
|
16
|
+
when nil then val
|
17
|
+
when :boolean then !(val.nil? || val.empty? || val)
|
17
18
|
when :string then String(val)
|
18
19
|
when :integer then val.to_i
|
19
20
|
when :float then val.to_f
|
20
21
|
when :array then Array(val)
|
21
|
-
|
22
|
+
when :hash then Hash(val)
|
23
|
+
else raise ArgumentError, "Invalid type(:boolean, :string, :integer, :float, :array, :hash)"
|
22
24
|
end
|
23
25
|
self.metadata = {} unless self.metadata.present?
|
24
26
|
self.metadata.merge!(name => val)
|