well-actually 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/well_actually/mounter.rb +10 -4
- data/lib/well_actually/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c08542aa3ee4a91ec771fa10868963b993fc51c3
|
4
|
+
data.tar.gz: 0f2c74bc11a9ae2719f1ab33f092a5149fcbfea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8caaa11c2608e1f73016e77e6b7d1f9e1f7a6baef9400eb003af1be4b200181661e95dd547e2988c81bac7629854a66a6be6b9897062917030b1c51fcd6ce7
|
7
|
+
data.tar.gz: 671b39d883b460e6ee87c309e84fd813065498a46b794659a7cc2ec72d173c089adbe23d23e2b2c3cde63932c1f62cde318f00032cba59c423a670895d04f5ea
|
data/README.md
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
module WellActually
|
2
2
|
class Mounter
|
3
|
-
attr_reader :klass, :overwrites, :attributes
|
3
|
+
attr_reader :klass, :overwrites, :attributes, :strick
|
4
4
|
|
5
5
|
BLANK_RE = defined?(String::BLANK_RE) ? String::BLANK_RE : /\A[[:space:]]*\z/
|
6
6
|
|
7
|
-
def initialize(klass:, overwrites: nil, overwrite: nil, attributes:)
|
7
|
+
def initialize(klass:, overwrites: nil, overwrite: nil, attributes:, strict:false)
|
8
8
|
overwrites = overwrite || overwrites
|
9
9
|
raise ArgumentError.new("overwrite must be a symbol or an array of symbols") unless overwrites.is_a?(Symbol) || (overwrites.is_a?(Array) && overwrites.all?{|a| a.is_a?(Symbol)})
|
10
10
|
raise ArgumentError.new("attributes must be an array of symbols") unless attributes.is_a?(Array) && attributes.all?{|a| a.is_a?(Symbol)}
|
11
11
|
@klass = klass
|
12
12
|
@overwrites = overwrites
|
13
13
|
@attributes = attributes.uniq
|
14
|
+
@strict = strict
|
14
15
|
end
|
15
16
|
|
16
17
|
def mount
|
17
18
|
klass.class_variable_set(:@@well_actually_attributes, attributes.map{|_attr| _attr.to_s})
|
18
19
|
klass.class_variable_set(:@@well_actually_overwrites, [*overwrites])
|
20
|
+
klass.class_variable_set(:@@well_actually_strict, strick)
|
19
21
|
|
20
22
|
klass.send(:define_singleton_method, :well_actually_attributes) do
|
21
23
|
self.class_variable_get(:@@well_actually_attributes)
|
@@ -29,10 +31,14 @@ module WellActually
|
|
29
31
|
self.class_variable_get(:@@well_actually_overwrites)
|
30
32
|
end
|
31
33
|
|
34
|
+
klass.send(:define_singleton_method, :well_actually_strict) do
|
35
|
+
self.class_variable_get(:@@well_actually_strict)
|
36
|
+
end
|
37
|
+
|
32
38
|
klass.send(:define_method, :well_actually_overwrites) do
|
33
39
|
self.class.well_actually_overwrites.map do |overwrite|
|
34
|
-
self.public_send(overwrite)
|
35
|
-
end.reduce({}) do |result, overwrite|
|
40
|
+
self.public_send(overwrite) if (self.respond_to?(overwrite) || self.class.well_actually_strict)
|
41
|
+
end.compact.reduce({}) do |result, overwrite|
|
36
42
|
result.merge(overwrite || {}) do |key, v1, v2|
|
37
43
|
v1 = nil unless self.well_actually_overwrite_value_check(key, v1)
|
38
44
|
v2 = nil unless self.well_actually_overwrite_value_check(key, v2)
|