jyron 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: da54f596258ac682b7f39167cf946a80d9a57f23eb89862a9540117570c54309
4
+ data.tar.gz: 5caba27d986c40a9118fa2365e6e021dc8cd19b56ba851f256f4fb51c0a4f9c2
5
+ SHA512:
6
+ metadata.gz: b00f74193b4c9c2274502beecbf4114f80c0a81d011fbb901eac52d07cbd6191a6c5ac07caa04f987ecee83854f6f3aceacd25d96aa3149848d0b18fb0a6bf60
7
+ data.tar.gz: 73d9d43f4c5c11f2e569be7fdb3ad7501128ebef421a4d06d92a2bef3d2eeea2e3b9540a8adf92f7418ab40d8dd2685ca93129c868e98141449eb1e6a2cc5e88
data/AUTHORS ADDED
@@ -0,0 +1,8 @@
1
+ Author :
2
+ Romain GEORGES <romain@ultragreen.net>
3
+ - code
4
+ - inline documentation
5
+ - specs
6
+ - Documentation
7
+ Ruby Gem maintener :
8
+ Romain GEORGES <romain@ultragreen.net>
data/COPYRIGHT ADDED
@@ -0,0 +1,24 @@
1
+ jyron Copyright (c) 2021 Ultragreen Software, Romain GEORGES
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
+ SUCH DAMAGE.
24
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jyron (0.1)
5
+ activesupport (~> 6.1.3.2)
6
+ jsonpath (~> 1.1.0)
7
+ mime-types (~> 3.3.1)
8
+ thor (~> 1.1.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (6.1.3.2)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
+ code_statistics (0.2.13)
20
+ concurrent-ruby (1.1.7)
21
+ diff-lcs (1.4.4)
22
+ i18n (1.8.5)
23
+ concurrent-ruby (~> 1.0)
24
+ jsonpath (1.1.0)
25
+ multi_json
26
+ mime-types (3.3.1)
27
+ mime-types-data (~> 3.2015)
28
+ mime-types-data (3.2020.0512)
29
+ minitest (5.14.2)
30
+ multi_json (1.14.1)
31
+ rake (13.0.1)
32
+ rdoc (6.2.1)
33
+ roodi (5.0.0)
34
+ ruby_parser (~> 3.2, >= 3.2.2)
35
+ rspec (3.9.0)
36
+ rspec-core (~> 3.9.0)
37
+ rspec-expectations (~> 3.9.0)
38
+ rspec-mocks (~> 3.9.0)
39
+ rspec-core (3.9.3)
40
+ rspec-support (~> 3.9.3)
41
+ rspec-expectations (3.9.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-mocks (3.9.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-support (3.9.3)
48
+ ruby_parser (3.15.0)
49
+ sexp_processor (~> 4.9)
50
+ sexp_processor (4.15.1)
51
+ thor (1.1.0)
52
+ tzinfo (2.0.2)
53
+ concurrent-ruby (~> 1.0)
54
+ yard (0.9.25)
55
+ yard-rspec (0.1)
56
+ yard
57
+ zeitwerk (2.4.0)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ code_statistics (~> 0.2.13)
64
+ jyron!
65
+ rake (~> 13.0.1)
66
+ rdoc (~> 6.2.1)
67
+ roodi (~> 5.0.0)
68
+ rspec (~> 3.9.0)
69
+ yard (~> 0.9.24)
70
+ yard-rspec (~> 0.1)
71
+
72
+ BUNDLED WITH
73
+ 2.1.2
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # JYRon
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ require "bundler/gem_tasks"
3
+ require 'rubygems'
4
+ require 'rspec'
5
+ require 'rake'
6
+ require "rake/clean"
7
+ require "rubygems/package_task"
8
+ require 'rspec/core/rake_task'
9
+ require 'yard'
10
+ require 'yard/rake/yardoc_task.rb'
11
+ require "rake/tasklib"
12
+ require "roodi"
13
+ require "roodi_task"
14
+ require 'code_statistics'
15
+
16
+ RoodiTask.new() do | t |
17
+ t.patterns = %w(lib/**/*.rb)
18
+ t.config = "ultragreen_roodi_coding_convention.yml"
19
+ end
20
+
21
+
22
+ CLEAN.include('*.tmp','*.old')
23
+ CLOBBER.include('*.tmp', 'build/*','#*#')
24
+
25
+
26
+ content = File::readlines(File.join(File.dirname(__FILE__), 'jyron.gemspec')).join
27
+ spec = eval(content)
28
+
29
+ RSpec::Core::RakeTask.new('spec')
30
+
31
+
32
+
33
+ YARD::Rake::YardocTask.new do |t|
34
+ t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
35
+ t.options += ['--title', "Gem Documentation"]
36
+ t.options += ['-o', "yardoc"]
37
+ t.options += ['-r', "doc/manual.rdoc"]
38
+ end
39
+ YARD::Config.load_plugin('yard-rspec')
40
+
41
+ namespace :yardoc do
42
+ task :clobber do
43
+ rm_r "yardoc" rescue nil
44
+ rm_r ".yardoc" rescue nil
45
+ end
46
+ end
47
+ task :clobber => "yardoc:clobber"
48
+
49
+
50
+ Gem::PackageTask.new(spec) do |pkg|
51
+ pkg.need_tar = true
52
+ pkg.need_zip = true
53
+ end
54
+
55
+ task :default => [:gem]
56
+
57
+ task :stage do
58
+ Rake::Task["clean"].invoke
59
+ Rake::Task["clobber"].invoke
60
+ Rake::Task["install"].invoke
61
+ end
data/bin/jyron ADDED
@@ -0,0 +1,10 @@
1
+
2
+ #!/usr/bin/env ruby
3
+ # coding: utf-8
4
+
5
+ require 'jyron'
6
+ require 'jyron/cli'
7
+
8
+ include JYRon::CLI
9
+
10
+ CMDBinding.start(ARGV)
data/jyron.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{jyron}
3
+ s.author = "Romain GEORGES"
4
+ s.version = "0.1"
5
+ s.date = "2021-05-14"
6
+ s.summary = "JYRon : JSON YAML Ruby object notation"
7
+ s.email = "romain@ultragreen.net"
8
+ s.homepage = "https://github.com/Ultragreen/jyron"
9
+ s.description = "JYRon : provide facilities to maniplate, convert, querying, storing transportables objects"
10
+ s.files = `git ls-files`.split($/)
11
+ s.require_paths = ["lib"]
12
+ s.require_paths << 'bin'
13
+ s.bindir = 'bin'
14
+ s.executables = Dir["bin/*"].map!{|item| item.gsub("bin/","")}
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+ s.add_runtime_dependency 'thor','~> 1.1.0'
17
+ s.add_runtime_dependency 'mime-types','~> 3.3.1'
18
+ s.add_runtime_dependency 'jsonpath','~> 1.1.0'
19
+ s.add_runtime_dependency 'activesupport','~> 6.1.3.2'
20
+ s.add_development_dependency 'rake', '~> 13.0.1'
21
+ s.add_development_dependency 'rspec', '~> 3.9.0'
22
+ s.add_development_dependency 'yard', '~> 0.9.24'
23
+ s.add_development_dependency 'rdoc', '~> 6.2.1'
24
+ s.add_development_dependency 'roodi', '~> 5.0.0'
25
+ s.add_development_dependency 'code_statistics', '~> 0.2.13'
26
+ s.add_development_dependency 'yard-rspec', '~> 0.1'
27
+ s.license = "BSD-2-Clause"
28
+ end
@@ -0,0 +1,15 @@
1
+ require 'pp'
2
+ require 'yaml'
3
+ require 'json'
4
+ require 'active_support/all'
5
+ require 'jsonpath'
6
+ require 'thor'
7
+ require 'mime-types'
8
+
9
+ require 'jyron/helpers'
10
+ require 'jyron/adapters'
11
+ require 'jyron/filters'
12
+ require 'jyron/inputs'
13
+ require 'jyron/outputs'
14
+
15
+ require 'jyron/mediator'
data/lib/jyron.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ require 'dependencies'
3
+
4
+ module JYRon
5
+
6
+ end
@@ -0,0 +1,50 @@
1
+ module JYRon
2
+ module Adapters
3
+
4
+ ADAPTERS = [:symbolize_keys, :stringify_keys, :upcase_keys, :snakecase_keys, :camelcase_keys, :downcase_keys]
5
+
6
+ private
7
+ def symbolize_keys
8
+ @object.deep_transform_keys! { |key| (key.class == String)? key.to_sym : key } if @object.class == Hash
9
+ if @object.class == Array then
10
+ @object.each do |item| item.deep_transform_keys! {|key| (key.class == String)? key.to_sym : key } if item.class == Hash end
11
+ end
12
+ end
13
+
14
+ def stringify_keys
15
+ object.deep_transform_keys!{|key| (key.class == Symbol)? key.to_s : key } if @object.class == Hash
16
+ if @object.class == Array then
17
+ @object.each do |item| item.deep_transform_keys!{|key| (key.class == Symbol)? key.to_s: key} if item.class == Hash end
18
+ end
19
+ end
20
+
21
+ def upcase_keys
22
+ object.deep_transform_keys!{|key| (key.class == String)? key.upcase : key } if @object.class == Hash
23
+ if @object.class == Array then
24
+ @object.each do |item| item.deep_transform_keys!{|key| (key.class == String)? key.upcase: key} if item.class == Hash end
25
+ end
26
+ end
27
+
28
+ def downcase_keys
29
+ object.deep_transform_keys!{|key| (key.class == String)? key.downcase : key } if @object.class == Hash
30
+ if @object.class == Array then
31
+ @object.each do |item| item.deep_transform_keys!{|key| (key.class == String)? key.downcase: key} if item.class == Hash end
32
+ end
33
+ end
34
+
35
+ def snakecase_keys
36
+ object.deep_transform_keys!{|key| (key.class == String)? key.underscore : key } if @object.class == Hash
37
+ if @object.class == Array then
38
+ @object.each do |item| item.deep_transform_keys!{|key| (key.class == String)? key.underscore: key} if item.class == Hash end
39
+ end
40
+ end
41
+
42
+ def camelcase_keys
43
+ object.deep_transform_keys!{|key| (key.class == String)? key.camelize : key } if @object.class == Hash
44
+ if @object.class == Array then
45
+ @object.each do |item| item.deep_transform_keys!{|key| (key.class == String)? key.camelize: key} if item.class == Hash end
46
+ end
47
+ end
48
+
49
+ end
50
+ end
data/lib/jyron/cli.rb ADDED
@@ -0,0 +1,83 @@
1
+ Dir[File.dirname(__FILE__) + '/cli/*.rb'].each {|file| require file }
2
+
3
+ module JYRon
4
+ module CLI
5
+ class CMDBinding < Thor
6
+ include JYRon::Inputs
7
+ include JYRon::Outputs
8
+ include JYRon::Filters
9
+ include JYRon::Helpers
10
+ include JYRon::Adapters
11
+ include JYRon::CLI::Exiter
12
+ desc "mediator", "say hello to NAME"
13
+ long_desc <<-LONGDESC
14
+ Mediator
15
+ LONGDESC
16
+ option :adapters, :type => :string, :banner => "<ADAPTER, ...>", :desc => "List of Adapters"
17
+ option :file, :type => :string, :aliases => "-f", :banner => "<FILENAME>", :desc => "Input filename"
18
+ CLI_INPUTS.each do |input,params|
19
+ option input, :type => :boolean, :desc => params[:desc], :negate => false
20
+ end
21
+ CLI_OUTPUTS.each do |output,params|
22
+ option output, :type => :boolean, :desc => params[:desc], :negate => false
23
+ end
24
+ FILTERS.each do |filter,params|
25
+ option "filter-#{filter}".to_sym, :type => :string, :desc => params[:desc], :negate => false, :banner => params[:banner]
26
+ end
27
+ def mediator
28
+ components = options.to_h.keys.map(&:to_sym)
29
+ if options[:file] then
30
+ begin
31
+ data = readfile(options[:file])
32
+ rescue HelpersError => e
33
+ cli_exit case: :not_found, more: e
34
+ end
35
+ elsif $stdin.ready?
36
+ data = STDIN.read
37
+ else
38
+ cli_exit case: :option_needed, more: "Data from STDIN or file ( --file|-f <filename> )"
39
+ end
40
+
41
+ #Adapters
42
+ adapters = []
43
+ adapters = options[:adapters].split(',').map(&:to_sym) if options[:adapters]
44
+ invalid_adapters = []
45
+ adapters.each {|adapter| invalid_adapters.push adapter unless ADAPTERS.include? adapter }
46
+ cli_exit case: :configuration_error, more: "Adapter(s) : #{invalid_adapters.join(', ')} not found" unless invalid_adapters.empty?
47
+
48
+ data_pipe = JYRon::Mediator::new adapters: adapters
49
+
50
+ # inputs
51
+ inputs = components.select{|value| value =~ /^from/} & CLI_INPUTS.keys
52
+ cli_exit case: :options_incompatibility, more: "Only one inputs type requiered" unless inputs.size < 2
53
+ cli_exit case: :option_needed, more: "Inputs type requiered (--from-<type>)" if inputs.empty?
54
+ input = inputs.first
55
+ begin
56
+ data_pipe.send(input, data)
57
+ rescue BadInputFormat => e
58
+ cli_exit case: :status_ko, more: "Bad Input format : #{e}"
59
+ end
60
+
61
+ # filters
62
+ filters = components.select{|value| value =~ /^filter/}
63
+ filters.each do |filter|
64
+ meth = filter.to_s.gsub('filter-','')
65
+ data_pipe.send meth.to_sym, options[filter]
66
+ end
67
+
68
+ # outputs
69
+ outputs = components.select{|value| value =~ /^to/} & CLI_OUTPUTS.keys
70
+ cli_exit case: :options_incompatibility, more: "Only one outputs type requiered" unless outputs.size < 2
71
+ cli_exit case: :option_needed, more: "Outputs type requiered (--to-<type>)" if outputs.empty?
72
+ output = outputs.first
73
+ puts data_pipe.send output
74
+
75
+ end
76
+
77
+ def self.exit_on_failure?
78
+ true
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+
3
+
4
+ module JYRon
5
+
6
+ module CLI
7
+
8
+ module Exiter
9
+
10
+ EXIT_MAP= {
11
+
12
+ # context execution
13
+ :not_root => {:message => "This operation need to be run as root (use sudo or rvmsudo)", :code => 10},
14
+ :options_incompatibility => {:message => "Options incompatibility", :code => 40},
15
+ :option_needed => {:message => "Option requiered", :code => 40},
16
+
17
+ # config
18
+ :specific_config_required => {:message => "Specific configuration required", :code => 30},
19
+ :configuration_error => {:message => "Configuration Error", :code => 50},
20
+
21
+
22
+ # global
23
+ :quiet_exit => {:code => 0},
24
+ :error_exit => {:code => 99, :message => "Operation failure"},
25
+
26
+ # events
27
+ :interrupt => {:message => "Operation interrupted", :code => 33},
28
+
29
+ # request
30
+ :not_found => {:message => "Object not found", :code => 44},
31
+ :already_exist => {:message => "Object already exist", :code => 48},
32
+
33
+ # daemon
34
+ :status_ok => {:message => "Status OK", :code => 0},
35
+ :status_ko => {:message => "Status KO", :code => 31}
36
+
37
+ }
38
+
39
+ # exiter wrapper
40
+ # @param [Hash] options
41
+ # @option options [Symbol] :case an exit case
42
+ # @option options [String] :more a complementary string to display
43
+ def cli_exit(options = {})
44
+
45
+ mess = ""
46
+ mess = EXIT_MAP[options[:case]][:message] if EXIT_MAP[options[:case]].include? :message
47
+ mess << " : " unless mess.empty? or not options[:more]
48
+ mess << "#{options[:more]}" if options[:more]
49
+ if EXIT_MAP[options[:case]][:code] == 0 then
50
+ puts mess unless mess.empty?
51
+ exit 0
52
+ else
53
+ puts "FATAL : #{mess}" unless mess.empty?
54
+ exit EXIT_MAP[options[:case]][:code]
55
+ end
56
+ end
57
+
58
+
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ module JYRon
2
+ module Filters
3
+
4
+ FILTERS = {:jsonpath => {:desc => "Filtering with JSONPath", :banner => "<JSONPath expression"}}
5
+
6
+ def jsonpath(expression)
7
+ if @adapters.include? :symbolize_keys then
8
+ res = JsonPath.new(expression, use_symbols: true).on(@object)
9
+ else
10
+ res = JsonPath.new(expression).on(@object)
11
+ end
12
+ @object = res
13
+ return self
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each {|file| require file }
@@ -0,0 +1,14 @@
1
+ module JYRon
2
+ module Helpers
3
+
4
+ class HelpersError < Exception; end
5
+
6
+ def readfile(filename)
7
+ begin
8
+ File::readlines(filename).join("\n")
9
+ rescue Errno::ENOENT
10
+ raise HelpersError.new "File #{filename} not found"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module JYRon
2
+
3
+ module Inputs
4
+
5
+ INPUTS_LIST = [:from_rb, :from_json, :from_yaml]
6
+ CLI_INPUTS = {:from_json => {:desc => "Input from JSON File"},
7
+ :from_rb => {:desc => "Input from RB File (Use very CAREFULLY)"},
8
+ :from_yaml => {:desc => "Input from YAML File"}}
9
+
10
+ class BadInputFormat < Exception; end
11
+
12
+
13
+
14
+ def from_yaml(string)
15
+ begin
16
+ @object = YAML::load(string)
17
+ adapt
18
+ return self
19
+ rescue Psych::SyntaxError
20
+ raise BadInputFormat.new 'Not in YAML format'
21
+ end
22
+ end
23
+
24
+ def from_json(string)
25
+ begin
26
+ @object = JSON.parse(string)
27
+ adapt
28
+ return self
29
+ rescue JSON::ParserError
30
+ raise BadInputFormat.new 'Not in JSON format'
31
+ end
32
+ end
33
+
34
+ def from_rb(string)
35
+ eval("@object=#{string}")
36
+ adapt
37
+ return self
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,47 @@
1
+ module JYRon
2
+ class Mediator
3
+ attr_accessor :object
4
+ include JYRon::Adapters
5
+ include JYRon::Filters
6
+ include JYRon::Outputs
7
+ include JYRon::Inputs
8
+
9
+ class MediatorOptionsFailure < Exception; end
10
+
11
+ def initialize(options = {})
12
+ @adapters = []
13
+ if options[:adapters] then
14
+ @adapters.push(options[:adapters]).flatten! if options[:adapters]
15
+ options.delete(:adapters)
16
+ end
17
+ from = INPUTS_LIST & options.keys
18
+ raise MediatorOptionsFailure if from.size > 2
19
+ self.send from.first, options[from.first] if from.size == 1
20
+ adapt unless @object.nil?
21
+ end
22
+
23
+
24
+
25
+ def from_obj(obj)
26
+ @object = obj
27
+ adapt
28
+ return self
29
+ end
30
+
31
+
32
+ def to_obj
33
+ return @object
34
+ end
35
+
36
+
37
+ private
38
+ def adapt
39
+ @adapters.each do |adapter|
40
+ self.send adapter
41
+ end
42
+ end
43
+
44
+
45
+
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ module JYRon
2
+ module Outputs
3
+
4
+
5
+ OUTPUTS_LIST = [:to_rb, :to_json, :to_yaml]
6
+ CLI_OUTPUTS = {:to_json => {:desc => "JSON Output format"},
7
+ :to_yaml => {:desc => "YAML Output format"},
8
+ :to_rb => {:desc => "RB/RON (Ruby Object Notation) Output format, use with carefull !"},
9
+ }
10
+
11
+ def to_rb
12
+ res = @object.pretty_inspect
13
+ return res
14
+ end
15
+
16
+ def to_json
17
+
18
+ return JSON.pretty_generate(@object).concat("\n")
19
+ end
20
+
21
+ def to_yaml
22
+ return @object.to_yaml
23
+ end
24
+
25
+
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ require_relative '../lib/jyron'
2
+
3
+ RSpec.configure do |config|
4
+ config.formatter = :documentation
5
+
6
+ end
7
+ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
8
+
9
+
10
+ describe JYRon::Mediator do
11
+ $data = {}
12
+ $data[:from_yaml] = {:content => File::readlines("./spec/test.yml").join, :type => 'yaml'}
13
+ $data[:from_json] = {:content => File::readlines("./spec/test.json").join, :type => 'json'}
14
+ $data[:from_rb] = {:content => File::readlines("./spec/test.rb").join, :type => 'rb'}
15
+ $data[:from_obj] = {:content => { 'Key' => "value", "Node" => { 'Key1' => 'value1', 'Key2' => 'value2'}}, :type => 'obj'}
16
+
17
+ before :all do
18
+
19
+ end
20
+
21
+ after :all do
22
+
23
+ end
24
+
25
+ subject { JYRon::Mediator::new }
26
+ specify { should be_an_instance_of JYRon::Mediator }
27
+ context "Inputs" do
28
+
29
+ $data.keys.each do |input|
30
+ describe "##{input} with #{$data[input][:type]}" do
31
+ specify { expect(subject).to respond_to input }
32
+ specify { expect(subject.send input, $data[input][:content]).to be_an_instance_of JYRon::Mediator }
33
+ specify { expect{subject.send input, $data[input][:content]}.to_not raise_error(JYRon::Inputs::BadInputFormat) }
34
+ end
35
+
36
+ end
37
+ end
38
+ context "Outputs" do
39
+ describe "#to_json" do
40
+ specify { expect(subject).to respond_to :to_json }
41
+ specify { expect(subject.to_json).to be_an_instance_of String }
42
+ specify { expect(subject.from_yaml($data[:from_yaml][:content]).to_json).to eq $data[:from_json][:content]}
43
+ end
44
+ describe "#to_yaml" do
45
+ specify { expect(subject).to respond_to :to_yaml }
46
+ specify { expect(subject.to_yaml).to be_an_instance_of String }
47
+ specify { expect(subject.from_json($data[:from_json][:content]).to_yaml).to eq $data[:from_yaml][:content]}
48
+ end
49
+ describe "#to_rb" do
50
+ specify { expect(subject).to respond_to :to_rb }
51
+ specify { expect(subject.to_rb).to be_an_instance_of String }
52
+ specify { expect(subject.from_json($data[:from_json][:content]).to_rb).to eq $data[:from_rb][:content]}
53
+ end
54
+ end
55
+
56
+ context "Filters" do
57
+ describe "#jsonpath with expression $..Node" do
58
+ specify { expect(subject).to respond_to :jsonpath }
59
+ specify { expect(subject.from_json($data[:from_json][:content]).jsonpath("$..Node")).to be_an_instance_of JYRon::Mediator }
60
+ specify { expect(subject.from_json($data[:from_json][:content]).jsonpath("$..Node").to_obj).to eq([{ 'Key1' => 'value1', 'Key2' => 'value2'}]) }
61
+ end
62
+ end
63
+
64
+ end
data/spec/test.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "Key": "value",
3
+ "Node": {
4
+ "Key1": "value1",
5
+ "Key2": "value2"
6
+ }
7
+ }
data/spec/test.rb ADDED
@@ -0,0 +1 @@
1
+ {"Key"=>"value", "Node"=>{"Key1"=>"value1", "Key2"=>"value2"}}
data/spec/test.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ Key: value
3
+ Node:
4
+ Key1: value1
5
+ Key2: value2
@@ -0,0 +1,25 @@
1
+ AssignmentInConditionalCheck:
2
+ CaseMissingElseCheck:
3
+ ClassLineCountCheck:
4
+ line_count: 300
5
+ ClassNameCheck:
6
+ pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
7
+ #ClassVariableCheck:
8
+ CyclomaticComplexityBlockCheck:
9
+ complexity: 4
10
+ CyclomaticComplexityMethodCheck:
11
+ complexity: 10
12
+ EmptyRescueBodyCheck:
13
+ ForLoopCheck:
14
+ MethodLineCountCheck:
15
+ line_count: 30
16
+ MethodNameCheck:
17
+ pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
18
+ # MissingForeignKeyIndexCheck:
19
+ ModuleLineCountCheck:
20
+ line_count: 500
21
+ ModuleNameCheck:
22
+ pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
23
+ ParameterNumberCheck:
24
+ parameter_count: 5
25
+
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jyron
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Romain GEORGES
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mime-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: jsonpath
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.1.3.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.1.3.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 13.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 13.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.9.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.9.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.24
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.24
111
+ - !ruby/object:Gem::Dependency
112
+ name: rdoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 6.2.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 6.2.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: roodi
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 5.0.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 5.0.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: code_statistics
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.2.13
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.2.13
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.1'
167
+ description: 'JYRon : provide facilities to maniplate, convert, querying, storing
168
+ transportables objects'
169
+ email: romain@ultragreen.net
170
+ executables:
171
+ - jyron
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - AUTHORS
176
+ - COPYRIGHT
177
+ - Gemfile
178
+ - Gemfile.lock
179
+ - README.md
180
+ - Rakefile
181
+ - bin/jyron
182
+ - jyron.gemspec
183
+ - lib/dependencies.rb
184
+ - lib/jyron.rb
185
+ - lib/jyron/adapters.rb
186
+ - lib/jyron/cli.rb
187
+ - lib/jyron/cli/exiter.rb
188
+ - lib/jyron/filters.rb
189
+ - lib/jyron/helpers.rb
190
+ - lib/jyron/helpers/files.rb
191
+ - lib/jyron/inputs.rb
192
+ - lib/jyron/mediator.rb
193
+ - lib/jyron/outputs.rb
194
+ - spec/mediator_spec.rb
195
+ - spec/test.json
196
+ - spec/test.rb
197
+ - spec/test.yml
198
+ - ultragreen_roodi_coding_convention.yml
199
+ homepage: https://github.com/Ultragreen/jyron
200
+ licenses:
201
+ - BSD-2-Clause
202
+ metadata: {}
203
+ post_install_message:
204
+ rdoc_options: []
205
+ require_paths:
206
+ - lib
207
+ - bin
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubygems_version: 3.1.2
220
+ signing_key:
221
+ specification_version: 4
222
+ summary: 'JYRon : JSON YAML Ruby object notation'
223
+ test_files:
224
+ - spec/mediator_spec.rb
225
+ - spec/test.json
226
+ - spec/test.rb
227
+ - spec/test.yml