-
Notifications
You must be signed in to change notification settings - Fork 6
Conversation
I'm not understanding the bug that this is supposed to fix. Why doesn't the existing initializer work as expected? The bug description in #124 has no details about when the bug arises or how to replicate the bug. |
At first glance, it seems that |
Another way to refactor this is to create a private or protected method in class Adapter
def map_date(model_field, public_field)
# call the date_format method, etc.
end
protected
def date_format
"%Y-%m-%dT%H:%M:%SZ"
end
end This would allow sub-classes to specialize it, if required. However, none of them do. Another idea is to define a default, e.g. def map_date(model_field, public_field, date_format = "%Y-%m-%dT%H:%M:%SZ")
# etc
end |
Not clear why the def time_from_string(string_time)
Time.zone.parse(string_time.gsub(/\.[0-9]*Z\Z/, "Z"))
end Also, when we look closer at this method, it's a puzzle that it's required at all because it is trying to parse or modify a string that the parser can handle just fine, e.g.
If that's the case, this method should disappear entirely. What's the use case that it serves that is not already solved by the This method seems to be used in the
|
33e368f
to
51db157
Compare
@@ -20,6 +20,7 @@ def map_simple(model_field, public_field) | |||
# @param [Symbol] public_field | |||
# @param [String] date_format The Date format to use. | |||
def map_date(model_field, public_field, date_format) | |||
raise ArgumentError, "date_format cannot be nil" if date_format.nil? |
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.
If it cannot be nil
, give it a default value. Use the default that is always given when this method is called, i.e.
map_date(model_field, public_field, date_format = "%Y-%m-%dT%H:%M:%SZ")
The Adapter/AbstractAdapter code does not need to know anything about the rest of the application other than it's built on Rails. We could extract it out into a gem. Defining a magic number specific to our application in these classes would solve our problem, but it would also violate the separation of concerns.
The goal here seems to be to move it into an application-wide top-level namespace, but it's already available in one such location. Also, despite the name, ApplicationHelper and the rest of the helpers are only available to views by default. I have no idea how the rails team didn't think to call these "view helpers."
This constant is invoked by class methods that explicitly declare the mapping between the public interface and our model. We want the class definitions to be precise, so having no default is appropriate here. |
I propose this is better fixed in #128 - as the actual date/time format being used is ISO8601 and the code in #128 makes this explicit. Also, it relies on the existing tried and tested libraries to parse/manipulate date time strings, rather than a custom method that wraps the libraries (i.e. the responsibility for date/time parsing or manipulation is not in any methods of this app). |
I don't love it, but I'm going to move forward on this to keep moving on an RC7 release. I will try to rebase and rework #128 to resolve my concerns about the code designs. |
Resolves #124
Constructing a spec is difficult for this issue, but the
raise
guard will fail before rails finishes loading if the constant is not yet defined.