-
Notifications
You must be signed in to change notification settings - Fork 10
Fix/person question sets array #23
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
Changes from all commits
9911cf2
0e68afa
760433a
553c52b
223a8a5
bdc3c82
db03f71
089e5db
0cd4706
6ccdac4
4102fa3
153a26f
b546473
68a8968
f43d11f
a4dd8e1
fc05a5b
999a725
969e450
59b6a29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,37 @@ module BlockScore | |
| class Base | ||
| extend Connection | ||
|
|
||
| attr_reader :attributes | ||
|
|
||
| def initialize(options = {}) | ||
| def initialize(options = {}, &block) | ||
| @loaded = !(block) | ||
| @proc = block | ||
| @attributes = options | ||
| end | ||
|
|
||
| def attributes | ||
| return @attributes if @loaded | ||
| force! | ||
| @attributes | ||
| end | ||
|
|
||
| def force! | ||
| res = @proc.call | ||
| @attributes = res.attributes.merge(@attributes) | ||
| @loaded = true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/MethodCallParentheses: Do not use parentheses for method calls with no arguments. |
||
| self | ||
| end | ||
|
|
||
| def id | ||
| @attributes.fetch(:id, nil) | ||
| end | ||
|
|
||
| def inspect | ||
| "#<#{self.class}:0x#{object_id.to_s(16)} JSON: " + JSON.pretty_generate(attributes) | ||
| str_attr = "JSON:#{JSON.pretty_generate(attributes)}" | ||
| "#<#{self.class}:0x#{object_id.to_s(16)} #{str_attr}>" | ||
| end | ||
|
|
||
| def refresh | ||
| r = self.class.retrieve(id) | ||
| @attributes = r.attributes | ||
| res = self.class.retrieve(id) | ||
| @attributes = res.attributes | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you didn't write this part but these two lines could likely just be one, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that looks good |
||
|
|
||
| true | ||
| rescue Error | ||
|
|
@@ -31,6 +49,7 @@ def save | |
|
|
||
| def save! | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While looking at this I noticed the other save method has a bare rescue which means it just swallows up ALL errors: def save
save!
rescue
false
endI thought I caught this back when the gem was first released but I guess not. Would you mind fixing that and double checking this isn't done elsewhere in the lib? |
||
| response = self.class.post(self.class.endpoint, attributes) | ||
| # binding.pry | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pry |
||
| @attributes = response.attributes | ||
|
|
||
| true | ||
|
|
@@ -45,16 +64,18 @@ def self.api_url | |
| end | ||
|
|
||
| def self.endpoint | ||
| if self == Base | ||
| fail NotImplementedError, 'Base is an abstract class, not an API resource' | ||
| end | ||
| fail NotImplementedError, 'Base is an abstract class, not an API resource' if equal?(Base) | ||
|
|
||
| "#{api_url}#{Util.to_plural(resource)}" | ||
| end | ||
|
|
||
| def persisted? | ||
| !id.nil? | ||
| end | ||
|
|
||
| protected | ||
|
|
||
| def add_accessor(symbol, *args) | ||
| def add_accessor(symbol, *_args) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just simplify this if we don't even use |
||
| singleton_class.instance_eval do | ||
| define_method(symbol) do | ||
| wrap_attribute(attributes[symbol]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what is going on here. I looked at the inheriting classes and I can't seem to find a block being provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the block is provided by
retrieve