activemodel-associations 0.1.2 → 0.2.0.beta1

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: 6685a28ca5b130f8762895039083ba25e8e7e230
4
- data.tar.gz: c245032bc18aa7fae1f9a25dbdcb21ac07d1bce7
3
+ metadata.gz: 96d915a47cf355c89bfb5267bfdabbbc74904373
4
+ data.tar.gz: c53bdffbaa73f1a10de38161362a5bf560c74a3b
5
5
  SHA512:
6
- metadata.gz: 786a262f5f9c012f46bc2d3fa9748634ce89745ebe8b7c636b718a42fae3a86310ae494d4c8f61bb94e751bfa42816cd6b2231550b44d874a807ea19cf5c7201
7
- data.tar.gz: e329a2da7598e1ea434ad0a2b16458405e9cd89a669843906418ad813aa1432c7b5eaeec40721c532acf8543f39844dfa6530e931f9731a4328d530ae118ad0e
6
+ metadata.gz: 2e87d7fc4bc20f1253bd7fd35ae63d474a457491f08ea5c5e1ca64f6ae82982c2aa0cc92149c693f85f7ab8ce04a8a3d4ddbfd7b0b0d267f06396592cd4402fb
7
+ data.tar.gz: 37db84892aeddc84b52443c5a9a4722f3efdcbb9d4f000390a948caccc6c5cfeaa7d00d0c494f2b297c021489e75c2022dd7d0f15fe5c099ce525fb7d90df4c8
@@ -1,20 +1,14 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.2
5
- - 2.1
6
- - 2.0
4
+ - 2.3.0
5
+ - 2.2.4
7
6
  gemfile:
8
- - gemfiles/activerecord-40.gemfile
9
7
  - gemfiles/activerecord-41.gemfile
10
8
  - gemfiles/activerecord-412.gemfile
11
9
  - gemfiles/activerecord-42.gemfile
10
+ - gemfiles/activerecord-50.gemfile
12
11
  - gemfiles/activerecord-master.gemfile
13
12
  matrix:
14
- exclude:
15
- - rvm: 2.0
16
- gemfile: gemfiles/activerecord-master.gemfile
17
- - rvm: 2.1
18
- gemfile: gemfiles/activerecord-master.gemfile
19
13
  allow_failures:
20
14
  - gemfile: gemfiles/activerecord-master.gemfile
data/Rakefile CHANGED
@@ -6,17 +6,19 @@ RSpec::Core::RakeTask.new(:spec)
6
6
  task :default => :spec
7
7
 
8
8
  namespace :spec do
9
- %w(activerecord-40 activerecord-41 activerecord-412 activerecord-42 activerecord-master).each do |gemfile|
9
+ %w(activerecord-41 activerecord-412 activerecord-42 activerecord-50 activerecord-master).each do |gemfile|
10
10
  desc "Run Tests by #{gemfile}.gemfile"
11
11
  task gemfile do
12
- sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
13
- sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
12
+ Bundler.with_clean_env do
13
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
14
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
15
+ end
14
16
  end
15
17
  end
16
18
 
17
19
  desc "Run All Tests"
18
20
  task :all do
19
- %w(activerecord-40 activerecord-41 activerecord-412 activerecord-42 activerecord-master).each do |gemfile|
21
+ %w(activerecord-41 activerecord-412 activerecord-42 activerecord-50 activerecord-master).each do |gemfile|
20
22
  Rake::Task["spec:#{gemfile}"].invoke
21
23
  end
22
24
  end
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", "~> 5.0.0.beta"
4
+ gem "activemodel", "~> 5.0.0.beta"
5
+ gem "activesupport", "~> 5.0.0.beta"
6
+
7
+ gemspec :path => "../"
@@ -4,6 +4,7 @@ require 'active_model/associations/autosave_association'
4
4
  require 'active_model/associations/override_methods'
5
5
  require 'active_record/associations/builder/has_many_for_active_model'
6
6
  require 'active_record/associations/has_many_for_active_model_association'
7
+ require 'active_support/core_ext/module'
7
8
 
8
9
  module ActiveModel
9
10
  module Associations
@@ -14,13 +15,15 @@ module ActiveModel
14
15
  include ActiveRecordReflection
