From a1dfe632f85509e12e20ecd07a9a938307848234 Mon Sep 17 00:00:00 2001 From: Andrea Longhi Date: Fri, 5 Dec 2014 09:00:47 +0100 Subject: [PATCH 01/17] syntax highlight for ruby example code --- README.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 18cc26d1..9732d6d7 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ inputs are in the format you want them in. If the inputs are valid it will call `execute`, store the return value of that method in `result`, and return an instance of your ActiveInteraction::Base subclass. Let's look at a simple example: - +```ruby # Define an interaction that signs up a user. class UserSignup < ActiveInteraction::Base # required @@ -82,7 +82,7 @@ subclass. Let's look at a simple example: render action: :new end end - +``` You may have noticed that ActiveInteraction::Base quacks like ActiveRecord::Base. It can use validations from your Rails application and check option validity with `valid?`. Any errors are added to @@ -94,24 +94,24 @@ ActiveRecord is available. There are two way to call an interaction. Given UserSignup, you can do this: - +```ruby outcome = UserSignup.run(params) if outcome.valid? # Do something with outcome.result... else # Do something with outcome.errors... end - +``` Or, you can do this: - +```ruby result = UserSignup.run!(params) # Either returns the result of execute, # or raises ActiveInteraction::InvalidInteractionError - +``` ## What can I pass to an interaction? Interactions only accept a Hash for `run` and `run!`. - +```ruby # A user comments on an article class CreateComment < ActiveInteraction::Base model :article, :user @@ -129,17 +129,17 @@ Interactions only accept a Hash for `run` and `run!`. user: current_user ) end - +``` ## How do I define an interaction? 1. Subclass ActiveInteraction::Base - +```ruby class YourInteraction < ActiveInteraction::Base # ... end - +``` 2. Define your attributes: - +```ruby string :name, :state integer :age boolean :is_special @@ -153,9 +153,9 @@ Interactions only accept a Hash for `run` and `run!`. end date :arrives_on, default: -> { Date.current } date :departs_on, default: -> { Date.tomorrow } - +``` 3. Use any additional validations you need: - +```ruby validates :name, length: { maximum: 10 } validates :state, inclusion: { in: %w(AL AK AR ... WY) } validate :arrives_before_departs @@ -167,15 +167,15 @@ Interactions only accept a Hash for `run` and `run!`. errors.add(:departs_on, 'must come after the arrival time') end end - +``` 4. Define your execute method. It can return whatever you like: - +```ruby def execute record = do_thing(...) # ... record end - +``` Check out the [documentation][12] for a full list of methods. ## How do I compose interactions? @@ -184,7 +184,7 @@ You can run interactions from within other interactions by calling `compose`. If the interaction is successful, it'll return the result (just like if you had called it with `run!`). If something went wrong, execution will halt immediately and the errors will be moved onto the caller. - +```ruby class AddThree < ActiveInteraction::Base integer :x def execute @@ -193,17 +193,17 @@ immediately and the errors will be moved onto the caller. end AddThree.run!(x: 5) # => 8 - +``` To bring in filters from another interaction, use `import_filters`. Combined with `inputs`, delegating to another interaction is a piece of cake. - +```ruby class AddAndDouble < ActiveInteraction::Base import_filters Add def execute compose(Add, inputs) * 2 end end - +``` ## How do I translate an interaction? ActiveInteraction is i18n-aware out of the box! All you have to do @@ -211,7 +211,7 @@ is add translations to your project. In Rails, they typically go into `config/locales`. So, for example, let's say that (for whatever reason) you want to print out everything backwards. Simply add translations for ActiveInteraction to your `hsilgne` locale: - +```ruby # config/locales/hsilgne.yml hsilgne: active_interaction: @@ -233,9 +233,9 @@ translations for ActiveInteraction to your `hsilgne` locale: invalid: dilavni si invalid_type: '%{type} dilav a ton si' missing: deriuqer si - +``` Then set your locale and run an interaction like normal: - +```ruby I18n.locale = :hsilgne class Interaction < ActiveInteraction::Base boolean :a @@ -243,7 +243,7 @@ Then set your locale and run an interaction like normal: end p Interaction.run.errors.messages # => {:a=>["deriuqer si"]} - +``` ## Credits ActiveInteraction is brought to you by [@AaronLasseigne][14] and From 36bd26e7eaa86631309a7859347161b73955e2a7 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Tue, 9 Dec 2014 13:58:35 -0600 Subject: [PATCH 02/17] Update to rubysl 2.1 --- active_interaction.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_interaction.gemspec b/active_interaction.gemspec index e7b2c69d..463f6d78 100644 --- a/active_interaction.gemspec +++ b/active_interaction.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'parser', '~> 2.1' spec.add_development_dependency 'racc', '~> 1.4' spec.add_development_dependency 'rubinius-coverage', '~> 2.0' - spec.add_development_dependency 'rubysl', '~> 2.0' + spec.add_development_dependency 'rubysl', '~> 2.1' spec.add_development_dependency 'rubysl-test-unit', '~> 2.0' end end From 903ff51ebfc13729e8096eb38cc49ea5f5fd58b7 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Tue, 9 Dec 2014 14:02:25 -0600 Subject: [PATCH 03/17] Fix #235; prepend locales to i18n load path --- lib/active_interaction.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_interaction.rb b/lib/active_interaction.rb index 63db5c47..c89e10af 100644 --- a/lib/active_interaction.rb +++ b/lib/active_interaction.rb @@ -40,8 +40,8 @@ require 'active_interaction/backports' -I18n.load_path += Dir[File.expand_path( - File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))] +I18n.load_path.unshift(Dir[File.expand_path( + File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))]) # Manage application specific business logic. # From d8c5277edd7170accc2c0d6d95377daebac42c52 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Tue, 9 Dec 2014 14:14:49 -0600 Subject: [PATCH 04/17] Fix #233; treat ActiveRecord::Relation objects as arrays --- lib/active_interaction/filters/array_filter.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/active_interaction/filters/array_filter.rb b/lib/active_interaction/filters/array_filter.rb index 2b39f3f9..00d90945 100644 --- a/lib/active_interaction/filters/array_filter.rb +++ b/lib/active_interaction/filters/array_filter.rb @@ -1,5 +1,10 @@ # coding: utf-8 +begin + require 'active_record' +rescue LoadError +end + module ActiveInteraction class Base # @!method self.array(*attributes, options = {}, &block) @@ -29,7 +34,7 @@ class ArrayFilter < Filter def cast(value) case value - when Array + when *classes return value if filters.empty? filter = filters.values.first @@ -51,6 +56,17 @@ def method_missing(*, &block) private + # @return [Array] + def classes + result = [Array] + + if ActiveRecord.const_defined?(:Relation) + result.push(ActiveRecord::Relation) + end + + result + end + # @param filter [Filter] # @param names [Array] # From 5119de3dc383afad9ee3b9f2faf4793790cec009 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:11:54 -0600 Subject: [PATCH 05/17] Update to rubocop 0.28 --- active_interaction.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_interaction.gemspec b/active_interaction.gemspec index e7b2c69d..e616bdff 100644 --- a/active_interaction.gemspec +++ b/active_interaction.gemspec @@ -36,7 +36,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'kramdown', '~> 1.5' spec.add_development_dependency 'rake', '~> 10.3' spec.add_development_dependency 'rspec', '~> 3.1' - spec.add_development_dependency 'rubocop', '~> 0.27' + spec.add_development_dependency 'rubocop', '~> 0.28' spec.add_development_dependency 'yard', '~> 0.8' if RUBY_ENGINE == 'rbx' From b091c838f06342b0be1420be500468047ac3d174 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:26:06 -0600 Subject: [PATCH 06/17] Only run RuboCop on the latest MRI --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7bf54edc..5f78be04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ before_install: gem update bundler +env: RAKE_TASK=spec gemfile: - Gemfile - gemfiles/activemodel3.rb @@ -14,6 +15,9 @@ matrix: rvm: jruby - gemfile: gemfiles/activemodel3.rb rvm: rbx-2 + include: + - env: RAKE_TASK='spec rubocop' + rvm: 2.1 notifications: email: false hipchat: @@ -28,3 +32,4 @@ rvm: - 1.9 - jruby - rbx-2 +script: bundle exec rake $RAKE_TASK From 966435e1957360627c38b0eda1cc1741ef4d21e3 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:31:42 -0600 Subject: [PATCH 07/17] Fix whitespace --- README.md | 310 +++++++++++++++++++++++++++++------------------------- 1 file changed, 167 insertions(+), 143 deletions(-) diff --git a/README.md b/README.md index 317c7ab8..8af9280e 100644 --- a/README.md +++ b/README.md @@ -42,47 +42,49 @@ inputs are in the format you want them in. If the inputs are valid it will call `execute`, store the return value of that method in `result`, and return an instance of your ActiveInteraction::Base subclass. Let's look at a simple example: -```ruby - # Define an interaction that signs up a user. - class UserSignup < ActiveInteraction::Base - # required - string :email, :name - - # optional - boolean :newsletter_subscribe, default: nil - - # ActiveRecord validations - validates :email, format: EMAIL_REGEX - - # The execute method is called only if the inputs validate. It - # does your business action. The return value will be stored in - # `result`. - def execute - user = User.create!(email: email, name: name) - if newsletter_subscribe - NewsletterSubscriptions.create(email: email, user_id: user.id) - end - UserMailer.async(:deliver_welcome, user.id) - user - end - end - # In a controller action (for instance), you can run it: - def new - @signup = UserSignup.new - end - - def create - @signup = UserSignup.run(params[:user]) - - # Then check to see if it worked: - if @signup.valid? - redirect_to welcome_path(user_id: signup.result.id) - else - render action: :new - end +```ruby +# Define an interaction that signs up a user. +class UserSignup < ActiveInteraction::Base + # required + string :email, :name + + # optional + boolean :newsletter_subscribe, default: nil + + # ActiveRecord validations + validates :email, format: EMAIL_REGEX + + # The execute method is called only if the inputs validate. It + # does your business action. The return value will be stored in + # `result`. + def execute + user = User.create!(email: email, name: name) + if newsletter_subscribe + NewsletterSubscriptions.create(email: email, user_id: user.id) end + UserMailer.async(:deliver_welcome, user.id) + user + end +end + +# In a controller action (for instance), you can run it: +def new + @signup = UserSignup.new +end + +def create + @signup = UserSignup.run(params[:user]) + + # Then check to see if it worked: + if @signup.valid? + redirect_to welcome_path(user_id: signup.result.id) + else + render action: :new + end +end ``` + You may have noticed that ActiveInteraction::Base quacks like ActiveRecord::Base. It can use validations from your Rails application and check option validity with `valid?`. Any errors are added to @@ -94,88 +96,102 @@ ActiveRecord is available. There are two way to call an interaction. Given UserSignup, you can do this: + ```ruby - outcome = UserSignup.run(params) - if outcome.valid? - # Do something with outcome.result... - else - # Do something with outcome.errors... - end +outcome = UserSignup.run(params) +if outcome.valid? + # Do something with outcome.result... +else + # Do something with outcome.errors... +end ``` + Or, you can do this: + ```ruby - result = UserSignup.run!(params) - # Either returns the result of execute, - # or raises ActiveInteraction::InvalidInteractionError +result = UserSignup.run!(params) +# Either returns the result of execute, +# or raises ActiveInteraction::InvalidInteractionError ``` + ## What can I pass to an interaction? Interactions only accept a Hash for `run` and `run!`. + ```ruby - # A user comments on an article - class CreateComment < ActiveInteraction::Base - model :article, :user - string :comment +# A user comments on an article +class CreateComment < ActiveInteraction::Base + model :article, :user + string :comment + + validates :comment, length: { maximum: 500 } + + def execute; ...; end +end + +def somewhere + outcome = CreateComment.run( + comment: params[:comment], + article: Article.find(params[:article_id]), + user: current_user + ) +end +``` - validates :comment, length: { maximum: 500 } +## How do I define an interaction? - def execute; ...; end - end +1. Subclass ActiveInteraction::Base - def somewhere - outcome = CreateComment.run( - comment: params[:comment], - article: Article.find(params[:article_id]), - user: current_user - ) + ```ruby + class YourInteraction < ActiveInteraction::Base + # ... end -``` -## How do I define an interaction? + ``` -1. Subclass ActiveInteraction::Base -```ruby - class YourInteraction < ActiveInteraction::Base - # ... - end -``` 2. Define your attributes: -```ruby - string :name, :state - integer :age - boolean :is_special - model :account - array :tags, default: nil do - string - end - hash :prefs, default: nil do - boolean :smoking - boolean :view - end - date :arrives_on, default: -> { Date.current } - date :departs_on, default: -> { Date.tomorrow } -``` + + ```ruby + string :name, :state + integer :age + boolean :is_special + model :account + array :tags, default: nil do + string + end + hash :prefs, default: nil do + boolean :smoking + boolean :view + end + date :arrives_on, default: -> { Date.current } + date :departs_on, default: -> { Date.tomorrow } + ``` + 3. Use any additional validations you need: -```ruby - validates :name, length: { maximum: 10 } - validates :state, inclusion: { in: %w(AL AK AR ... WY) } - validate :arrives_before_departs - private + ```ruby + validates :name, length: { maximum: 10 } + validates :state, inclusion: { in: %w(AL AK AR ... WY) } + validate :arrives_before_departs + + private + + def arrive_before_departs + if departs_on <= arrives_on + errors.add(:departs_on, 'must come after the arrival time') + end + end + ``` - def arrive_before_departs - if departs_on <= arrives_on - errors.add(:departs_on, 'must come after the arrival time') - end - end -``` 4. Define your execute method. It can return whatever you like: -```ruby - def execute - record = do_thing(...) - # ... - record - end -``` + + ```ruby + def execute + record = do_thing(...) + # ... + record + end + ``` + Check out the [documentation][12] for a full list of methods. ## How do I compose interactions? @@ -184,26 +200,30 @@ You can run interactions from within other interactions by calling `compose`. If the interaction is successful, it'll return the result (just like if you had called it with `run!`). If something went wrong, execution will halt immediately and the errors will be moved onto the caller. + ```ruby - class AddThree < ActiveInteraction::Base - integer :x - def execute - compose(Add, x: x, y: 3) - end - end - AddThree.run!(x: 5) - # => 8 +class AddThree < ActiveInteraction::Base + integer :x + def execute + compose(Add, x: x, y: 3) + end +end +AddThree.run!(x: 5) +# => 8 ``` + To bring in filters from another interaction, use `import_filters`. Combined with `inputs`, delegating to another interaction is a piece of cake. + ```ruby - class AddAndDouble < ActiveInteraction::Base - import_filters Add - def execute - compose(Add, inputs) * 2 - end - end +class AddAndDouble < ActiveInteraction::Base + import_filters Add + def execute + compose(Add, inputs) * 2 + end +end ``` + ## How do I translate an interaction? ActiveInteraction is i18n-aware out of the box! All you have to do @@ -211,39 +231,43 @@ is add translations to your project. In Rails, they typically go into `config/locales`. So, for example, let's say that (for whatever reason) you want to print out everything backwards. Simply add translations for ActiveInteraction to your `hsilgne` locale: + ```ruby - # config/locales/hsilgne.yml - hsilgne: - active_interaction: - types: - array: yarra - boolean: naeloob - date: etad - date_time: emit etad - decimal: lamiced - file: elif - float: taolf - hash: hsah - integer: regetni - model: ledom - string: gnirts - time: emit - errors: - messages: - invalid: dilavni si - invalid_type: '%{type} dilav a ton si' - missing: deriuqer si +# config/locales/hsilgne.yml +hsilgne: + active_interaction: + types: + array: yarra + boolean: naeloob + date: etad + date_time: emit etad + decimal: lamiced + file: elif + float: taolf + hash: hsah + integer: regetni + model: ledom + string: gnirts + time: emit + errors: + messages: + invalid: dilavni si + invalid_type: '%{type} dilav a ton si' + missing: deriuqer si ``` + Then set your locale and run an interaction like normal: + ```ruby - I18n.locale = :hsilgne - class Interaction < ActiveInteraction::Base - boolean :a - def execute; end - end - p Interaction.run.errors.messages - # => {:a=>["deriuqer si"]} +I18n.locale = :hsilgne +class Interaction < ActiveInteraction::Base + boolean :a + def execute; end +end +p Interaction.run.errors.messages +# => {:a=>["deriuqer si"]} ``` + ## Credits ActiveInteraction is brought to you by [@AaronLasseigne][14] and From f06bec58c71a177502d2610b00918091abdbbc69 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:32:19 -0600 Subject: [PATCH 08/17] Add syntax highlighting to other bits of code --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8af9280e..956a39a9 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,21 @@ This project uses [semantic versioning][13]. Add it to your Gemfile: - gem 'active_interaction', '~> 1.3' +``` ruby +gem 'active_interaction', '~> 1.3' +``` And then execute: - $ bundle +``` sh +$ bundle +``` Or install it yourself with: - $ gem install active_interaction +``` sh +$ gem install active_interaction +``` ## What do I get? From dea1d309df75212d2e76ffe2147bb1844c610180 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:37:58 -0600 Subject: [PATCH 09/17] Remove obsolete option travis-ci/travis-build#346 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f78be04..efa3ca57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ env: RAKE_TASK=spec gemfile: - Gemfile - gemfiles/activemodel3.rb -install: bundle install --jobs=1 # rubygems/rubygems#982 language: ruby matrix: exclude: From d33c986494a66d6783089dacc3c4ea50792e5995 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:39:50 -0600 Subject: [PATCH 10/17] Construct matrix through inclusion --- .travis.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index efa3ca57..d30698a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,12 @@ before_install: gem update bundler env: RAKE_TASK=spec -gemfile: -- Gemfile -- gemfiles/activemodel3.rb language: ruby matrix: - exclude: - - gemfile: gemfiles/activemodel3.rb - rvm: 2.0 - - gemfile: gemfiles/activemodel3.rb - rvm: 1.9 - - gemfile: gemfiles/activemodel3.rb - rvm: jruby - - gemfile: gemfiles/activemodel3.rb - rvm: rbx-2 include: - env: RAKE_TASK='spec rubocop' rvm: 2.1 + - gemfile: gemfiles/activemodel3.rb + rvm: 2.1 notifications: email: false hipchat: From 13962157b61e9623b13a0e3ef4d87ba94b97bc0c Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:52:09 -0600 Subject: [PATCH 11/17] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5fa1a50..59290d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Fixed +- [#235][]: Fix a bug that prevented custom translations from loading. - [#224][]: Fix a bug that incorrectly inferred plural class names for filters inside arrays. @@ -461,3 +462,4 @@ [#206]: https://github.com/orgsync/active_interaction/issues/206 [#207]: https://github.com/orgsync/active_interaction/issues/207 [#224]: https://github.com/orgsync/active_interaction/issues/224 + [#235]: https://github.com/orgsync/active_interaction/issues/235 From 05c51c0ce325287857ab3b6d893e058662f12f46 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 15:56:57 -0600 Subject: [PATCH 12/17] Run RuboCop by itself There's no reason to re-run the specs. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d30698a6..f89b8170 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ env: RAKE_TASK=spec language: ruby matrix: include: - - env: RAKE_TASK='spec rubocop' + - env: RAKE_TASK=rubocop rvm: 2.1 - gemfile: gemfiles/activemodel3.rb rvm: 2.1 From 058acf9e02f4383580a7d542d8d5e382e0855c06 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 16:02:08 -0600 Subject: [PATCH 13/17] Bump version to 1.3.1 --- CHANGELOG.md | 5 ++++- lib/active_interaction.rb | 2 +- lib/active_interaction/version.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59290d1e..19b7686c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Master][] +# [1.3.1][] (2014-12-10) + ## Fixed - [#235][]: Fix a bug that prevented custom translations from loading. @@ -352,7 +354,8 @@ - Initial release. - [master]: https://github.com/orgsync/active_interaction/compare/v1.3.0...master + [master]: https://github.com/orgsync/active_interaction/compare/v1.3.1...master + [1.3.1]: https://github.com/orgsync/active_interaction/compare/v1.3.0...v1.3.1 [1.3.0]: https://github.com/orgsync/active_interaction/compare/v1.2.5...v1.3.0 [1.2.5]: https://github.com/orgsync/active_interaction/compare/v1.2.4...v1.2.5 [1.2.4]: https://github.com/orgsync/active_interaction/compare/v1.2.3...v1.2.4 diff --git a/lib/active_interaction.rb b/lib/active_interaction.rb index c89e10af..f7fef247 100644 --- a/lib/active_interaction.rb +++ b/lib/active_interaction.rb @@ -50,5 +50,5 @@ # # @since 1.0.0 # -# @version 1.3.0 +# @version 1.3.1 module ActiveInteraction end diff --git a/lib/active_interaction/version.rb b/lib/active_interaction/version.rb index 4bde3cf8..ec5b52df 100644 --- a/lib/active_interaction/version.rb +++ b/lib/active_interaction/version.rb @@ -5,5 +5,5 @@ module ActiveInteraction # The version number. # # @return [Gem::Version] - VERSION = Gem::Version.new('1.3.0') + VERSION = Gem::Version.new('1.3.1') end From 9fdd70a603f1687891584b143b05eacf90eb32de Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 16:11:23 -0600 Subject: [PATCH 14/17] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19b7686c..9371428c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # [Master][] +## Changed + +- [#239][]: Accept `ActiveRecord::Relation` objects as `array` inputs. + # [1.3.1][] (2014-12-10) ## Fixed @@ -466,3 +470,4 @@ [#207]: https://github.com/orgsync/active_interaction/issues/207 [#224]: https://github.com/orgsync/active_interaction/issues/224 [#235]: https://github.com/orgsync/active_interaction/issues/235 + [#239]: https://github.com/orgsync/active_interaction/issues/239 From 9d415a2cb31917f5c6ce934f6454257df62e8351 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 16:12:31 -0600 Subject: [PATCH 15/17] Bump version to 1.4.0 --- CHANGELOG.md | 5 ++++- README.md | 2 +- lib/active_interaction.rb | 2 +- lib/active_interaction/version.rb | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9371428c..40daad35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Master][] +# [1.4.0][] (2014-12-10) + ## Changed - [#239][]: Accept `ActiveRecord::Relation` objects as `array` inputs. @@ -358,7 +360,8 @@ - Initial release. - [master]: https://github.com/orgsync/active_interaction/compare/v1.3.1...master + [master]: https://github.com/orgsync/active_interaction/compare/v1.4.0...master + [1.4.0]: https://github.com/orgsync/active_interaction/compare/v1.3.1...v1.4.0 [1.3.1]: https://github.com/orgsync/active_interaction/compare/v1.3.0...v1.3.1 [1.3.0]: https://github.com/orgsync/active_interaction/compare/v1.2.5...v1.3.0 [1.2.5]: https://github.com/orgsync/active_interaction/compare/v1.2.4...v1.2.5 diff --git a/README.md b/README.md index 956a39a9..63127186 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This project uses [semantic versioning][13]. Add it to your Gemfile: ``` ruby -gem 'active_interaction', '~> 1.3' +gem 'active_interaction', '~> 1.4' ``` And then execute: diff --git a/lib/active_interaction.rb b/lib/active_interaction.rb index f7fef247..6298f9e7 100644 --- a/lib/active_interaction.rb +++ b/lib/active_interaction.rb @@ -50,5 +50,5 @@ # # @since 1.0.0 # -# @version 1.3.1 +# @version 1.4.0 module ActiveInteraction end diff --git a/lib/active_interaction/version.rb b/lib/active_interaction/version.rb index ec5b52df..ba2cad97 100644 --- a/lib/active_interaction/version.rb +++ b/lib/active_interaction/version.rb @@ -5,5 +5,5 @@ module ActiveInteraction # The version number. # # @return [Gem::Version] - VERSION = Gem::Version.new('1.3.1') + VERSION = Gem::Version.new('1.4.0') end From 4ac7497d57382a187f66be2e55360fef107351e5 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 16:19:44 -0600 Subject: [PATCH 16/17] That's YAML, not Ruby --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63127186..576752ce 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ into `config/locales`. So, for example, let's say that (for whatever reason) you want to print out everything backwards. Simply add translations for ActiveInteraction to your `hsilgne` locale: -```ruby +```yaml # config/locales/hsilgne.yml hsilgne: active_interaction: From 4d0ebe3ac9363597e09147d2984bb4721e6146b1 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 10 Dec 2014 16:20:26 -0600 Subject: [PATCH 17/17] Put a space between code fence blocks and the syntax name --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 576752ce..620cdb68 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ it will call `execute`, store the return value of that method in `result`, and return an instance of your ActiveInteraction::Base subclass. Let's look at a simple example: -```ruby +``` ruby # Define an interaction that signs up a user. class UserSignup < ActiveInteraction::Base # required @@ -103,7 +103,7 @@ ActiveRecord is available. There are two way to call an interaction. Given UserSignup, you can do this: -```ruby +``` ruby outcome = UserSignup.run(params) if outcome.valid? # Do something with outcome.result... @@ -114,7 +114,7 @@ end Or, you can do this: -```ruby +``` ruby result = UserSignup.run!(params) # Either returns the result of execute, # or raises ActiveInteraction::InvalidInteractionError @@ -124,7 +124,7 @@ result = UserSignup.run!(params) Interactions only accept a Hash for `run` and `run!`. -```ruby +``` ruby # A user comments on an article class CreateComment < ActiveInteraction::Base model :article, :user @@ -148,7 +148,7 @@ end 1. Subclass ActiveInteraction::Base - ```ruby + ``` ruby class YourInteraction < ActiveInteraction::Base # ... end @@ -156,7 +156,7 @@ end 2. Define your attributes: - ```ruby + ``` ruby string :name, :state integer :age boolean :is_special @@ -174,7 +174,7 @@ end 3. Use any additional validations you need: - ```ruby + ``` ruby validates :name, length: { maximum: 10 } validates :state, inclusion: { in: %w(AL AK AR ... WY) } validate :arrives_before_departs @@ -190,7 +190,7 @@ end 4. Define your execute method. It can return whatever you like: - ```ruby + ``` ruby def execute record = do_thing(...) # ... @@ -207,7 +207,7 @@ If the interaction is successful, it'll return the result (just like if you had called it with `run!`). If something went wrong, execution will halt immediately and the errors will be moved onto the caller. -```ruby +``` ruby class AddThree < ActiveInteraction::Base integer :x def execute @@ -221,7 +221,7 @@ AddThree.run!(x: 5) To bring in filters from another interaction, use `import_filters`. Combined with `inputs`, delegating to another interaction is a piece of cake. -```ruby +``` ruby class AddAndDouble < ActiveInteraction::Base import_filters Add def execute @@ -238,7 +238,7 @@ into `config/locales`. So, for example, let's say that (for whatever reason) you want to print out everything backwards. Simply add translations for ActiveInteraction to your `hsilgne` locale: -```yaml +``` yaml # config/locales/hsilgne.yml hsilgne: active_interaction: @@ -264,7 +264,7 @@ hsilgne: Then set your locale and run an interaction like normal: -```ruby +``` ruby I18n.locale = :hsilgne class Interaction < ActiveInteraction::Base boolean :a