Skip to content

Commit

Permalink
Merge branch 'master' into v1.3.0
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG.md
  • Loading branch information
tfausak committed May 20, 2014
2 parents bfc7a49 + 28086a8 commit d342df6
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AlignParameters:
EnforcedStyle: with_fixed_indentation
AllCops:
Exclude:
- tmp/*
- tmp/**/*
HandleExceptions:
Enabled: false
NonNilCheck:
Expand Down
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
before_install: gem update bundler
gemfiles:
gemfile:
- Gemfile
- gemfiles/activemodel3.rb
language: ruby
Expand All @@ -12,8 +12,8 @@ notifications:
ivR5nEELqEsDgDZAcKGJtRgp70d6Geg5iFUfV9aP1ySy2U0AXBM='
rvm:
- 2.1.1
- 2.0.0
- 1.9.3
- 2.1
- 2.0
- 1.9
- jruby
- rbx
- rbx-2
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# [Master][]

- Add an interface filter.

# [1.2.3][] (2014-05-12)

- Fix a bug that raised `ActiveRecord::Rollback` when composing even when not
in a transaction.

# [1.2.2][] (2014-05-07)

- Fix a bug that raised `NameError`s when there were invalid nested hash
errors.
- Add missing translation for symbol filters.

# [1.2.1][] (2014-05-02)
Expand Down Expand Up @@ -202,7 +212,9 @@

- Initial release.

[master]: https://github.com/orgsync/active_interaction/compare/v1.2.1...master
[master]: https://github.com/orgsync/active_interaction/compare/v1.2.3...master
[1.2.3]: https://github.com/orgsync/active_interaction/compare/v1.2.2...v1.2.3
[1.2.2]: https://github.com/orgsync/active_interaction/compare/v1.2.1...v1.2.2
[1.2.1]: https://github.com/orgsync/active_interaction/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/orgsync/active_interaction/compare/v1.1.7...v1.2.0
[1.1.7]: https://github.com/orgsync/active_interaction/compare/v1.1.6...v1.1.7
Expand Down
20 changes: 10 additions & 10 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Vagrant 1.5.4 <http://www.vagrantup.com/downloads.html>
# VirtualBox 4.3.10 <https://www.virtualbox.org/wiki/Downloads>
# Vagrant 1.6.2 <http://www.vagrantup.com/downloads.html>
# VirtualBox 4.3.12 <https://www.virtualbox.org/wiki/Downloads>

Vagrant.require_version '~> 1.5'

Expand All @@ -13,14 +13,14 @@ Vagrant.configure('2') do |config|
set -e -x
apt-get update
apt-get install --assume-yes libffi-dev make
if ! ruby --version | grep --fixed-strings 2.1.1p76; then
test -f ruby-2.1.1.tar.bz2 ||
wget cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.bz2
test -f ruby-2.1.1.tar ||
bunzip2 --keep ruby-2.1.1.tar.bz2
test -d ruby-2.1.1 ||
tar --extract --file ruby-2.1.1.tar
cd ruby-2.1.1
if ! ruby --version | grep --fixed-strings 2.1.2; then
test -f ruby-2.1.2.tar.bz2 ||
wget cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2
test -f ruby-2.1.2.tar ||
bunzip2 --keep ruby-2.1.2.tar.bz2
test -d ruby-2.1.2 ||
tar --extract --file ruby-2.1.2.tar
cd ruby-2.1.2
./configure --disable-install-doc
make
make install
Expand Down
2 changes: 1 addition & 1 deletion active_interaction.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
# Dependencies
spec.required_ruby_version = '>= 1.9.3'

spec.add_dependency 'activemodel', '>= 3', '< 5'
spec.add_dependency 'activemodel', '>= 3.2', '< 5'

spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'coveralls', '~> 0.7'
Expand Down
7 changes: 4 additions & 3 deletions lib/active_interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@

require 'active_interaction/backports'

I18n.load_path << File.expand_path(
File.join(%w[active_interaction locale en.yml]), File.dirname(__FILE__))
I18n.load_path += Dir[File.expand_path(
File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))]
I18n.default_locale = :en

# Manage application specific business logic.
#
Expand All @@ -50,5 +51,5 @@
#
# @since 1.0.0
#
# @version 1.2.1
# @version 1.2.3
module ActiveInteraction end
7 changes: 6 additions & 1 deletion lib/active_interaction/backports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ def []=(name, value)
send("#{name}=", value)
end unless method_defined?(:[]=)
end

class Errors
# Required for Rails < 3.2.13.
protected :initialize_dup
end
end

# @private
class Hash
# Required for Rails <= 4.0.2.
# Required for Rails < 4.0.0.
def transform_keys
result = {}
each_key do |key|
Expand Down
2 changes: 1 addition & 1 deletion lib/active_interaction/concerns/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def run
rescue Interrupt => interrupt
merge_errors_onto_base(interrupt.outcome.errors)

raise ActiveRecord::Rollback
raise ActiveRecord::Rollback if self.class.transaction?
end
end
end
Expand Down
38 changes: 8 additions & 30 deletions lib/active_interaction/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ module ActiveInteraction

