active_delegate 0.1.2 → 0.1.3

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: 9257eb3266aac4668738613ec5fee51d5bd64fbd
4
- data.tar.gz: d31d564366686047837729288ef8e61d1d68b609
3
+ metadata.gz: 5480972eade03dbf9ba6243f90028eb9ad46ffaa
4
+ data.tar.gz: 8372d588d8f5b383eba4f727bc56b78e2a533d77
5
5
  SHA512:
6
- metadata.gz: 5d080e28edc7ddea35d0985bd401dbe5b7c3eb096638bd63761b6384b71994db51346ca9724de857cd257e4515e359af7d8bd30f8a88f8389263b52b371ac244
7
- data.tar.gz: 939e98b59a2b65954c7c467c925e5820fd29e99c870f2f2c903b219d468b3c46d1f924bc0ca4e4fd4e062ed83c609003034dd7bdc9c0612b3859d9cb1a746b19
6
+ metadata.gz: ead37ccef91c33ebb9ad0076894a6fd129331d516ad81cba08995cf984e7ac6ec96106ba9cfca05fa19e10861225cc6a900184c78d39128ec6af4fb8a1ff22c1
7
+ data.tar.gz: a1c912a92de34d6f1fdb52d7ac696c43b8d71de8a587b00a6d29e8812c426887607b13e8c00f07939f8b9a4df8d3a9b23c5ad99b141e6250ea80492a334ec632
@@ -1,28 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_delegate (0.1.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.1)
12
- activesupport (= 5.1.1)
13
- activerecord (5.1.1)
14
- activemodel (= 5.1.1)
15
- activesupport (= 5.1.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.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.8.4)
25
- minitest (5.10.2)
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.14.6
42
+ 1.15.4
@@ -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
- require "active_record"
8
-
9
- class << self
10
- def included(model_class)
11
- model_class.extend self
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
- def delegate_associations(*args)
16
- options = args.extract_options!
17
- Associations.new(self, options)
18
- end
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
@@ -1,3 +1,3 @@
1
1
  module ActiveDelegate
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  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.2
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-09-28 00:00:00.000000000 Z
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 a ActiveRecord
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