acts_as_inheritable 0.4.0 → 0.5.0

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: 2b1041cc8ec082ae65cf0b6c89252e2298bd24bd
4
- data.tar.gz: 77d74d6cdcba7e5f40239ae9e361536d18778feb
3
+ metadata.gz: 391d2159779c617d4641194c7a9e49585763661f
4
+ data.tar.gz: 96ff7393944b993f84b0976e31e88b38669fcc62
5
5
  SHA512:
6
- metadata.gz: 3a2fe15e1ce0aefb9a44bf9528de5055caa03dc4112a103cadcaabaebf12e69518c3ba484c1c5db9191d5b431c4b898a26c579c8cc4cff248a9e6eb401ce0ed4
7
- data.tar.gz: db0ae6bfb76bd7fcf4c0f3308b77dc0ae80798ff1ed22af9f888dd61f0b5b7c3f104def94d576a72b9b756d50a71c8f85511181afa1b1e16d0027a8623439d4f
6
+ metadata.gz: e3bfcbbc59f32c2205ffa8debfa389d5ef5301b2fc641ad8ba38fe9b0cbf356b0d6727039451b3ca545f02c07b28063bd81d9cebfac4f23fc5cbea9ed433851a
7
+ data.tar.gz: 6d4c676e640ac8f32c8b8ce100446a38cef44702a5c5e8196c0150ca7ad2d6ec372e9030430ccd8e3c40d46880d030335956f819036765c3bd582d894b659b5a
data/.codeclimate.yml CHANGED
@@ -17,6 +17,9 @@ engines:
17
17
  # to turn off an engine, set enabled to `false` or remove it
18
18
  rubocop:
19
19
  enabled: true
20
+ checks:
21
+ Rubocop/Style/Documentation:
22
+ enabled: false
20
23
 
21
24
  # Engines can analyze files and report issues on them, but you can separately
22
25
  # decide which files will receive ratings based on those issues. This is
data/README.md CHANGED
@@ -101,6 +101,19 @@ son.pet.inspect # => #<Pet id: 2, person_id: 2, name: "Mango", breed: "Golden Re
101
101
 
102
102
  ````
103
103
 
104
+ ### Handling your own `dup`
105
+
106
+ By default new relations are _duplicated_ using [dup](http://ruby-doc.org/core-2.2.3/Object.html#method-i-dup), which produces a shallow copy of the object. But you can also handle this as you want by defining a `duplicate!` method.
107
+
108
+
109
+ ## Testing
110
+
111
+ All tests follow the RSpec format and are located in the spec directory. They can be run with:
112
+
113
+ ````bash
114
+ $ rspec
115
+ ````
116
+
104
117
  ## Contributing
105
118
 
106
119
  1. Fork it ( https://github.com/esbanarango/acts_as_inheritable/fork )
@@ -109,6 +122,14 @@ son.pet.inspect # => #<Pet id: 2, person_id: 2, name: "Mango", breed: "Golden Re
109
122
  4. Push to the branch (`git push origin my-new-feature`)
110
123
  5. Create a new Pull Request
111
124
 
125
+ ## Donating
126
+ Support this project and [others by esbanarango][gratipay-esbanarango] via [gratipay][gratipay-esbanarango].
127
+
128
+ [![Support via Gratipay][gratipay]][gratipay-esbanarango]
129
+
130
+ [gratipay]: https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.png
131
+ [gratipay-esbanarango]: https://gratipay.com/esbanarango/
132
+
112
133
  ## Author
113
134
 
114
135
  This was written by [Esteban Arango Medina](http://esbanarango.com) while working at [Blue Sky Cards](https://www.blueskycards.com/).
@@ -1,10 +1,10 @@
1
1
  require 'active_record'
2
- require "acts_as_inheritable/version"
2
+ require 'acts_as_inheritable/version'
3
3
 
4
4
  module ActsAsInheritable
5
5
  def acts_as_inheritable(options)
6
- raise ArgumentError, "Hash expected, got #{options.class.name}" if !options.is_a?(Hash)
7
- raise ArgumentError, "Empty options" if options[:attributes].blank? && options[:associations].blank?
6
+ fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
7
+ fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
8
8
 
9
9
  class_attribute :inheritable_configuration
10
10
 
@@ -20,8 +20,8 @@ module ActsAsInheritable
20
20
  # relations defined on `INHERITABLE_ASSOCIATIONS`. For each instance on
21
21
  # each relation it re-creates it.
22
22
  def inherit_relations(model_parent = send(:parent), current = self)
23
- if model_parent && model_parent.class.method_defined?(:inheritable_configuration) && model_parent.class::inheritable_configuration[:associations]
24
- model_parent.class::inheritable_configuration[:associations].each do |relation|
23
+ if model_parent && current.class.method_defined?(:inheritable_configuration) && current.class.inheritable_configuration[:associations]
24
+ current.class.inheritable_configuration[:associations].each do |relation|
25
25
  parent_relation = model_parent.send(relation)
26
26
  relation_instances = parent_relation.respond_to?(:each) ? parent_relation : [parent_relation].compact
27
27
  relation_instances.each do |relation_instance|
@@ -55,22 +55,25 @@ module ActsAsInheritable
55
55
  return parent_name if new_relation.respond_to?(parent_name)
56
56
  many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
57
57
  many_and_one_associations.each do |association|
58
- if association.klass.to_s.downcase == new_relation.class.to_s.downcase && association.options.has_key?(:as)
59
- as = association.options[:as].to_s
60
- parent_name = as if new_relation.respond_to?(as) && !new_relation.respond_to?(parent_name)
58
+ next unless association.klass.to_s.downcase == new_relation.class.to_s.downcase && association.options.key?(:as)
59
+ as = association.options[:as].to_s
60
+ if new_relation.respond_to?(as) && !new_relation.respond_to?(parent_name)
61
+ parent_name = as
61
62
  break
62
63
  end
63
64
  end
64
65
  # Relations has a diffeent name
65
66
  unless new_relation.respond_to?(parent_name)
66
- new_relation.class.reflections.each_key do |reflection|
67
- parent_name = reflection if new_relation.class.reflections[reflection].class_name == model_parent.class.name
67
+ new_relation.class.reflections.each_key do |reflection|
68
+ next unless new_relation.class.reflections[reflection].class_name == model_parent.class.name
69
+ parent_name = reflection
70
+ break
68
71
  end
69
72
  end
70
73
  parent_name
71
74
  end
72
75
 
73
- def inherit_attributes(force = false, not_force_for=[])
76
+ def inherit_attributes(force = false, not_force_for = [])
74
77
  if has_parent? && self.class.inheritable_configuration[:attributes]
75
78
  # Attributes
76
79
  self.class.inheritable_configuration[:attributes].each do |attribute|
@@ -83,6 +86,7 @@ module ActsAsInheritable
83
86
  end
84
87
  end
85
88
  end
89
+
86
90
  if defined?(ActiveRecord)
87
91
  # Extend ActiveRecord's functionality
88
92
  ActiveRecord::Base.send :extend, ActsAsInheritable
@@ -1,3 +1,3 @@
1
1
  module ActsAsInheritable
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_inheritable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esteban Arango Medina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler