Skip to content

Commit

Permalink
Fix #27; use RDoc instead of kramdown
Browse files Browse the repository at this point in the history
This necessitated switching from tilde code blocks (~~~) to backtick
code blocks (```). I also switched from "rb" to "ruby" because RDoc
claims to only support "ruby".
  • Loading branch information
tfausak committed Jul 15, 2013
1 parent f65ea54 commit 8273810
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .yardopts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--readme=README.md
--no-private
--protected
--markup-provider=kramdown
--markup-provider=rdoc
--markup=markdown
-
LICENSE.txt
Expand Down
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ This project uses [semantic versioning][].

Add it to your Gemfile:

~~~ rb
```ruby
gem 'active_interaction', '~> 0.1.2'
~~~
```

And then execute:

~~~ sh
```sh
$ bundle
~~~
```

Or install it yourself as:

~~~ rb
```sh
$ gem install active_interaction
~~~
```

## What do I get?

Expand All @@ -44,7 +44,7 @@ want them in. If the options 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 looks at a simple example:

~~~ rb
```ruby
# Define an interaction that signs up a user.
class UserSignup < ActiveInteraction::Base
# required
Expand Down Expand Up @@ -81,7 +81,7 @@ def create
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
Expand All @@ -92,28 +92,28 @@ model.

There are two way to call an interaction. Given UserSignup, you can do this:

~~~ rb
```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:

~~~ rb
```ruby
result = UserSignup.run!(params)
# Either returns the result of execute,
# or raises ActiveInteraction::InteractionInvalid
~~~
```

## What can I pass to an interaction?

Interactions only accept a Hash for `run` and `run!`.

~~~ rb
```ruby
# A user comments on an article
class CreateComment < ActiveInteraction::Base
model :article, :user
Expand All @@ -131,21 +131,21 @@ def somewhere
user: current_user
)
end
~~~
```

## How do I define an interaction?

1. Subclass ActiveInteraction::Base

~~~ rb
```ruby
class YourInteraction < ActiveInteraction::Base
# ...
end
~~~
```

2. Define your attributes:

~~~ rb
```ruby
string :name, :state
integer :age
boolean :is_special
Expand All @@ -159,11 +159,11 @@ end
end
date :arrives_on, default: Date.today
date :departs_on, default: Date.tomorrow
~~~
```

3. Use any additional validations you need:

~~~ rb
```ruby
validates :name, length: {maximum: 10}
validates :state, inclusion: {in: %w(AL AK AR ... WY)}
validate arrives_before_departs
Expand All @@ -175,17 +175,17 @@ end
errors.add(:departs_on, 'must come after the arrival time')
end
end
~~~
```

4. Define your execute method. It can return whatever you like:

~~~ rb
```ruby
def execute
record = do_thing(...)
# ...
record
end
~~~
```

A full list of methods can be found [here](http://www.rubydoc.info/github/orgsync/active_interaction/master/ActiveInteraction/Base).

Expand Down
2 changes: 1 addition & 1 deletion active_interaction.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'coveralls', '~> 0.6'
spec.add_development_dependency 'guard-rspec', '~> 3.0'
spec.add_development_dependency 'kramdown', '~> 1.1'
spec.add_development_dependency 'rake', '~> 10.1'
spec.add_development_dependency 'rb-fsevent', '~> 0.9'
spec.add_development_dependency 'rdoc', '~> 4.0'
spec.add_development_dependency 'rspec', '~> 2.14'
spec.add_development_dependency 'yard', '~> 0.8'
end

0 comments on commit 8273810

Please sign in to comment.