Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Manage xcdatamodeld #53

Merged
merged 6 commits into from
Mar 15, 2018
Merged

Manage xcdatamodeld #53

merged 6 commits into from
Mar 15, 2018

Conversation

StevenWatremez
Copy link
Contributor

@StevenWatremez StevenWatremez commented Mar 12, 2018

This PR fixes #26.

Gyro::Log.fail!('Unable to find contents of xcdatamodel', stacktrace: true) unless File.exist?(contents_file)
is_xcdatamodeld = xcdatamodel_dir.extname != '.xcdatamodeld'
Gyro::Log.fail!('Please target an xcdatamodel inside your xcdatamodeld') unless is_xcdatamodeld
if xcdatamodel_dir.to_path.include?('.xcdatamodeld')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this : xcdatamodel_dir.parent.extname == '.xcdatamodeld

contents_file = File.join(xcdatamodel_dir, 'contents')
Gyro::Log.fail!('Unable to find contents of xcdatamodel', stacktrace: true) unless File.exist?(contents_file)
is_xcdatamodeld = xcdatamodel_dir.extname != '.xcdatamodeld'
Gyro::Log.fail!('Please target an xcdatamodel inside your xcdatamodeld') unless is_xcdatamodeld
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording nitpicking: "Please target an '.xcdatamodel' file inside your xcdatamodeld"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks for this

if xcdatamodel_dir.parent.extname == '.xcdatamodeld'
xcdatamodeld_info_message = 'You are using an xcdatamodeld, ' \
'please be sure you target the correct version of your xcdatamodel.' \
' Actual version using by gyro is : ' + xcdatamodel_dir.basename.to_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Current version used by gyro is: ' + xcdatamodel_dir.basename.to_path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Current is better than actual

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in english there's no space before :

document_xml = Document.new(file)
file.close
load_entities(document_xml)
xml_document = Document.new(file_contents.open)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Not sure if that new syntax properly closes the file once read
Also, maybe XML::Document can take a Pathname? Worth checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find any information about REXML::Document with Pathname, the better solution is to rollback my changes.

expect { Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) }
.to raise_error 'The relationship "user" from "FidelityCard" is wrong - please fix it'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new spec is good, but why did the old "check raising relationship error" spec disappear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad I will fix this

load_entities(xml_document)
file = File.open(file_contents)
document_xml = Document.new(file)
file.close
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File.open can take a trailing closure/block which will open the file, execute the block with the file handle, then auto-close the file.

document_xml = File.open(file_contents) { |file| Document.new(file) }

That's more readable, and also safer as, in case there's an exception on the lines of code before open and close, the block syntax will catch the exception and close the file properly before rethrowing, instead of letting the file open.

@@ -37,18 +37,20 @@ class XCDataModel

def initialize(xcdatamodel_dir)
is_xcdatamodeld = xcdatamodel_dir.extname != '.xcdatamodeld'
Gyro::Log.fail!('Please target an xcdatamodel inside your xcdatamodeld') unless is_xcdatamodeld
Gyro::Log.fail!('Please target an \'.xcdatamodel\' file inside your xcdatamodeld') unless is_xcdatamodeld
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised rubocop doesn't suggest you here to use %q(Please target an '.xcdatamodel' file …) syntax here (%q(…) allowing you to avoid having to escape the single quotes in the string)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so I tried with %qbut rubocop told that this syntax is only for string that contain both single quotes and double quotes. I seached and I found %() and %Q().

Copy link
Contributor Author

@StevenWatremez StevenWatremez Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And rubocop tells me to use %() instead of %Q()

@@ -27,7 +27,13 @@ module Gyro
it 'check raise an error for xcdatamodeld' do
xcdatamodel_dir = fixture('xcdatamodel', 'Model.xcdatamodeld')
expect { Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) }
.to raise_error 'Please target an xcdatamodel inside your xcdatamodeld'
.to raise_error 'Please target an \'.xcdatamodel\' file inside your xcdatamodeld'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (%q)

@AliSoftware AliSoftware merged commit 45e8c43 into master Mar 15, 2018
@AliSoftware AliSoftware deleted the feature/handle-xcdatamodeld branch March 15, 2018 17:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message when passing an xcdatamodeld
2 participants