# Describes an input filter for an interaction.
class Filter
# @return [Regexp]
CLASS_REGEXP = /\AActiveInteraction::([A-Z]\w*)Filter\z/
private_constant :CLASS_REGEXP

# @return [Hash{Symbol => Class}]
CLASSES = {}
private_constant :CLASSES
Expand All @@ -32,6 +28,9 @@ class Filter
undef_method :hash

class << self
# @return [Symbol]
attr_reader :slug

# Get the filter associated with a symbol.
#
# @example
Expand All @@ -52,35 +51,14 @@ def factory(slug)
CLASSES.fetch(slug) { fail MissingFilterError, slug.inspect }
end

# Convert the class name into a short symbol.
#
# @example
# ActiveInteraction::BooleanFilter.slug
# # => :boolean
# @example
# ActiveInteraction::Filter.slug
# # => ActiveInteraction::InvalidClassError: ActiveInteraction::Filter
#
# @return [Symbol]
#
# @raise [InvalidClassError] If the filter doesn't have a valid slug.
#
# @see .factory
def slug
return @slug if defined?(@slug)

match = name[CLASS_REGEXP, 1]
fail InvalidClassError, name unless match
@slug = match.underscore.to_sym
end
private

# @param slug [Symbol]
# @param klass [Class]
#
# @private
def inherited(klass)
CLASSES[klass.slug] = klass
rescue InvalidClassError
CLASSES[klass.name.to_sym] = klass
# @return [Class]
def register(slug)
CLASSES[@slug = slug] = self
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_interaction/filters/abstract_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AbstractFilter < Filter

# @return [Class]
def klass
@klass ||= self.class.slug.to_s.camelize.constantize
@klass ||= Object.const_get(self.class.slug.to_s.camelize, false)
end
end
end
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/array_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Base
class ArrayFilter < Filter
include Missable

register :array

def cast(value)
case value
when Array
Expand Down
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/boolean_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Base

# @private
class BooleanFilter < Filter
register :boolean

def cast(value)
case value
when FalseClass, '0', /\Afalse\z/i
Expand Down
1 change: 1 addition & 0 deletions lib/active_interaction/filters/date_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ class Base

# @private
class DateFilter < AbstractDateTimeFilter
register :date
end
end
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/date_time_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Base

# @private
class DateTimeFilter < AbstractDateTimeFilter
register :date_time

def database_column_type
:datetime
end
Expand Down
4 changes: 4 additions & 0 deletions lib/active_interaction/filters/decimal_filter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding: utf-8

require 'bigdecimal'

module ActiveInteraction
class Base
# @!method self.decimal(*attributes, options = {})
Expand All @@ -17,6 +19,8 @@ class Base

# @private
class DecimalFilter < AbstractNumericFilter
register :decimal

def cast(value)
case value
when Numeric
Expand Down
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/file_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Base

# @private
class FileFilter < Filter
register :file

def cast(value)
value = extract_file(value)

Expand Down
1 change: 1 addition & 0 deletions lib/active_interaction/filters/float_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class Base

# @private
class FloatFilter < AbstractNumericFilter
register :float
end
end
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/hash_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Base
class HashFilter < Filter
include Missable

register :hash

def cast(value)
case value
when Hash
Expand Down
1 change: 1 addition & 0 deletions lib/active_interaction/filters/integer_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class Base

# @private
class IntegerFilter < AbstractNumericFilter
register :integer
end
end
4 changes: 3 additions & 1 deletion lib/active_interaction/filters/model_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Base

# @private
class ModelFilter < Filter
register :model

def cast(value, reconstantize = true)
@klass ||= klass

Expand All @@ -38,7 +40,7 @@ def cast(value, reconstantize = true)
# @raise [InvalidClassError]
def klass
klass_name = options.fetch(:class, name).to_s.classify
klass_name.constantize
Object.const_get(klass_name)
rescue NameError
raise InvalidClassError, klass_name.inspect
end
Expand Down
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/string_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Base

# @private
class StringFilter < Filter
register :string

def cast(value)
case value
when String
Expand Down
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/symbol_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Base

# @private
class SymbolFilter < Filter
register :symbol

def cast(value)
case value
when Symbol
Expand Down
2 changes: 2 additions & 0 deletions lib/active_interaction/filters/time_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Base

# @private
class TimeFilter < AbstractDateTimeFilter
register :time

alias_method :_klass, :klass
private :_klass

Expand Down
2 changes: 1 addition & 1 deletion lib/active_interaction/modules/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def error_args(filter, error)
case error
when InvalidNestedValueError
[filter.name, :invalid_nested, nil,
name: e.filter_name.inspect, value: e.input_value.inspect]
name: error.filter_name.inspect, value: error.input_value.inspect]
when InvalidValueError
[filter.name, :invalid_type, nil, type: type(filter)]
when MissingValueError
Expand Down
2 changes: 1 addition & 1 deletion lib/active_interaction/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ module ActiveInteraction
# The version number.
#
# @return [Gem::Version]
VERSION = Gem::Version.new('1.2.1')
VERSION = Gem::Version.new('1.2.3')
end
Loading

0 comments on commit d342df6

Please sign in to comment.