rails_metadata 0.0.2 → 0.0.3

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: 7eab9f889c572c66734f4ba7e24344d144bf08e2
4
- data.tar.gz: cb39206f27494433958fd58e88955768889a66a9
3
+ metadata.gz: 084ee18887c21e25caac6e07614d1fe9196748b4
4
+ data.tar.gz: db5578b6f8f54823e44b89d30eaf02c54eb8cfb7
5
5
  SHA512:
6
- metadata.gz: 212044b980f026a62c62dea455a5e49cf4c77dd26af246c78ca8c42d424a5e1c082f379e1e4e8325a7cc4dde6731e86955af1f5df56616abed034b96ed8e613e
7
- data.tar.gz: c03f8cb025b7009377f1998a983f954b97f5fd86403099162b9a37906264abc8ca3b7bf830cbf12da4c495ee0ffd8640be1c34d45dae237d68dacbe9362c5016
6
+ metadata.gz: a72c957d8bce64a33c0db8edf02ce9d6b4e58485d46370beec5864d08bcc3f871bea3fd7435dffd273edda2c8a22ff5af01d7c242783b0090682ca5117e33b48
7
+ data.tar.gz: cef7076850762436e4664cb94931c3b600fcb93afd66d9426eac72a44a18a63fb6d1ad9448eadf1b63fcd5f1a05f696c8874a9493c32d92f596dce5dad623778
@@ -11,19 +11,19 @@ module RailsMetadata
11
11
  self.metadata = {} unless self.metadata.present?
12
12
  self.metadata[name]
13
13
  end
14
+ typecast = case type
15
+ when nil then val
16
+ when :boolean then lambda { |v| v.is_a?(String) ? v.empty? : !!v }
17
+ when :string then lambda { |v| v.to_s }
18
+ when :integer then lambda { |v| v.to_i }
19
+ when :float then lambda { |v| v.to_f }
20
+ when :array then lambda { |v| v.to_a }
21
+ when :hash then lambda { |v| v.to_hash }
22
+ else raise ArgumentError, "Invalid type(:boolean, :string, :integer, :float, :array, :hash)"
23
+ end
14
24
  define_method(name.to_s + '=') do |val|
15
- val = case type
16
- when nil then val
17
- when :boolean then !(val.nil? || val.empty? || val)
18
- when :string then String(val)
19
- when :integer then val.to_i
20
- when :float then val.to_f
21
- when :array then Array(val)
22
- when :hash then Hash(val)
23
- else raise ArgumentError, "Invalid type(:boolean, :string, :integer, :float, :array, :hash)"
24
- end
25
25
  self.metadata = {} unless self.metadata.present?
26
- self.metadata.merge!(name => val)
26
+ self.metadata.merge!(name => typecast.call(val))
27
27
  end
28
28
  end
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module RailsMetadata
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Neyer