duck_record 0.0.5 → 0.0.6

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: bc1667096dfb88fc6d2b74ea577440eb5bcf8fd0
4
- data.tar.gz: 86a738d000265404c2309bf4d04ff6a5db11d446
3
+ metadata.gz: ea74dd5ae7d2fa4b29957220898223bffacd1e11
4
+ data.tar.gz: b6b5baee57bc4bd3915172b22b84a2fb948a236b
5
5
  SHA512:
6
- metadata.gz: 2e92f601db7fae6b7a687cb42caa647ba39ca2441f0174a6999feeb5a0d1537eab686c7297734981ca2bb77109b3eaf7f7a5cff7a1da63f2bff1ef6efe15f2a9
7
- data.tar.gz: e61511a9b89654b61a1350d69a748e44cba5b4ef8fd3ef061667db04f12a1d57e00d1a6ac95dfa63a8c32ddf512d7b146c7432a1f0a7f9ea6ba7937dbd5c9977
6
+ metadata.gz: a36210ba1a1fff6aae044d453641b0db60a9f93b80e24a261c012b2bec8f6afdc57a80def009289a8711f0463d7ec9ad6c9238aff7c71ad8157ea4e3fafc74e3
7
+ data.tar.gz: 7a04f4c5824149560e3d0784781b2535a05438d090c3e397ff324ebc9a2e1911424c6a22342318f09f50e9faf6c43e22c40a11f05553d3adbe38c0189a073215
@@ -57,6 +57,7 @@ module DuckRecord
57
57
  end
58
58
 
59
59
  def initialize_attributes(record, attributes = nil) #:nodoc:
60
+ attributes ||= {}
60
61
  record.assign_attributes(attributes)
61
62
  end
62
63
 
@@ -7,6 +7,15 @@ module DuckRecord
7
7
  module Core
8
8
  extend ActiveSupport::Concern
9
9
 
10
+ included do
11
+ ##
12
+ # :singleton-method:
13
+ # Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
14
+ # dates and times from the database. This is set to :utc by default.
15
+ mattr_accessor :default_timezone, instance_writer: false
16
+ self.default_timezone = :utc
17
+ end
18
+
10
19
  module ClassMethods
11
20
  def allocate
12
21
  define_attribute_methods
@@ -396,7 +396,6 @@ module DuckRecord
396
396
 
397
397
  if existing_record
398
398
  existing_record.assign_attributes(assignable_attributes)
399
- association(association_name).initialize_attributes(existing_record)
400
399
  else
401
400
  method = "build_#{association_name}"
402
401
  if respond_to?(method)
@@ -1,6 +1,11 @@
1
1
  require 'active_model/type'
2
2
 
3
3
  require 'duck_record/type/internal/abstract_json'
4
+ require 'duck_record/type/internal/timezone'
5
+
6
+ require 'duck_record/type/date'
7
+ require 'duck_record/type/date_time'
8
+ require 'duck_record/type/time'
4
9
  require 'duck_record/type/json'
5
10
 
6
11
  require 'duck_record/type/array'
@@ -44,9 +49,6 @@ module DuckRecord
44
49
  String = ActiveModel::Type::String
45
50
  Text = ActiveModel::Type::Text
46
51
  UnsignedInteger = ActiveModel::Type::UnsignedInteger
47
- DateTime = ActiveModel::Type::DateTime
48
- Time = ActiveModel::Type::Time
49
- Date = ActiveModel::Type::Date
50
52
  Value = ActiveModel::Type::Value
51
53
 
52
54
  register(:big_integer, Type::BigInteger, override: false)
@@ -0,0 +1,7 @@
1
+ module DuckRecord
2
+ module Type
3
+ class Date < ActiveModel::Type::Date
4
+ include Internal::Timezone
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module DuckRecord
2
+ module Type
3
+ class DateTime < ActiveModel::Type::DateTime
4
+ include Internal::Timezone
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module DuckRecord
2
+ module Type
3
+ module Internal
4
+ module Timezone
5
+ def is_utc?
6
+ DuckRecord::Base.default_timezone == :utc
7
+ end
8
+
9
+ def default_timezone
10
+ DuckRecord::Base.default_timezone
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module DuckRecord
2
+ module Type
3
+ class Time < ActiveModel::Type::Time
4
+ include Internal::Timezone
5
+
6
+ class Value < DelegateClass(::Time) # :nodoc:
7
+ end
8
+
9
+ def serialize(value)
10
+ case value = super
11
+ when ::Time
12
+ Value.new(value)
13
+ else
14
+ value
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -1,3 +1,3 @@
1
1
  module DuckRecord
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duck_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -105,12 +105,16 @@ files:
105
105
  - lib/duck_record/translation.rb
106
106
  - lib/duck_record/type.rb
107
107
  - lib/duck_record/type/array.rb
108
+ - lib/duck_record/type/date.rb
109
+ - lib/duck_record/type/date_time.rb
108
110
  - lib/duck_record/type/decimal_without_scale.rb
109
111
  - lib/duck_record/type/internal/abstract_json.rb
112
+ - lib/duck_record/type/internal/timezone.rb
110
113
  - lib/duck_record/type/json.rb
111
114
  - lib/duck_record/type/registry.rb
112
115
  - lib/duck_record/type/serialized.rb
113
116
  - lib/duck_record/type/text.rb
117
+ - lib/duck_record/type/time.rb
114
118
  - lib/duck_record/type/unsigned_integer.rb
115
119
  - lib/duck_record/validations.rb
116
120
  - lib/duck_record/version.rb
@@ -135,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
139
  version: '0'
136
140
  requirements: []
137
141
  rubyforge_project:
138
- rubygems_version: 2.6.10
142
+ rubygems_version: 2.6.8
139
143
  signing_key:
140
144
  specification_version: 4
141
145
  summary: Used for creating virtual models like ActiveType or ModelAttribute does