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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9d3cbd45c8bd9beb62542631fb22dd7ee23a0ea
4
- data.tar.gz: bf57eeccaff8abaf0422d223d8fddd0625786c71
3
+ metadata.gz: c08542aa3ee4a91ec771fa10868963b993fc51c3
4
+ data.tar.gz: 0f2c74bc11a9ae2719f1ab33f092a5149fcbfea4
5
5
  SHA512:
6
- metadata.gz: 3dbca6039c04b91e1c6c98da262291f33d98afa6f502be08cab79a38f7570e8951d681e3691dc29ec60c7a2aaf4feacfbdbdf2917d61df852dcfd5d3d0362b08
7
- data.tar.gz: 6535a3575c0994f6a19227b4cb69bb10c6b0acf2a7102a1a34b42de521992ef354e00b85edd6acc3410faf223e80ed98679d7c6135b3c440d530d46eda823750
6
+ metadata.gz: bd8caaa11c2608e1f73016e77e6b7d1f9e1f7a6baef9400eb003af1be4b200181661e95dd547e2988c81bac7629854a66a6be6b9897062917030b1c51fcd6ce7
7
+ data.tar.gz: 671b39d883b460e6ee87c309e84fd813065498a46b794659a7cc2ec72d173c089adbe23d23e2b2c3cde63932c1f62cde318f00032cba59c423a670895d04f5ea
data/README.md CHANGED
@@ -5,7 +5,7 @@ Is tested with pure ruby classes and classes that inherit from ActiveRecord::Bas
5
5
  Add this line to your application's Gemfile:
6
6
 
7
7
  ```ruby
8
- gem 'well-actually'
8
+ gem 'well-actually', require: 'well_actually'
9
9
  ```
10
10
 
11
11
  And then execute:
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module WellActually
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: well-actually
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Rove