coerced_accessor 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: f7145312b0c3b70a97a9cd0e3ffb444e85cb5963
4
- data.tar.gz: d0a1ead53be0fde30753b896a12a2ec9d3285c52
3
+ metadata.gz: 2221ecad5891caadc531537eda79f84fdfbcf3dd
4
+ data.tar.gz: 884fa63efaccc599bb0bc1de989bc8c074422926
5
5
  SHA512:
6
- metadata.gz: 9d91228a03b74eb7b0c512f6b4278333e4e7044632d228a0368fafdcf05768bcf81bdcbadde218128286f140d7421fa974c5a646c961397d59a4a249bd3ff1e7
7
- data.tar.gz: f12ca4be50acb1b452163ebc80c028faa0fb5b52a68a1814e991858fb11824b49132afb1d3f3ce94ab2b8a8ed18bd7169aac0365befdb6f0d7963ebf303baec9
6
+ metadata.gz: 717636a2589d536bed119521805161c2d2c63e237a9e1af5cad9f32f9ad20d92790b6d1125ef86a9dcda53dc7d3e5ef341e4acdf5a93e393607f9b6d9e13b07d
7
+ data.tar.gz: ef1f708a2ac587d06a20cc52903d78fbb3dce14abd7dd6c0ff5684f7c4ddab44d558a175e1ec5e5c12155d0bf531bf5bc6346ebe037704faafb6c5a07a13011b
data/README.md CHANGED
@@ -18,6 +18,8 @@ Or install it yourself as:
18
18
 
19
19
  ## Human readable dates
20
20
 
21
+ Motivation: Rails Time.new = String can parse most date formats. On the other hand, if user inputs '12.01.2001' in text field - we should keep this value after form submission. Instead of this he will see `Time#to_s` result (`"2001-01-12 00:00:00 +0300"`) by default.
22
+
21
23
  ```ruby
22
24
  class UserForm
23
25
  extend CoercedAccessor::Time
@@ -52,7 +54,7 @@ class User < ActiveRecord::Base
52
54
  extend CoercedAccessor::Compound
53
55
 
54
56
  belongs_to :imageable
55
- compound_accessor :imageable_formatted, :imageable_id, :imageable_type
57
+ compound_accessor :imageable_formatted, :imageable_id, :imageable_type, delimiter: ':'
56
58
  end
57
59
 
58
60
  user = User.new
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/array/extract_options'
2
+ require 'active_support/time_with_zone'
2
3
  require "coerced_accessor/version"
3
4
  require "coerced_accessor/time"
4
5
  require "coerced_accessor/compound"
@@ -5,7 +5,7 @@ module CoercedAccessor
5
5
  time_class = options.delete(:time_class) || ::Time
6
6
 
7
7
  define_method("#{as}=") do |value|
8
- time = time_class.parse(value, format) rescue nil
8
+ time = time_class.strptime(value, format) rescue nil
9
9
  send("#{attribute}=", time)
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module CoercedAccessor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -27,7 +27,7 @@ describe CoercedAccessor::Time do
27
27
  end
28
28
 
29
29
  it ':as option works' do
30
- subject.year = "20090202"
30
+ subject.year = "2009"
31
31
  expect(subject.year).to eq("2009")
32
32
  end
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coerced_accessor
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
  - Viktor Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.2.2
129
+ rubygems_version: 2.4.8
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Provides object attribute aliases coercing values to/from human readable