active_conductor 0.1.1 → 0.2.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.
- data/lib/active_conductor.rb +42 -14
- metadata +2 -2
data/lib/active_conductor.rb
CHANGED
@@ -30,25 +30,42 @@ require "forwardable"
|
|
30
30
|
class ActiveConductor
|
31
31
|
include ActiveModel::Conversion
|
32
32
|
include ActiveModel::Validations
|
33
|
+
include ActiveModel::Serialization
|
33
34
|
|
34
35
|
extend ActiveModel::Naming
|
35
36
|
extend ActiveModel::Translation
|
36
37
|
extend Forwardable
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
attr_accessor :conducted_attributes
|
40
|
+
|
41
|
+
class << self
|
42
|
+
|
43
|
+
# Conduct an attribute from the conductor to the associated
|
44
|
+
# model.
|
45
|
+
#
|
46
|
+
# @example Conduct an the email and password attribute to the user model
|
47
|
+
# conduct :user, :email, :password
|
48
|
+
#
|
49
|
+
# @param model [Symbol] the name of the model
|
50
|
+
# @param *attributes [Symbol] one or more model attribute name
|
51
|
+
#
|
52
|
+
def conduct(model, *attributes)
|
53
|
+
conducted_attributes.concat(attributes.map(&:to_sym))
|
54
|
+
|
55
|
+
attributes.each do |attr|
|
56
|
+
def_delegator model, attr
|
57
|
+
def_delegator model, "#{attr}="
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Remembers the conducted attributes
|
62
|
+
#
|
63
|
+
# @return [Array] the attributes
|
64
|
+
#
|
65
|
+
def conducted_attributes
|
66
|
+
@conducted_attributes ||= []
|
51
67
|
end
|
68
|
+
|
52
69
|
end
|
53
70
|
|
54
71
|
# Initialize the conductor with optional attributes.
|
@@ -66,10 +83,21 @@ class ActiveConductor
|
|
66
83
|
#
|
67
84
|
def attributes=(attributes)
|
68
85
|
attributes.each do |key, value|
|
69
|
-
self.send("#{key}=", value)
|
86
|
+
self.send("#{key}=", value) if respond_to?(key.to_sym)
|
70
87
|
end if attributes
|
71
88
|
end
|
72
89
|
|
90
|
+
# Get the conducted attribute methods
|
91
|
+
#
|
92
|
+
# @return [Hash] the conducted attributes values
|
93
|
+
#
|
94
|
+
def attributes
|
95
|
+
self.class.conducted_attributes.inject({}) do |attributes, name|
|
96
|
+
attributes[name.to_s] = send(name)
|
97
|
+
attributes
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
73
101
|
# Tests if all of the records have been persisted.
|
74
102
|
#
|
75
103
|
# @return [true, false] the persistence status
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: active_conductor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Scott Taylor
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-03-
|
14
|
+
date: 2011-03-11 00:00:00 +01:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|