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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdaee495f63042b5010be919ac446ad53f6a5109
4
- data.tar.gz: 1e52b9d0dfe979ba3d9c2fdc3ca34b285ce79e90
3
+ metadata.gz: 7eab9f889c572c66734f4ba7e24344d144bf08e2
4
+ data.tar.gz: cb39206f27494433958fd58e88955768889a66a9
5
5
  SHA512:
6
- metadata.gz: 38a464530152410fc2a6fdc4c97aabd5bbcf7f693ff0412ab54d8938af23f764e62014c8defc54930f066b1aa83b2cea4e3ff2c1c479b0fc3ad4759f173fb5a9
7
- data.tar.gz: 9d126a1f70fd06dc17e98b88a2b50afe64095d8c1701c9e12ea97083ca0acdc28cf644013591fad438b795d153b22935ee8b2999550c92560ac3233a9b814ae4
6
+ metadata.gz: 212044b980f026a62c62dea455a5e49cf4c77dd26af246c78ca8c42d424a5e1c082f379e1e4e8325a7cc4dde6731e86955af1f5df56616abed034b96ed8e613e
7
+ data.tar.gz: c03f8cb025b7009377f1998a983f954b97f5fd86403099162b9a37906264abc8ca3b7bf830cbf12da4c495ee0ffd8640be1c34d45dae237d68dacbe9362c5016
@@ -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 :boolean then !!val
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
- else val
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)
@@ -1,3 +1,3 @@
1
1
  module RailsMetadata
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Neyer