activemodel-associations 0.0.3 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 017e2f0b46163726880d4703ec352add2b9b9b05
4
- data.tar.gz: b5afa0902988cd9cae5656126178bc720d2fc12d
3
+ metadata.gz: 79477d111d595a8744d9aa8791e2af76140472c6
4
+ data.tar.gz: 2049c89ed6dcd5469f6c7d6038b4e61f8d53fc76
5
5
  SHA512:
6
- metadata.gz: 57be72dc156c9913ed2de207b866385eb32391263b5d81f7695a431c9c54fe701bab046d2f608111be3d6fa75facf14d1744eca905231d719c1717338773c85c
7
- data.tar.gz: bbbed9c4019bf1a309c4670ff54802dae9e04db77795882b171f59a4b2db1d5af10e2859eb947f44bbd03ca5ccb3185a158aca09da7c53dcd52f648184f4a0b4
6
+ metadata.gz: b14400b269f6fa840d48b83d0aa4713a95a64632abbd2c0585cc05214d3291932b8cecc9884f2f9e735cbccdb6edf56ac39d523053a018bbb793ba38a3905594
7
+ data.tar.gz: bafe78db7336da6457d3cb303c23f2c03f88bb6281513b9bf5c803f6b21a478b491ecc264cb185ea91ade09f7e47b7dc31f424f053bfc35f0cea684e853fc0c9
data/.travis.yml CHANGED
@@ -1,8 +1,20 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
- - 2.1.1
4
- - 2.0.0
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0
5
7
  gemfile:
6
8
  - gemfiles/activerecord-40.gemfile
7
9
  - gemfiles/activerecord-41.gemfile
10
+ - gemfiles/activerecord-412.gemfile
8
11
  - gemfiles/activerecord-42.gemfile
12
+ - gemfiles/activerecord-master.gemfile
13
+ matrix:
14
+ exclude:
15
+ - rvm: 2.0
16
+ gemfile: gemfiles/activerecord-master.gemfile
17
+ - rvm: 2.1
18
+ gemfile: gemfiles/activerecord-master.gemfile
19
+ allow_failures:
20
+ - gemfile: gemfiles/activerecord-master.gemfile
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'activemodel-association'
11
+ gem 'activemodel-associations'
12
12
 
13
13
  And then execute:
14
14
 
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install activemodel-association
19
+ $ gem install activemodel-associations
20
20
 
21
21
  ## Usage
22
22
 
@@ -115,7 +115,7 @@ Support associations is only `belongs_to` and simple `has_many`
115
115
 
116
116
  ## Contributing
117
117
 
