Skip to content

Commit

Permalink
Dropped Rails < 3.1, added support for Rails 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
justinweiss committed Mar 6, 2012
1 parent 6ac328b commit a6bea27
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby-18mode # JRuby in 1.8 mode
- jruby-19mode # JRuby in 1.9 mode
- rbx-18mode
- rbx-19mode
env:
- RAILS_VERSION=3.0.0
- RAILS_VERSION=3.1.0
# Isn't compatible w / 3.2 yet
# - RAILS_VERSION=3.2.0
- RAILS_VERSION=3.2.0
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ PATH
remote: .
specs:
reactive_resource (0.6.1)
activeresource (~> 3.1.0, >= 3.0)
activesupport (~> 3.1.0, >= 3.0)
activeresource (>= 3.1)
activesupport (>= 3.1)

GEM
remote: http://rubygems.org/
specs:
activemodel (3.1.3)
activesupport (= 3.1.3)
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activeresource (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
activesupport (3.2.2)
i18n (~> 0.6)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
addressable (2.2.2)
builder (3.0.0)
Expand Down
26 changes: 14 additions & 12 deletions lib/reactive_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
require 'active_support/all'

module ReactiveResource

# The class that all ReactiveResourse resources should inherit
# from. This class fixes and patches over a lot of the broken stuff
# in Active Resource, and smoothes out the differences between the
# client-side Rails REST stuff and the server-side Rails REST stuff.
# It also adds support for ActiveRecord-like associations.
class Base < ActiveResource::Base
extend Extensions::RelativeConstGet
class_attribute :singleton_resource

# Call this method to transform a resource into a 'singleton'
# resource. This will fix the paths Active Resource generates for
# singleton resources. See
# https://rails.lighthouseapp.com/projects/8994/tickets/4348-supporting-singleton-resources-in-activeresource
# for more info.
def self.singleton
write_inheritable_attribute(:singleton, true)
self.singleton_resource = true
end

# +true+ if this resource is a singleton resource, +false+
# otherwise
def self.singleton?
read_inheritable_attribute(:singleton)
self.singleton_resource?
end

# Active Resource's find_one does nothing if you don't pass a
# +:from+ parameter. This doesn't make sense if you're dealing
# with a singleton resource, so if we don't get anything back from
Expand All @@ -38,7 +40,7 @@ def self.find_one(options)
end
found_object
end

# Override ActiveResource's +collection_name+ to support singular
# names for singleton resources.
def self.collection_name
Expand Down Expand Up @@ -76,7 +78,7 @@ def self.custom_method_collection_url(method_name, options = {})
def self.element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
element_path = "#{prefix(prefix_options)}#{association_prefix(prefix_options)}#{collection_name}"

# singleton resources don't have an ID
if id || !singleton?
element_path += "/#{id}"
Expand Down Expand Up @@ -122,7 +124,7 @@ def self.prefix_associations(options)
options = options.dup
used_associations = []
parent_associations = []

# Recurse to add the parent resource hierarchy. For Phone, for
# instance, this will add the '/lawyers/:id' part of the URL,
# which it knows about from the Address class.
Expand All @@ -133,7 +135,7 @@ def self.prefix_associations(options)

# The association chain we're following
used_association = nil

belongs_to_associations.each do |association|
if !used_association && param_value = options.delete("#{association.attribute}_id".intern) # only take the first one
used_associations << association
Expand All @@ -151,11 +153,11 @@ def self.prefix_associations(options)
def self.association_prefix(options)
options = options.dup
association_prefix = ''

if belongs_to_associations

used_associations = prefix_associations(options)

association_prefix = used_associations.map do |association|
collection_name = association.associated_class.collection_name
value = options.delete("#{association.attribute}_id".intern)
Expand All @@ -173,7 +175,7 @@ class << self
attr_accessor :associations
end
self.associations = []

# Add a has_one relationship to another class. +options+ is a hash
# of extra parameters:
#
Expand All @@ -183,7 +185,7 @@ class << self
def self.has_one(attribute, options = {})
self.associations << Association::HasOneAssociation.new(self, attribute, options)
end

# Add a has_many relationship to another class. +options+ is a hash
# of extra parameters:
#
Expand Down
2 changes: 1 addition & 1 deletion reactive_resource.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
rails_version = ENV.key?('RAILS_VERSION') ? "~> #{ENV['RAILS_VERSION']}" : ['>= 3.0', '~> 3.1.0']
rails_version = ENV.key?('RAILS_VERSION') ? "~> #{ENV['RAILS_VERSION']}" : '>= 3.1'
$:.push File.expand_path("../lib", __FILE__)
require "reactive_resource/version"

Expand Down

0 comments on commit a6bea27

Please sign in to comment.