15
16
  include OverrideMethods
16
17
 
18
+ included do
19
+ mattr_accessor :belongs_to_required_by_default, instance_accessor: false
20
+ end
21
+
17
22
  module ClassMethods
18
23
  # define association like ActiveRecord
19
24
  def belongs_to(name, scope = nil, options = {})
20
25
  reflection = ActiveRecord::Associations::Builder::BelongsTo.build(self, name, scope, options)
21
- if ActiveRecord.version >= Gem::Version.new("4.1")
22
- ActiveRecord::Reflection.add_reflection self, name, reflection
23
- end
26
+ ActiveRecord::Reflection.add_reflection self, name, reflection
24
27
  end
25
28
 
26
29
  # define association like ActiveRecord
@@ -32,9 +35,7 @@ module ActiveModel
32
35
  end
33
36
 
34
37
  reflection = ActiveRecord::Associations::Builder::HasManyForActiveModel.build(self, name, scope, options, &extension)
35
- if ActiveRecord.version >= Gem::Version.new("4.1")
36
- ActiveRecord::Reflection.add_reflection self, name, reflection
37
- end
38
+ ActiveRecord::Reflection.add_reflection self, name, reflection
38
39
 
39
40
  mixin = generated_association_methods
40
41
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
@@ -1,9 +1,9 @@
1
1
  module ActiveModel::Associations
2
2
  module AssociationScopeExtension
3
- if ActiveRecord.version < Gem::Version.new("4.1")
4
- def add_constraints(scope)
5
- if reflection.options[:active_model]
6
- target_ids = reflection.options[:target_ids]
3
+ if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
4
+ def add_constraints(scope, owner, association_klass, refl, chain_head, chain_tail)
5
+ if refl.options[:active_model]
6
+ target_ids = refl.options[:target_ids]
7
7
  return scope.where(id: owner[target_ids])
8
8
  end
9
9
 
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  module Associations
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0.beta1"
4
4
  end
5
5
  end
@@ -1,7 +1,23 @@
1
1
  module ActiveRecord::Associations::Builder
2
2
  class HasManyForActiveModel < HasMany
3
- def valid_options
4
- super + [:active_model, :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
3
+ p ActiveRecord.version
4
+ p ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
5
+ if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
6
+ AR_CALLBACK_METHODS = %i(define_callback before_validation after_validation before_save after_save before_update after_update)
7
+
8
+ def self.valid_options(_options)
9
+ super + [:active_model, :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
10
+ end
11
+
12
+ def self.define_callbacks(model, reflection)
13
+ if AR_CALLBACK_METHODS.all? { |meth| self.respond_to?(meth) }
14
+ super
15
+ end
16
+ end
17
+ else
18
+ def valid_options
19
+ super + [:active_model, :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
20
+ end
5
21
  end
6
22
  end
7
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel-associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -207,10 +207,10 @@ files:
207
207
  - README.md
208
208
  - Rakefile
209
209
  - activemodel-associations.gemspec
210
- - gemfiles/activerecord-40.gemfile
211
210
  - gemfiles/activerecord-41.gemfile
212
211
  - gemfiles/activerecord-412.gemfile
213
212
  - gemfiles/activerecord-42.gemfile
213
+ - gemfiles/activerecord-50.gemfile
214
214
  - gemfiles/activerecord-master.gemfile
215
215
  - lib/active_model/associations.rb
216
216
  - lib/active_model/associations/active_record_reflection.rb
@@ -242,12 +242,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
242
  version: '0'
243
243
  required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  requirements:
245
- - - ">="
245
+ - - ">"
246
246
  - !ruby/object:Gem::Version
247
- version: '0'
247
+ version: 1.3.1
248
248
  requirements: []
249
249
  rubyforge_project:
250
- rubygems_version: 2.4.8
250
+ rubygems_version: 2.5.1
251
251
  signing_key:
252
252
  specification_version: 4
253
253
  summary: ActiveRecord Association Helper for PORO (Plain Old Ruby Object)
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 4.0.0"
4
- gem "activemodel", "~> 4.0.0"
5
- gem "activesupport", "~> 4.0.0"
6
-
7
- gemspec :path => "../"