Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: buty4649/rf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.0
Choose a base ref
...
head repository: buty4649/rf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.2.0
Choose a head ref

Commits on Jun 12, 2023

  1. Use JSON.pretty_generate

    buty4649 committed Jun 12, 2023
    Copy the full SHA
    ba49321 View commit details
  2. Copy the full SHA
    041dd97 View commit details
  3. Bump rubocop from 1.52.0 to 1.52.1

    Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.52.0 to 1.52.1.
    - [Release notes](https://github.com/rubocop/rubocop/releases)
    - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
    - [Commits](rubocop/rubocop@v1.52.0...v1.52.1)
    
    ---
    updated-dependencies:
    - dependency-name: rubocop
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jun 12, 2023
    Copy the full SHA
    e7956fe View commit details

Commits on Jun 13, 2023

  1. Merge pull request #42 from buty4649/dependabot/bundler/rubocop-1.52.1

    Bump rubocop from 1.52.0 to 1.52.1
    github-actions[bot] authored Jun 13, 2023
    Copy the full SHA
    af6d364 View commit details
  2. Copy the full SHA
    4beb513 View commit details
  3. Copy the full SHA
    b9fcb33 View commit details
  4. Improve version text

    buty4649 committed Jun 13, 2023
    Copy the full SHA
    69eec89 View commit details
  5. Copy the full SHA
    659d638 View commit details
  6. Copy the full SHA
    e482bee View commit details

Commits on Jun 14, 2023

  1. Copy the full SHA
    3b3bb4b View commit details
  2. Copy the full SHA
    c53b56b View commit details
  3. Copy the full SHA
    e7e0df4 View commit details

Commits on Jun 15, 2023

  1. Copy the full SHA
    6deeb40 View commit details
  2. Copy the full SHA
    c1ca81b View commit details
  3. Copy the full SHA
    61e21e0 View commit details
  4. Copy the full SHA
    fd87c37 View commit details

Commits on Jun 17, 2023

  1. Copy the full SHA
    abcc29d View commit details
  2. Copy the full SHA
    d03e06e View commit details
  3. Increase release task

    buty4649 committed Jun 17, 2023
    Copy the full SHA
    69ae07f View commit details
  4. Remove dependency

    buty4649 committed Jun 17, 2023
    Copy the full SHA
    dec10c9 View commit details
  5. 1.2.0

    buty4649 committed Jun 17, 2023
    Copy the full SHA
    95e74ba View commit details
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ jobs:
with:
ruby-version: 3.2
bundler-cache: true
- name: Build
run: rake release
- name: Build assets
run: rake build:assets
- name: Create release tag
env:
GH_TOKEN: ${{ github.token }}
10 changes: 6 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -54,15 +54,17 @@ GEM
parallel (1.23.0)
parallel_tests (4.2.1)
parallel
parser (3.2.2.1)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
proc_to_ast (0.1.0)
coderay
parser
unparser
racc (1.7.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.8.0)
regexp_parser (2.8.1)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
@@ -88,10 +90,10 @@ GEM
binding_of_caller
rspec-parameterized-core (< 2)
rspec-support (3.12.0)
rubocop (1.52.0)
rubocop (1.52.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
21 changes: 18 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -58,6 +58,11 @@ namespace :build do
docker_run(env:)
end
end

desc 'Build assets files for all targets'
task assets: %w[clean build:all] do
archive_binary_file(build_targets, "v#{Rf::VERSION}")
end
end

desc 'Cleanup build cache'
@@ -71,9 +76,19 @@ task 'deep_clean' do
docker_run(cmd: 'deep_clean', env:)
end

desc 'Release the project'
task release: %w[clean build:all] do
archive_binary_file(build_targets, "v#{Rf::VERSION}")
desc 'Bumpup minor version and release'
task 'release' do
version = Rf::VERSION.split('.')
version[1].succ! # increment minor version
File.write('mrblib/rf/version.rb', <<~VERSION)
module Rf
VERSION = '#{version.join('.').inspect}'
end
VERSION
sh 'git add mrblib/rf/version.rb'
sh "git commit -m '#{version.join('.')}'"
sh "git tag v#{version.join('.')}"
sh "git push origin v#{version.join('.')}"
end

desc 'Run RSpec with parallel_rspec'
5 changes: 5 additions & 0 deletions mrblib/core_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class String
def red
"\e[31m#{self}\e[0m"
end
end
74 changes: 32 additions & 42 deletions mrblib/rf/00filter/base.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,54 @@
module Rf
module Filter
class Base
attr_reader :data, :record
attr_reader :record, :index

def each_record
index = 1
data.each do |record|
@record = preprocess(record)
fields = split(@record)
yield @record, index, fields
index += 1
end
def initialize
@index = 0
end

def preprocess(record)
record
def decorate(val)
raise NotImplementedError
end

def split(record)
case record
when Array
record
when Hash
record.to_a
when String
record.split
else
[record]
end
def gets
raise NotImplementedError
end

def output(val)
return if quiet?(val)
# Increment index when gets is called
def self.inherited(klass)
klass.define_singleton_method(:method_added) do |name|
if name == :gets && !method_defined?(:gets_without_increment)
alias_method :gets_without_increment, :gets

puts(case val
when true, Regexp
record
else
val
end)
end
define_method(:gets) do
return unless v = gets_without_increment

@index += 1
v
end
end

def puts(*args)
args.each do |arg|
$stdout.puts decorate(arg)
super
end

super
end

def decorate(val)
val.to_s
def each_record
yield record, index, split(record) while @record = gets
end

def quiet?(val)
def split(val)
case val
when true, String, Integer, Float, Array, Hash, MatchData
false
when Regexp
!val.match?(record)
when Array
val
when Hash
val.to_a
when String
val.split
else
true
[val]
end
end
end
46 changes: 42 additions & 4 deletions mrblib/rf/00filter/json.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ def raw?
self.class.config.raw
end

def initialize(io) # rubocop:disable Lint/MissingSuper
def initialize(io)
super()

json = JSON.parse(io.read)
@data = if json.instance_of?(Array)
json
@@ -20,13 +22,49 @@ def initialize(io) # rubocop:disable Lint/MissingSuper
end
end

def gets
@data.shift
end

def decorate(val)
if raw? && val.instance_of?(String)
val
return if quiet?(val)

case val
when String
raw? ? val : val.to_json
when Regexp
decorate_regexp(val)
when true, MatchData
decorate(record)
else
JSON.pretty_generate(val)
val.to_json
end
end

class RegexpUnsupportType < StandardError
def initialize
super('Regexp supports only String and Number records')
end
end

def decorate_regexp(regexp)
raise RegexpUnsupportType unless regexp_support_type?
return unless regexp.match?(record.to_s)

decorate(record)
end

def regexp_support_type?
record.instance_of?(String) ||
record.instance_of?(Integer) ||
record.instance_of?(Float)
end

def quiet?(val)
# false and nil is special character in JSON
(val == false && record != false) ||
(val.nil? && !record.nil?)
end
end
end
end
29 changes: 26 additions & 3 deletions mrblib/rf/00filter/text.rb
Original file line number Diff line number Diff line change
@@ -7,14 +7,37 @@ def self.config
@config ||= Config.new
end

def initialize(io) # rubocop:disable Lint/MissingSuper
def initialize(io)
super()

@data = io
fs = self.class.config.fs
$; = Regexp.new(fs) if fs
end

def preprocess(record)
record.chomp
def gets
@data.gets&.chomp
end

def decorate(val)
case val
when true
record
when Regexp
return unless m = val.match(record)

[
m.pre_match,
m.to_s.red,
m.post_match
].join
when Array
val.map(&method(:decorate)).join(' ')
when false, nil
nil
else
val.to_s
end
end
end
end
44 changes: 42 additions & 2 deletions mrblib/rf/00filter/yaml.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module Rf
module Filter
class Yaml < Base
def initialize(io) # rubocop:disable Lint/MissingSuper
def initialize(io)
super()

yaml = YAML.load(io.read)
@data = if yaml.instance_of?(Array)
yaml
@@ -10,8 +12,46 @@ def initialize(io) # rubocop:disable Lint/MissingSuper
end
end

def gets
@data.shift
end

def decorate(val)
val.to_yaml.sub(/\A---[\s\n]/, '')
return if quiet?(val)

case val
when MatchData, true
decorate(record)
when Regexp
decorate_regexp(val)
else
val.to_yaml.sub(/\A---[\s\n]/, '')
end
end

class RegexpUnsupportType < StandardError
def initialize
super('Regexp supports only String and Number records')
end
end

def decorate_regexp(regexp)
raise RegexpUnsupportType unless regexp_support_type?
return unless regexp.match?(record.to_s)

decorate(record)
end

def regexp_support_type?
record.instance_of?(String) ||
record.instance_of?(Integer) ||
record.instance_of?(Float)
end

def quiet?(val)
# false and nil is special character in YAML
(val == false && record != false) ||
(val.nil? && !record.nil?)
end
end
end
1 change: 1 addition & 0 deletions mrblib/rf/cli.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ class Cli

def run(argv)
@config = Config.parse(argv)
Rf.add_features
Runner.run({
command: config.command,
filter:,
8 changes: 4 additions & 4 deletions mrblib/rf/config.rb
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ def option # rubocop:disable Metrics/AbcSize
@config.type = v.to_sym
end

opt.on('--debug', 'enable debug mode') { @config.debug = true }
opt.on('-n', '--quiet', 'suppress automatic priting') { @config.quiet = true }
opt.on('-h', '--help', 'show this message') { print_help_and_exit }
opt.on('-v', '--version', 'show version') { print_version_and_exit }
opt.on('--debug', 'enable debug mode') { @config.debug = true }
opt.on('--help', 'show this message') { print_help_and_exit }
opt.on('--version', 'show version') { print_version_and_exit }

opt.separator ''
opt.separator 'text options:'
@@ -69,7 +69,7 @@ def print_help_and_exit(exit_status = 0)
end

def print_version_and_exit
puts Rf::VERSION
puts "rf #{Rf::VERSION} (mruby #{MRUBY_VERSION})"
exit
end
end
Loading