Skip to content

Commit

Permalink
Support Rails 5 #310
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi-Cyuan Chen committed Sep 29, 2016
1 parent 15422c4 commit 6f6a784
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Expand Up @@ -12,12 +12,12 @@ language: ruby
rvm:
- "2.1"
- "2.3"
- "jruby-9.0.0.0"

gemfile:
- "gemfiles/rails_4.0.gemfile"
- "gemfiles/rails_4.1.gemfile"
- "gemfiles/rails_4.2.gemfile"
- "gemfiles/rails_5.0.gemfile"

env:
- CASSANDRA_VERSION: 2.1
Expand All @@ -26,3 +26,8 @@ env:
script: script/ci-unit-test

bundler_args: '--without=debug'

matrix:
exclude:
- rvm: 2.1
gemfile: gemfiles/rails_5.0.gemfile
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -15,3 +15,4 @@ end
gem 'racc', '~> 1.4', :platforms => :rbx
gem 'rubysl', '~> 2.0', :platforms => :rbx
gem 'psych', '~> 2.0', :platforms => :rbx
gem 'activemodel-serializers-xml'
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -24,6 +24,11 @@ Add it to your Gemfile:
gem 'cequel'
```

If you use Rails 5, add this:
``` ruby
gem 'activemodel-serializers-xml'
```

### Rails integration ###

Cequel does not require Rails, but if you are using Rails, you
Expand Down Expand Up @@ -572,7 +577,6 @@ the columns that are given.
### Ruby ###

* Ruby 2.3, 2.2, 2.1, 2.0
* JRuby 9.0

### Cassandra ###

Expand Down
2 changes: 1 addition & 1 deletion cequel.gemspec
Expand Up @@ -27,7 +27,7 @@ DESC
s.has_rdoc = true
s.extra_rdoc_files = 'README.md'
s.required_ruby_version = '>= 2.0'
s.add_runtime_dependency 'activemodel', '~> 4.0'
s.add_runtime_dependency 'activemodel', '>= 4.0'
s.add_runtime_dependency 'cassandra-driver', '~> 3.0'
s.add_development_dependency 'appraisal', '~> 1.0'
s.add_development_dependency 'wwtd', '~> 0.5'
Expand Down
21 changes: 21 additions & 0 deletions gemfiles/rails_5.0.gemfile
@@ -0,0 +1,21 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "racc", "~> 1.4", :platforms => :rbx
gem "rubysl", "~> 2.0", :platforms => :rbx
gem "psych", "~> 2.0", :platforms => :rbx
gem "activemodel", "~> 5.0.0"
gem 'activemodel-serializers-xml'

group :debug do
gem "debugger", "~> 1.6", :platforms => :mri_19
gem "byebug", "~> 2.7", :platforms => [:mri_20, :mri_21]
gem "pry", "~> 0.9"
end

group :development do
gem "rubocop", :require => nil
end

gemspec :path => "../"
9 changes: 5 additions & 4 deletions lib/cequel/instrumentation.rb
Expand Up @@ -37,16 +37,17 @@ def instrument(method_name, opts)

define_method(:"__data_for_#{method_name}_instrumentation", &data_proc)

module_eval <<-METH
def #{method_name}_with_instrumentation(*args)
mod = Module.new
mod.module_eval <<-METH
def #{method_name}(*args)
instrument("#{topic}",
__data_for_#{method_name}_instrumentation(self)) do
#{method_name}_without_instrumentation(*args)
super(*args)
end
end
METH

alias_method_chain method_name, "instrumentation"
prepend mod
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/cequel/record/validations.rb
Expand Up @@ -26,7 +26,7 @@ module Validations
included do
include ActiveModel::Validations
define_model_callbacks :validation
alias_method_chain :valid?, :callbacks
prepend Callback
end

#
Expand Down Expand Up @@ -80,11 +80,11 @@ def update_attributes!(attributes)
self.attributes = attributes
save!
end
end

private

def valid_with_callbacks?(context=nil)
run_callbacks(:validation) { valid_without_callbacks? context }
module Callback
def valid?(context=nil)
run_callbacks(:validation) { super context }
end
end
end
Expand Down

0 comments on commit 6f6a784

Please sign in to comment.