Skip to content

Enforce Ruby style with Rubocop. #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
AllCops:
Excludes:
- vendor/**

LineLength:
Enabled: false

MethodLength:
Enabled: false

ClassLength:
Enabled: false

Documentation:
# don't require classes to be documented
Enabled: false

CollectionMethods:
# don't prefer map to collect, recuce to inject
Enabled: false

Encoding:
# no need to always specify encoding
Enabled: false

HashMethods:
# key? instead of has_key?
# value? instead of has_value?
Enabled: false

StringLiterals:
# use single or double-quoted strings, as you please
Enabled: false

Void:
# == operator used in void context in specs
Enabled: false

SignalException:
# prefer raise to fail
EnforcedStyle: only_raise

RaiseArgs:
# don't care for what kind of raise
Enabled: false

PerlBackrefs:
# TODO: regular expression matching with $1, $2, etc.
Enabled: false

BlockNesting:
# TODO: fix too much nesting
Max: 4

Lambda:
# TODO: replace all lambda with -> or Proc
Enabled: false

Blocks:
# allow multi-line blocks like expect { }
Enabled: false

WordArray:
# %w vs. [ '', ... ]
Enabled: false
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
language: ruby
cache: bundler
rvm:
- 2.0.0
- 1.9.3
- jruby-19mode
- rbx-19mode
script:
- "bundle exec rubocop"
- "bundle exec rake"
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
Next Release
============
* Ruby 1.8.x is no longer supported - [@dblock](https://github.com/dblock).
* [#7](https://github.com/intridea/grape-entity/issues/7): Add `serializable` option to `represent` - [@mbleigh](https://github.com/mbleigh).
* [#18](https://github.com/intridea/grape-entity/pull/18): Add `safe` option to `expose`, will not raise error for a missing attribute - [@fixme](https://github.com/fixme).
* [#16](https://github.com/intridea/grape-entity/pull/16): Add `using` option to `expose SYMBOL BLOCK` - [@fahchen](https://github.com/fahchen).
* [#36](https://github.com/intridea/grape-entity/pull/35): Enforcing Ruby style guidelines via Rubocop - [@dblock](https://github.com/dblock).
* [#7](https://github.com/intridea/grape-entity/issues/7): Added `serializable` option to `represent` - [@mbleigh](https://github.com/mbleigh).
* [#18](https://github.com/intridea/grape-entity/pull/18): Added `safe` option to `expose`, will not raise error for a missing attribute - [@fixme](https://github.com/fixme).
* [#16](https://github.com/intridea/grape-entity/pull/16): Added `using` option to `expose SYMBOL BLOCK` - [@fahchen](https://github.com/fahchen).
* [#24](https://github.com/intridea/grape-entity/pull/24): Return documentation with `as` param considered - [@drakula2k](https://github.com/drakula2k).
* [#27](https://github.com/intridea/grape-entity/pull/27): Properly serializing hashes - [@clintonb](https://github.com/clintonb).
* [#28](https://github.com/intridea/grape-entity/pull/28): Look for method on entity before calling on the object - [@MichaelXavier](https://github.com/MichaelXavier).
* [#27](https://github.com/intridea/grape-entity/pull/27): Properly serialize hashes - [@clintonb](https://github.com/clintonb).
* [#28](https://github.com/intridea/grape-entity/pull/28): Look for method on entity before calling it on the object - [@MichaelXavier](https://github.com/MichaelXavier).
* [#33](https://github.com/intridea/grape-entity/pull/33): Support proper merging of nested conditionals - [@wyattisimo](https://github.com/wyattisimo).
* Your contribution here.

0.3.0 (2013-03-29)
==================

* [#9](https://github.com/intridea/grape-entity/pull/9): Adds `with_options` for block-level exposure setting - [@SegFaultAX](https://github.com/SegFaultAX).
* [#9](https://github.com/intridea/grape-entity/pull/9): Added `with_options` for block-level exposure setting - [@SegFaultAX](https://github.com/SegFaultAX).
* The `instance.entity` method now optionally accepts `options` - [@mbleigh](https://github.com/mbleigh).
* You can pass symbols to `:if` and `:unless` to simply check for truthiness/falsiness of the specified options key - [@mbleigh](https://github.com/mbleigh).

0.2.0 (2013-01-11)
==================

* Moved the namespace back to Grape::Entity to preserve compatibility with Grape - [@dblock](https://github.com/dblock).
* Moved the namespace back to `Grape::Entity` to preserve compatibility with Grape - [@dblock](https://github.com/dblock).

0.1.0 (2013-01-11)
==================
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ group :development, :test do
gem 'rspec'
gem 'rack-test', "~> 0.6.2", :require => "rack/test"
gem 'github-markup'
gem 'rubocop', '~> 0.14.1'
end
1 change: 0 additions & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ guard 'rspec', :version => 2 do
watch('spec/spec_helper.rb') { "spec/" }
end


guard 'bundler' do
watch('Gemfile')
watch(/^.+\.gemspec/)
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Any additional options defined on the entity exposure are included as is. In the

```ruby
class Status < Grape::Entity
expose :user, :if => lambda { |instance, options| options[:user] } do |instance, options|
expose :user, if: lambda { |instance, options| options[:user] } do |instance, options|
# examine available environment keys with `p options[:env].keys`
options[:user]
end
Expand Down Expand Up @@ -193,7 +193,7 @@ module API
version 'v1'

desc 'Statuses.', {
:object_fields => API::Entities::Status.documentation
object_fields: API::Entities::Status.documentation
}
get '/statuses' do
statuses = Status.all
Expand Down Expand Up @@ -230,8 +230,8 @@ Entities with duplicate exposure names and conditions will silently overwrite on
module API
module Entities
class Status < Grape::Entity
expose :field_a, :foo, :if => lambda { |object, options| object.check == "foo" }
expose :field_b, :foo, :if => lambda { |object, options| object.check == "bar" }
expose :field_a, :foo, if: lambda { |object, options| object.check == "foo" }
expose :field_b, :foo, if: lambda { |object, options| object.check == "bar" }
end
end
end
Expand All @@ -243,9 +243,9 @@ This can be problematic, when you have mixed collections. Using `respond_to?` is
module API
module Entities
class Status < Grape::Entity
expose :field_a, :if => lambda { |object, options| object.check == "foo" }
expose :field_b, :if => lambda { |object, options| object.check == "bar" }
expose :foo, :if => lambda { |object, options| object.respond_to?(:foo) }
expose :field_a, if: lambda { |object, options| object.check == "foo" }
expose :field_b, if: lambda { |object, options| object.check == "bar" }
expose :foo, if: lambda { |object, options| object.respond_to?(:foo) }
end
end
end
Expand Down Expand Up @@ -273,11 +273,12 @@ Also see [Grape Entity Matchers](https://github.com/agileanimal/grape-entity-mat

## Contributing

1. Fork it
1. Fork the project
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Write tests. Make changes. Run `rubocop`.
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
5. Create a new pull request

## License

Expand Down
2 changes: 1 addition & 1 deletion lib/grape-entity.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require 'grape_entity'
require 'grape_entity'
2 changes: 1 addition & 1 deletion lib/grape_entity.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require "grape_entity/version"
require "grape_entity/entity"
require "grape_entity/entity"
Loading