118
- 1. Fork it ( https://github.com/[my-github-username]/activemodel-association/fork )
118
+ 1. Fork it ( https://github.com/[my-github-username]/activemodel-associations/fork )
119
119
  2. Create your feature branch (`git checkout -b my-new-feature`)
120
120
  3. Commit your changes (`git commit -am 'Add some feature'`)
121
121
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ 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).each do |gemfile|
9
+ %w(activerecord-40 activerecord-41 activerecord-412 activerecord-42 activerecord-master).each do |gemfile|
10
10
  desc "Run Tests by #{gemfile}.gemfile"
11
11
  task gemfile do
12
12
  sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
@@ -16,7 +16,7 @@ namespace :spec do
16
16
 
17
17
  desc "Run All Tests"
18
18
  task :all do
19
- %w(activerecord-40 activerecord-41 activerecord-412 activerecord-42).each do |gemfile|
19
+ %w(activerecord-40 activerecord-41 activerecord-412 activerecord-42 activerecord-master).each do |gemfile|
20
20
  Rake::Task["spec:#{gemfile}"].invoke
21
21
  end
22
22
  end
@@ -1,8 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", github: "rails/rails"
4
- gem "arel", github: "rails/arel"
5
- gem "activemodel", github: "rails/rails"
6
- gem "activesupport", github: "rails/rails"
3
+ gem "activerecord", "~> 4.2.0"
4
+ gem "activemodel", "~> 4.2.0"
5
+ gem "activesupport", "~> 4.2.0"
7
6
 
8
7
  gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", github: "rails/rails", branch: 'master'
4
+ gem "arel", github: "rails/arel", branch: 'master'
5
+ gem "activemodel", github: "rails/rails", branch: 'master'
6
+ gem "activesupport", github: "rails/rails", branch: 'master'
7
+ gem 'i18n', github: 'svenfuchs/i18n', branch: 'master'
8
+
9
+ gemspec :path => "../"
@@ -2,17 +2,6 @@ module ActiveModel::Associations
2
2
  module OverrideMethods
3
3
  extend ActiveSupport::Concern
4
4
 
5
- included do
6
- # borrow method definition from ActiveRecord::Inheritance
7
- # use in Rails internal
8
- mod = Module.new do
9
- unbound = ActiveRecord::Inheritance::ClassMethods.instance_method(:compute_type)
10
- define_method(:compute_type, unbound)
11
- protected :compute_type
12
- end
13
- extend mod
14
- end
15
-
16
5
  module ClassMethods
17
6
  def generated_association_methods
18
7
  @generated_association_methods ||= begin
@@ -33,6 +22,34 @@ module ActiveModel::Associations
33
22
  def pluralize_table_names
34
23
  self.to_s.pluralize
35
24
  end
25
+
26
+ protected
27
+
28
+ def compute_type(type_name)
29
+ if type_name.match(/^::/)
30
+ # If the type is prefixed with a scope operator then we assume that
31
+ # the type_name is an absolute reference.
32
+ ActiveSupport::Dependencies.constantize(type_name)
33
+ else
34
+ # Build a list of candidates to search for
35
+ candidates = []
36
+ name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
37
+ candidates << type_name
38
+
39
+ candidates.each do |candidate|
40
+ begin
41
+ constant = ActiveSupport::Dependencies.constantize(candidate)
42
+ return constant if candidate == constant.to_s
43
+ # We don't want to swallow NoMethodError < NameError errors
44
+ rescue NoMethodError
45
+ raise
46
+ rescue NameError
47
+ end
48
+ end
49
+
50
+ raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
51
+ end
52
+ end
36
53
  end
37
54
 
38
55
  # use by association accessor
@@ -55,6 +72,12 @@ module ActiveModel::Associations
55
72
  def read_attribute(name)
56
73
  send(name)
57
74
  end
75
+ alias :_read_attribute :read_attribute
76
+
77
+ # dummy
78
+ def new_record?
79
+ false
80
+ end
58
81
 
59
82
  private
60
83
 
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  module Associations
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -10,6 +10,15 @@ module ActiveRecord::Associations
10
10
  false
11
11
  end
12
12
 
13
+ # not support counter_cache
14
+ def empty?
15
+ if loaded?
16
+ size.zero?
17
+ else
18
+ @target.blank? && !scope.exists?
19
+ end
20
+ end
21
+
13
22
  # full replace simplely
14
23
  def replace(other_array)
15
24
  original_target = load_target.dup
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.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-28 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -211,6 +211,7 @@ files:
211
211
  - gemfiles/activerecord-41.gemfile
212
212
  - gemfiles/activerecord-412.gemfile
213
213
  - gemfiles/activerecord-42.gemfile
214
+ - gemfiles/activerecord-master.gemfile
214
215
  - lib/active_model/associations.rb
215
216
  - lib/active_model/associations/active_record_reflection.rb
216
217
  - lib/active_model/associations/association_scope_extension.rb
@@ -246,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
247
  version: '0'
247
248
  requirements: []
248
249
  rubyforge_project:
249
- rubygems_version: 2.2.2
250
+ rubygems_version: 2.4.5
250
251
  signing_key:
251
252
  specification_version: 4
252
253
  summary: ActiveRecord Association Helper for PORO (Plain Old Ruby Object)