active_delegate 0.1.2 → 0.1.3
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.lock +11 -10
- data/lib/active_delegate.rb +14 -14
- data/lib/active_delegate/attributes.rb +11 -0
- data/lib/active_delegate/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5480972eade03dbf9ba6243f90028eb9ad46ffaa
|
4
|
+
data.tar.gz: 8372d588d8f5b383eba4f727bc56b78e2a533d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ead37ccef91c33ebb9ad0076894a6fd129331d516ad81cba08995cf984e7ac6ec96106ba9cfca05fa19e10861225cc6a900184c78d39128ec6af4fb8a1ff22c1
|
7
|
+
data.tar.gz: a1c912a92de34d6f1fdb52d7ac696c43b8d71de8a587b00a6d29e8812c426887607b13e8c00f07939f8b9a4df8d3a9b23c5ad99b141e6250ea80492a334ec632
|
data/Gemfile.lock
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_delegate (0.1.
|
4
|
+
active_delegate (0.1.2)
|
5
5
|
activerecord (~> 5.0)
|
6
6
|
i18n (~> 0.8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (5.1.
|
12
|
-
activesupport (= 5.1.
|
13
|
-
activerecord (5.1.
|
14
|
-
activemodel (= 5.1.
|
15
|
-
activesupport (= 5.1.
|
11
|
+
activemodel (5.1.4)
|
12
|
+
activesupport (= 5.1.4)
|
13
|
+
activerecord (5.1.4)
|
14
|
+
activemodel (= 5.1.4)
|
15
|
+
activesupport (= 5.1.4)
|
16
16
|
arel (~> 8.0)
|
17
|
-
activesupport (5.1.
|
17
|
+
activesupport (5.1.4)
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (~> 0.7)
|
20
20
|
minitest (~> 5.1)
|
21
21
|
tzinfo (~> 1.1)
|
22
22
|
arel (8.0.0)
|
23
23
|
concurrent-ruby (1.0.5)
|
24
|
-
i18n (0.
|
25
|
-
|
24
|
+
i18n (0.9.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
minitest (5.10.3)
|
26
27
|
rake (10.5.0)
|
27
28
|
thread_safe (0.3.6)
|
28
29
|
tzinfo (1.2.3)
|
@@ -38,4 +39,4 @@ DEPENDENCIES
|
|
38
39
|
rake (~> 10.0)
|
39
40
|
|
40
41
|
BUNDLED WITH
|
41
|
-
1.
|
42
|
+
1.15.4
|
data/lib/active_delegate.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
+
require 'active_record'
|
1
2
|
require 'active_delegate/version'
|
2
3
|
|
3
4
|
module ActiveDelegate
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# Autoload modules
|
4
8
|
autoload :Associations, 'active_delegate/associations'
|
5
9
|
autoload :Attributes, 'active_delegate/attributes'
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
class_methods do
|
12
|
+
# Delegate associations
|
13
|
+
def delegate_associations(*args)
|
14
|
+
options = args.extract_options!
|
15
|
+
Associations.new(self, options)
|
12
16
|
end
|
13
|
-
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def delegate_attributes(*args)
|
21
|
-
options = args.extract_options!
|
22
|
-
Attributes.new(self, options)
|
18
|
+
# Delegate attributes
|
19
|
+
def delegate_attributes(*args)
|
20
|
+
options = args.extract_options!
|
21
|
+
Attributes.new(self, options)
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
@@ -121,6 +121,7 @@ module ActiveDelegate
|
|
121
121
|
delegated = @model.try(dl_method).to_a.concat(delegated)
|
122
122
|
|
123
123
|
@model.send(:define_singleton_method, dl_method) { delegated }
|
124
|
+
define_attribute_names_and_types(delegated)
|
124
125
|
|
125
126
|
if @options[:localized].present?
|
126
127
|
localized = prefix_attributes(localized_attributes)
|
@@ -129,5 +130,15 @@ module ActiveDelegate
|
|
129
130
|
@model.send(:define_singleton_method, lc_method) { localized }
|
130
131
|
end
|
131
132
|
end
|
133
|
+
|
134
|
+
# Define attribute names and types
|
135
|
+
def define_attribute_names_and_types(attributes)
|
136
|
+
attributes.each do |attrib|
|
137
|
+
attr_name = attrib.to_s.sub("#{@options[:to]}_", '')
|
138
|
+
cast_type = association_class.attribute_types["#{attr_name}"]
|
139
|
+
|
140
|
+
@model.attribute(attrib, cast_type) unless cast_type.nil?
|
141
|
+
end
|
142
|
+
end
|
132
143
|
end
|
133
144
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_delegate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonian Guveli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.0'
|
83
|
-
description: Stores and retrieves delegatable data through attributes on
|
83
|
+
description: Stores and retrieves delegatable data through attributes on an ActiveRecord
|
84
84
|
class, with support for translatable attributes.
|
85
85
|
email:
|
86
86
|
- jonian@hardpixel.eu
|