typecast 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae264bc787481a2a893d02fd669bbf8cab35ac56
4
- data.tar.gz: 3812c7ad940d5365ad520d7ab5461e6e3426d0b7
3
+ metadata.gz: 6ab8f1650d1e14de428e215bf8c11c26738eae07
4
+ data.tar.gz: fb46b3866ea380cb935c9109c4348e7e12150a1f
5
5
  SHA512:
6
- metadata.gz: 2892564732a97685768a0a3440c4d8456dd0a123fbbaff91d90361423dca215148cd453ee138092f7f0c771901c5d1d550a2c4f12bc8598644bae60a6bac5dcd
7
- data.tar.gz: 97a7db182f2232abe219dfdbe77245745c7a2743a6a0f2dd4999cc65d37e7104eb731e08845cadf92eb7b20a7f79f90f9143fddb5645bd41cbb9b0c677eeaf5a
6
+ metadata.gz: 9bf81694ebce5752c7d31a114238a94b3f5d0636f6ea8dd1f75a715b9f6eca7c225f94e450bcf09c10d5b3b61ed0528aaee97d21b8627744392b8056e894af6b
7
+ data.tar.gz: 8d740bf2c55fe09af27432a73cce9ad4f8910c1f16741bb59765fff5ebf2f0a947df832754f362148b45ea8dfdbb5ac2171020a6a9fa0251245f34b283614235
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Typecast
1
+ # TypeCast
2
2
 
3
3
  Type casting of attributes defined in superclass or realized through method_missing. Works only for string attributes.
4
4
 
@@ -1,3 +1,3 @@
1
1
  module TypeCast
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/type_cast.rb CHANGED
@@ -48,7 +48,7 @@ module TypeCast
48
48
  method_missing(:#{attribute})
49
49
  end
50
50
  self.#{attribute}_before_type_cast = uncasted
51
- if uncasted.kind_of?(String) && uncasted.respond_to?(:#{conversion_method})
51
+ if uncasted.respond_to?(:#{conversion_method})
52
52
  uncasted.__send__(:#{conversion_method})
53
53
  else
54
54
  uncasted
@@ -33,4 +33,8 @@ describe Customer do
33
33
  expect(subject.created_at_before_type_cast).to eq "2014-05-26T19:31:04+03:00"
34
34
  expect(subject.dynamic_created_at_before_type_cast).to eq "2014-05-27T13:19:25+03:00"
35
35
  end
36
+
37
+ it "performs type casting of any value (not only String) if provided method name for type cast" do
38
+ expect(subject.suggestions_count).to eq 0
39
+ end
36
40
  end
@@ -5,7 +5,7 @@ class Customer < User
5
5
 
6
6
  type_cast :expires_at, DateTime
7
7
  type_cast :created_at, :updated_at, Time
8
- type_cast :orders_count, :to_i
8
+ type_cast :orders_count, :suggestions_count, :to_i
9
9
  type_cast :aov, :to_f
10
10
  type_cast :dynamic_created_at, Time
11
11
  end
data/spec/support/user.rb CHANGED
@@ -19,6 +19,10 @@ class User
19
19
  "26 September 2014 at 19:50:38 EEST"
20
20
  end
21
21
 
22
+ def suggestions_count
23
+ nil
24
+ end
25
+
22
26
  def method_missing(method_name, *args, &block)
23
27
  return super unless "dynamic_created_at" == method_name.to_s
24
28
  "2014-05-27T13:19:25+03:00"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typecast
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
  - Alex Avoyants
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport