Skip to content
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

Set attributes in initializer through <attribute>= so it can be overridden w/ a setter. #137

Merged
merged 2 commits into from
Oct 25, 2015

Conversation

bvandenbos
Copy link
Contributor

By settings attributes via method_missing (instead of set_attribute) we can define custom setters in the resource classes and not have those fields hit the server.

class Person < JsonApiClient::Resource
  attr_accessor :my_field
  # ...
end

person = Person.new(name: "Ben", my_field: "Blah")
person.save # => my_field is not passed to the server

Also, adding support for validation contexts: on: :create and on: :update.

class Person < JsonApiClient::Resource
  validates :first_name, presence: true, on: :create
end

chingor13 added a commit that referenced this pull request Oct 25, 2015
Set attributes in initializer through <attribute>= so it can be overridden w/ a setter.
@chingor13 chingor13 merged commit 1c221df into JsonApiClient:master Oct 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants