Skip to content

Commit

Permalink
add new file and update gemspec, lockfile, bin, and spec files
Browse files Browse the repository at this point in the history
  • Loading branch information
dorianmariecom committed Sep 1, 2024
1 parent a0b8259 commit 76961d2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
22 changes: 22 additions & 0 deletions :w
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "spec_helper"
require "json"

RSpec.describe "Dorian" do
it "works" do
version = File.read("VERSION")
expect(`bin/dorian -v 2>&1`).to eq(version)
expect(`bin/dorian --version 2>&1`).to eq(version)
expect(`bin/dorian -h 2>&1`).to include("USAGE")
expect(`bin/dorian --help 2>&1`).to include("USAGE")
books_pretty =
JSON.pretty_generate(JSON.parse(File.read("samples/books.json"))) +
"\n"
expect(`bin/dorian samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --pretty true samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --pretty samples/books.json`).to eq(books_pretty)
books_ugly = JSON.parse(File.read("samples/books.json")).to_json + "\n"
expect(`bin/dorian --pretty false samples/books.json`).to eq(books_ugly)
end
end
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: .
specs:
dorian (2.0.2)
activesupport
csv
dorian-arguments
dorian-eval
Expand Down Expand Up @@ -41,7 +42,7 @@ GEM
yaml
dorian-progress (1.1.0)
ruby-progressbar
dorian-to_struct (1.2.0)
dorian-to_struct (2.0.0)
drb (2.2.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
Expand Down
1 change: 1 addition & 0 deletions dorian.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Gem::Specification.new do |s|
s.files = %w[VERSION bin/dorian lib/dorian/bin.rb]
s.executables << "dorian"

s.add_dependency "activesupport"
s.add_dependency "csv"
s.add_dependency "dorian-arguments"
s.add_dependency "dorian-eval"
Expand Down
13 changes: 6 additions & 7 deletions lib/dorian/bin.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# frozen_string_literal: true

require "active_support"
require "active_support/core_ext/hash"
require "active_support/core_ext/array"
require "csv"
require "dorian/arguments"
require "dorian/eval"
require "dorian/progress"
require "dorian/to_struct"
require "json"
require "yaml"
require "parallel"
require "yaml"

class Dorian
class Bin
Expand Down Expand Up @@ -152,12 +155,8 @@ def to_output(content)
map(content, &:to_json).join("\n")
when :raw
content
when :ruby
content.inspect
when :rubyl
map(content, &:inspect).join("\n")
when :yaml
content.to_yaml
content.deep_stringify_keys.to_yaml
else
abort "#{output} not supported"
end
Expand All @@ -178,7 +177,7 @@ def reads(content)
when :raw
content
when :yaml
YAML.safe_load(content)
YAML.safe_load(content).to_deep_struct
else
abort "#{input} not supported"
end
Expand Down
34 changes: 30 additions & 4 deletions spec/dorian_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
# frozen_string_literal: true

require "spec_helper"
require "json"
require "yaml"

RSpec.describe "Dorian" do
it "has the dorian-times gem" do
expect(`bin/times 3`).to eq("1\n2\n3\n")
describe "--version" do
it "works" do
version = File.read("VERSION")
expect(`bin/dorian -v 2>&1`).to eq(version)
expect(`bin/dorian --version 2>&1`).to eq(version)
end
end

it "has the dorian-each gem" do
expect(`bin/times 2 | each "puts it.to_i * 2"`).to eq("2\n4\n")
describe "--help" do
it "works" do
expect(`bin/dorian -h 2>&1`).to include("USAGE")
expect(`bin/dorian --help 2>&1`).to include("USAGE")
end
end

describe "read" do
it "works" do
books = JSON.parse(File.read("samples/books.json"))
books_pretty = "#{JSON.pretty_generate(books)}\n"
books_ugly = "#{books.to_json}\n"
books_yaml = "#{books.to_yaml}\n"

expect(`bin/dorian samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --pretty samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --pretty true samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --pretty false samples/books.json`).to eq(books_ugly)
expect(`bin/dorian --input json samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --io json samples/books.json`).to eq(books_pretty)
expect(`bin/dorian --output yaml samples/books.json`).to eq(books_yaml)
end
end
end

0 comments on commit 76961d2

Please sign in to comment.