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

Refactoring to remove some rubocop warnings and for consistency #106

Merged
merged 1 commit into from
Sep 7, 2019
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
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
Lint/AmbiguousOperator:
Exclude:
- 'lib/jekyll/commands/draft.rb'
- 'lib/jekyll/commands/page.rb'
- 'lib/jekyll/commands/post.rb'

# Offense count: 6
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Exclude:
- 'lib/jekyll-compose/file_mover.rb'
- 'lib/jekyll/commands/publish.rb'
- 'lib/jekyll/commands/unpublish.rb'
- 'spec/post_spec.rb'
- 'spec/publish_spec.rb'
8 changes: 4 additions & 4 deletions lib/jekyll/commands/draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def self.init_with_program(prog)
c.syntax "draft NAME"
c.description "Creates a new draft post with the given NAME"

options.each { |opt| c.option *opt }
options.each { |opt| c.option(*opt) }

c.action { |args, options| process args, options }
c.action { |args, options| process(args, options) }
end
end

Expand All @@ -25,10 +25,10 @@ def self.options

def self.process(args = [], options = {})
config = configuration_from_options(options)
params = Compose::ArgParser.new args, options, config
params = Compose::ArgParser.new(args, options, config)
params.validate!

draft = DraftFileInfo.new params
draft = DraftFileInfo.new(params)

file_creator = Compose::FileCreator.new(draft, params.force?, params.source)
file_creator.create!
Expand Down
8 changes: 4 additions & 4 deletions lib/jekyll/commands/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def self.init_with_program(prog)
c.syntax "page NAME"
c.description "Creates a new page with the given NAME"

options.each { |opt| c.option *opt }
options.each { |opt| c.option(*opt) }

c.action { |args, options| process args, options }
c.action { |args, options| process(args, options) }
end
end

Expand All @@ -25,10 +25,10 @@ def self.options

def self.process(args = [], options = {})
config = configuration_from_options(options)
params = PageArgParser.new args, options, config
params = PageArgParser.new(args, options, config)
params.validate!

page = PageFileInfo.new params
page = PageFileInfo.new(params)

Compose::FileCreator.new(page, params.force?, params.source).create!
end
Expand Down
10 changes: 5 additions & 5 deletions lib/jekyll/commands/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def self.init_with_program(prog)
c.syntax "post NAME"
c.description "Creates a new post with the given NAME"

options.each { |opt| c.option *opt }
options.each { |opt| c.option(*opt) }

c.action { |args, options| process args, options }
c.action { |args, options| process(args, options) }
end
end

Expand All @@ -26,10 +26,10 @@ def self.options

def self.process(args = [], options = {})
config = configuration_from_options(options)
params = PostArgParser.new args, options, config
params = PostArgParser.new(args, options, config)
params.validate!

post = PostFileInfo.new params
post = PostFileInfo.new(params)

file_creator = Compose::FileCreator.new(post, params.force?, params.source)
file_creator.create!
Expand All @@ -40,7 +40,7 @@ def self.process(args = [], options = {})

class PostArgParser < Compose::ArgParser
def date
options["date"].nil? ? Time.now : Date.parse(options["date"])
@date ||= options["date"] ? Date.parse(options["date"]) : Time.now
end
end

Expand Down
18 changes: 11 additions & 7 deletions lib/jekyll/commands/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ def self.init_with_program(prog)
c.syntax "publish DRAFT_PATH"
c.description "Moves a draft into the _posts directory and sets the date"

c.option "date", "-d DATE", "--date DATE", "Specify the post date"
c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"
c.option "force", "-f", "--force", "Overwrite a post if it already exists"
options.each { |opt| c.option(*opt) }

c.action do |args, options|
Jekyll::Commands::Publish.process(args, options)
end
c.action { |args, options| process(args, options) }
end
end

def self.options
[
["date", "-d DATE", "--date DATE", "Specify the post date"],
["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
["force", "-f", "--force", "Overwrite a post if it already exists"],
]
end

def self.process(args = [], options = {})
config = configuration_from_options(options)
params = PublishArgParser.new args, options, config
Expand All @@ -36,7 +40,7 @@ def resource_type
end

def date
options["date"].nil? ? Time.now : Date.parse(options["date"])
@date ||= options["date"] ? Date.parse(options["date"]) : Time.now
end

def name
Expand Down
20 changes: 12 additions & 8 deletions lib/jekyll/commands/unpublish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ def self.init_with_program(prog)
c.syntax "unpublish POST_PATH"
c.description "Moves a post back into the _drafts directory"

c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"
c.option "force", "-f", "--force", "Overwrite a draft if it already exists"
options.each { |opt| c.option(*opt) }

c.action do |args, options|
process(args, options)
end
c.action { |args, options| process(args, options) }
end
end

def self.options
[
["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
["force", "-f", "--force", "Overwrite a draft if it already exists"],
]
end

def self.process(args = [], options = {})
config = configuration_from_options(options)
params = UnpublishArgParser.new args, options, config
params = UnpublishArgParser.new(args, options, config)
params.validate!

movement = PostMovementInfo.new params
movement = PostMovementInfo.new(params)

mover = PostMover.new movement, params.force?, params.source
mover = PostMover.new(movement, params.force?, params.source)
mover.move
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

context "when the post already exists" do
let(:name) { "An existing post" }
let(:filename) { "#{Time.now.strftime(Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT)}-an-existing-post.md" }
let(:filename) { "#{datestamp}-an-existing-post.md" }

before(:each) do
FileUtils.touch path
Expand Down