activeresource-attributes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9c80868bfca98400c9394297bf5b9b8c6e17990c58138d19fa3c77a01660585
4
+ data.tar.gz: 58166a5a877f58c85a87c6f8f73a10255f64e9f4787319dc8da3bfa13d8c38f9
5
+ SHA512:
6
+ metadata.gz: c215ad01db4d79843d36e994ac342899c046f5d17e8787b1fd408adab7e307c896de074d2687de52491f34ba9d38c0257454f8d7c4fc0e8224fe113bccfa4c49
7
+ data.tar.gz: 973968451f00c80b08e70de88333485a897f09ae5cd90ef5d6c51bd8a2a236cfccbeed8e137e084ca06124a68425e355c947b0189dcce1d02918c2ea2da4a04c
@@ -0,0 +1,58 @@
1
+ require "active_resource"
2
+
3
+ module ActiveResource
4
+ module Attributes
5
+ def self.included(base)
6
+ base.include ActiveModel::Attributes
7
+ base.prepend CompatibilityPatch
8
+ end
9
+
10
+ module CompatibilityPatch
11
+ def initialize(attributes = {}, persisted = false)
12
+ @attributes = self.class._default_attributes.deep_dup
13
+ @prefix_options = {}
14
+ @persisted = persisted
15
+ load(attributes, false, persisted)
16
+ end
17
+
18
+ def load(attributes, remove_root = false, persisted = false)
19
+ unless attributes.respond_to?(:to_hash)
20
+ raise ArgumentError, "expected attributes to be able to convert to Hash, got #{attributes.inspect}"
21
+ end
22
+
23
+ attributes = attributes.to_hash
24
+ @prefix_options, attributes = split_options(attributes)
25
+
26
+ if attributes.keys.size == 1
27
+ remove_root = self.class.element_name == attributes.keys.first.to_s
28
+ end
29
+
30
+ attributes = Formats.remove_root(attributes) if remove_root
31
+
32
+ attributes.each do |key, value|
33
+ attribute_value =
34
+ case value
35
+ when Array
36
+ resource = nil
37
+ value.map do |attrs|
38
+ if attrs.is_a?(Hash)
39
+ resource ||= find_or_create_resource_for_collection(key)
40
+ resource.new(attrs, persisted)
41
+ else
42
+ attrs.duplicable? ? attrs.dup : attrs
43
+ end
44
+ end
45
+ when Hash
46
+ resource = find_or_create_resource_for(key)
47
+ resource.new(value, persisted)
48
+ else
49
+ value.duplicable? ? value.dup : value
50
+ end
51
+
52
+ public_send("#{key}=", attribute_value)
53
+ end
54
+ self
55
+ end
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeresource-attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Burtsev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeresource
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ description: This ActiveResource extension which integrates ActiveModel::Attributes
42
+ for type casting and default values.
43
+ email: sergey@burtsev.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/active_resource_attributes.rb
49
+ homepage: https://github.com/SergeyBurtsev/activeresource-attributes
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.4.10
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: ActiveResource attributes extension
72
+ test_files: []