all_futures 1.0.2 → 2.0.0
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 +4 -4
- data/Gemfile +4 -1
- data/Gemfile.lock +297 -0
- data/LICENSE.txt +1 -1
- data/README.md +59 -77
- data/Rakefile +13 -1
- data/SUMMARY.md +22 -2
- data/bin/console +8 -0
- data/bin/loc +0 -0
- data/bin/setup +0 -0
- data/bin/standardize +0 -0
- data/lib/all_futures/association.rb +42 -0
- data/lib/all_futures/association_index.rb +69 -0
- data/lib/all_futures/attributes.rb +28 -0
- data/lib/all_futures/base.rb +66 -0
- data/lib/all_futures/callbacks.rb +71 -0
- data/lib/all_futures/configuration.rb +9 -0
- data/lib/all_futures/dirty.rb +116 -0
- data/lib/all_futures/embeds.rb +40 -0
- data/lib/all_futures/errors.rb +37 -0
- data/lib/all_futures/finder.rb +214 -0
- data/lib/all_futures/locale/en.yml +49 -0
- data/lib/all_futures/persistence.rb +595 -0
- data/lib/all_futures/presenter.rb +35 -0
- data/lib/all_futures/railtie.rb +26 -0
- data/lib/all_futures/translation.rb +22 -0
- data/lib/all_futures/validations.rb +10 -0
- data/lib/all_futures/version.rb +3 -1
- data/lib/all_futures/versions.rb +80 -0
- data/lib/all_futures.rb +24 -1
- data/lib/vendor/ACTIVE_ENTITY_MIT-LICENSE +42 -0
- data/lib/vendor/README.md +8 -0
- data/lib/vendor/active_entity/aggregations.rb +277 -0
- data/lib/vendor/active_entity/associations/embeds/association.rb +134 -0
- data/lib/vendor/active_entity/associations/embeds/builder/association.rb +105 -0
- data/lib/vendor/active_entity/associations/embeds/builder/collection_association.rb +71 -0
- data/lib/vendor/active_entity/associations/embeds/builder/embedded_in.rb +38 -0
- data/lib/vendor/active_entity/associations/embeds/builder/embeds_many.rb +13 -0
- data/lib/vendor/active_entity/associations/embeds/builder/embeds_one.rb +16 -0
- data/lib/vendor/active_entity/associations/embeds/builder/singular_association.rb +28 -0
- data/lib/vendor/active_entity/associations/embeds/collection_association.rb +209 -0
- data/lib/vendor/active_entity/associations/embeds/collection_proxy.rb +310 -0
- data/lib/vendor/active_entity/associations/embeds/embedded_in_association.rb +31 -0
- data/lib/vendor/active_entity/associations/embeds/embeds_many_association.rb +15 -0
- data/lib/vendor/active_entity/associations/embeds/embeds_one_association.rb +26 -0
- data/lib/vendor/active_entity/associations/embeds/singular_association.rb +35 -0
- data/lib/vendor/active_entity/associations.rb +168 -0
- data/lib/vendor/active_entity/attribute_assignment.rb +87 -0
- data/lib/vendor/active_entity/attribute_decorators.rb +90 -0
- data/lib/vendor/active_entity/attribute_methods/before_type_cast.rb +78 -0
- data/lib/vendor/active_entity/attribute_methods/dirty.rb +180 -0
- data/lib/vendor/active_entity/attribute_methods/primary_key.rb +96 -0
- data/lib/vendor/active_entity/attribute_methods/query.rb +38 -0
- data/lib/vendor/active_entity/attribute_methods/read.rb +44 -0
- data/lib/vendor/active_entity/attribute_methods/serialization.rb +90 -0
- data/lib/vendor/active_entity/attribute_methods/time_zone_conversion.rb +93 -0
- data/lib/vendor/active_entity/attribute_methods/write.rb +54 -0
- data/lib/vendor/active_entity/attribute_methods.rb +833 -0
- data/lib/vendor/active_entity/attributes.rb +240 -0
- data/lib/vendor/active_entity/base.rb +293 -0
- data/lib/vendor/active_entity/callbacks.rb +21 -0
- data/lib/vendor/active_entity/coders/json.rb +15 -0
- data/lib/vendor/active_entity/coders/yaml_column.rb +50 -0
- data/lib/vendor/active_entity/core.rb +348 -0
- data/lib/vendor/active_entity/enum.rb +260 -0
- data/lib/vendor/active_entity/errors.rb +69 -0
- data/lib/vendor/active_entity/gem_version.rb +17 -0
- data/lib/vendor/active_entity/inheritance.rb +176 -0
- data/lib/vendor/active_entity/integration.rb +78 -0
- data/lib/vendor/active_entity/locale/en.yml +45 -0
- data/lib/vendor/active_entity/model_schema.rb +118 -0
- data/lib/vendor/active_entity/nested_attributes.rb +554 -0
- data/lib/vendor/active_entity/persistence.rb +20 -0
- data/lib/vendor/active_entity/railtie.rb +76 -0
- data/lib/vendor/active_entity/readonly_attributes.rb +55 -0
- data/lib/vendor/active_entity/reflection.rb +447 -0
- data/lib/vendor/active_entity/serialization.rb +28 -0
- data/lib/vendor/active_entity/store.rb +291 -0
- data/lib/vendor/active_entity/translation.rb +24 -0
- data/lib/vendor/active_entity/type/date.rb +9 -0
- data/lib/vendor/active_entity/type/date_time.rb +9 -0
- data/lib/vendor/active_entity/type/internal/timezone.rb +17 -0
- data/lib/vendor/active_entity/type/json.rb +30 -0
- data/lib/vendor/active_entity/type/modifiers/array.rb +72 -0
- data/lib/vendor/active_entity/type/modifiers/array_without_blank.rb +19 -0
- data/lib/vendor/active_entity/type/registry.rb +112 -0
- data/lib/vendor/active_entity/type/serialized.rb +71 -0
- data/lib/vendor/active_entity/type/text.rb +11 -0
- data/lib/vendor/active_entity/type/time.rb +21 -0
- data/lib/vendor/active_entity/type/unsigned_integer.rb +17 -0
- data/lib/vendor/active_entity/type.rb +75 -0
- data/lib/vendor/active_entity/validate_embeds_association.rb +300 -0
- data/lib/vendor/active_entity/validations/absence.rb +25 -0
- data/lib/vendor/active_entity/validations/associated.rb +60 -0
- data/lib/vendor/active_entity/validations/length.rb +26 -0
- data/lib/vendor/active_entity/validations/presence.rb +68 -0
- data/lib/vendor/active_entity/validations/subset.rb +76 -0
- data/lib/vendor/active_entity/validations/uniqueness_in_embeds.rb +91 -0
- data/lib/vendor/active_entity/validations/uniqueness_on_active_record.rb +234 -0
- data/lib/vendor/active_entity/validations.rb +47 -0
- data/lib/vendor/active_entity/version.rb +10 -0
- data/lib/vendor/active_entity.rb +99 -0
- data/lib/vendor/core_ext/array_without_blank.rb +48 -0
- metadata +172 -31
- data/lib/all_futures/all_futures.rb +0 -28
- data/lib/all_futures/config.rb +0 -14
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/core_ext/object/try"
|
|
4
|
+
|
|
5
|
+
module ActiveEntity
|
|
6
|
+
module AttributeMethods
|
|
7
|
+
module TimeZoneConversion
|
|
8
|
+
class TimeZoneConverter < DelegateClass(Type::Value) # :nodoc:
|
|
9
|
+
def deserialize(value)
|
|
10
|
+
convert_time_to_time_zone(super)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def cast(value)
|
|
14
|
+
return if value.nil?
|
|
15
|
+
|
|
16
|
+
if value.is_a?(Hash)
|
|
17
|
+
set_time_zone_without_conversion(super)
|
|
18
|
+
elsif value.respond_to?(:in_time_zone)
|
|
19
|
+
begin
|
|
20
|
+
super(user_input_in_time_zone(value)) || super
|
|
21
|
+
rescue ArgumentError
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
map_avoiding_infinite_recursion(super) { |v| cast(v) }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def convert_time_to_time_zone(value)
|
|
32
|
+
return if value.nil?
|
|
33
|
+
|
|
34
|
+
if value.acts_like?(:time)
|
|
35
|
+
value.in_time_zone
|
|
36
|
+
elsif value.is_a?(::Float)
|
|
37
|
+
value
|
|
38
|
+
else
|
|
39
|
+
map_avoiding_infinite_recursion(value) { |v| convert_time_to_time_zone(v) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def set_time_zone_without_conversion(value)
|
|
44
|
+
::Time.zone.local_to_utc(value).try(:in_time_zone) if value
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def map_avoiding_infinite_recursion(value)
|
|
48
|
+
map(value) do |v|
|
|
49
|
+
if value.equal?(v)
|
|
50
|
+
nil
|
|
51
|
+
else
|
|
52
|
+
yield(v)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
extend ActiveSupport::Concern
|
|
59
|
+
|
|
60
|
+
included do
|
|
61
|
+
mattr_accessor :time_zone_aware_attributes, instance_writer: false, default: false
|
|
62
|
+
|
|
63
|
+
class_attribute :skip_time_zone_conversion_for_attributes, instance_writer: false, default: []
|
|
64
|
+
class_attribute :time_zone_aware_types, instance_writer: false, default: [ :datetime, :time ]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module ClassMethods # :nodoc:
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def inherited(subclass)
|
|
71
|
+
super
|
|
72
|
+
# We need to apply this decorator here, rather than on module inclusion. The closure
|
|
73
|
+
# created by the matcher would otherwise evaluate for `ActiveEntity::Base`, not the
|
|
74
|
+
# sub class being decorated. As such, changes to `time_zone_aware_attributes`, or
|
|
75
|
+
# `skip_time_zone_conversion_for_attributes` would not be picked up.
|
|
76
|
+
subclass.class_eval do
|
|
77
|
+
matcher = ->(name, type) { create_time_zone_conversion_attribute?(name, type) }
|
|
78
|
+
decorate_matching_attribute_types(matcher, "_time_zone_conversion") do |type|
|
|
79
|
+
TimeZoneConverter.new(type)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def create_time_zone_conversion_attribute?(name, cast_type)
|
|
85
|
+
enabled_for_column = time_zone_aware_attributes &&
|
|
86
|
+
!skip_time_zone_conversion_for_attributes.include?(name.to_sym)
|
|
87
|
+
|
|
88
|
+
enabled_for_column && time_zone_aware_types.include?(cast_type.type)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveEntity
|
|
4
|
+
module AttributeMethods
|
|
5
|
+
module Write
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
attribute_method_suffix "="
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module ClassMethods # :nodoc:
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def define_method_attribute=(name, owner:)
|
|
16
|
+
ActiveEntity::AMAttributeMethods::AttrNames.define_attribute_accessor_method(
|
|
17
|
+
owner, name, writer: true,
|
|
18
|
+
) do |temp_method_name, attr_name_expr|
|
|
19
|
+
owner <<
|
|
20
|
+
"def #{temp_method_name}(value)" <<
|
|
21
|
+
" _write_attribute(#{attr_name_expr}, value)" <<
|
|
22
|
+
"end"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Updates the attribute identified by <tt>attr_name</tt> with the
|
|
28
|
+
# specified +value+. Empty strings for Integer and Float columns are
|
|
29
|
+
# turned into +nil+.
|
|
30
|
+
def write_attribute(attr_name, value)
|
|
31
|
+
name = attr_name.to_s
|
|
32
|
+
name = self.class.attribute_aliases[name] || name
|
|
33
|
+
|
|
34
|
+
name = @primary_key if name == "id" && @primary_key
|
|
35
|
+
@attributes.write_from_user(name, value)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# This method exists to avoid the expensive primary_key check internally, without
|
|
39
|
+
# breaking compatibility with the write_attribute API
|
|
40
|
+
def _write_attribute(attr_name, value) # :nodoc:
|
|
41
|
+
@attributes.write_from_user(attr_name, value)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
alias :attribute= :_write_attribute
|
|
45
|
+
private :attribute=
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def write_attribute_without_type_cast(attr_name, value)
|
|
50
|
+
@attributes.write_cast_value(attr_name, value)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|