Skip to content

Commit

Permalink
Merge pull request #22 from velocidi/feature/ruby-min-version-supported
Browse files Browse the repository at this point in the history
Increase minimum required ruby version to 2.6.0
  • Loading branch information
jcazevedo authored Feb 17, 2021
2 parents dd041e7 + 8fcd04d commit afd0f06
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ 2.5, 2.6, 2.7 ]
ruby: [ 2.6, 2.7, 3.0 ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: '2.3'
NewCops: enable
Layout/EmptyLineAfterGuardClause:
Enabled: false
Metrics:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 0.5.0 (TBD)

- Breaking changes
- Increase minimum required ruby version to 2.6.0 ([#22](https://github.com/velocidi/frise/pull/22)).

### 0.4.1 (July 7, 2020)

- New features
Expand Down
4 changes: 2 additions & 2 deletions frise.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
f.match(%r{^(test|spec|features|example)/})
end
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.3.0'
spec.required_ruby_version = '>= 2.6.0'

spec.add_dependency 'liquid', '~> 4.0'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'rubocop', '0.77.0'
spec.add_development_dependency 'rubocop', '~> 1.10'
spec.add_development_dependency 'simplecov', '~> 0.18'
spec.add_development_dependency 'simplecov-lcov', '0.8.0'
end
10 changes: 9 additions & 1 deletion lib/frise/defaults_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ module Frise
class DefaultsLoader
SYMBOLS = %w[$all $optional].freeze

def initialize(include_sym: '$include', content_include_sym: '$content_include', schema_sym: '$schema', delete_sym: '$delete')
def initialize(
include_sym: '$include',
content_include_sym: '$content_include',
schema_sym: '$schema',
delete_sym: '$delete'
)

@include_sym = include_sym
@content_include_sym = content_include_sym
@schema_sym = schema_sym
Expand All @@ -25,6 +31,7 @@ def widened_class(obj)
class_name
end

# rubocop:disable Lint/DuplicateBranch
def merge_defaults_obj(config, defaults)
config_class = widened_class(config)
defaults_class = widened_class(defaults)
Expand Down Expand Up @@ -66,6 +73,7 @@ def merge_defaults_obj(config, defaults)
config
end
end
# rubocop:enable Lint/DuplicateBranch

def merge_defaults_obj_at(config, at_path, defaults)
at_path.reverse.each { |key| defaults = { key => defaults } }
Expand Down
17 changes: 9 additions & 8 deletions lib/frise/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def load(config_file, global_vars = {})
private

def process_includes(config, at_path, root_config, global_vars, include_confs_stack = [])
return config unless config.class == Hash
return config unless config.instance_of?(Hash)

# process $content_include directives
config, content_include_confs = extract_content_include(config, at_path)
Expand All @@ -73,18 +73,19 @@ def process_includes(config, at_path, root_config, global_vars, include_confs_st
else
Lazy.new do
include_conf = include_confs.first
rest_include_confs = include_confs[1..-1]
rest_include_confs = include_confs[1..]
symbol_table = build_symbol_table(root_config, at_path, config, global_vars, include_conf)
included_config = Parser.parse(include_conf['file'], symbol_table)
config = @defaults_loader.merge_defaults_obj(config, included_config)
process_includes(config, at_path, merge_at(root_config, at_path, config), global_vars, rest_include_confs)
process_includes(config, at_path, merge_at(root_config, at_path, config), global_vars,
rest_include_confs)
end
end
@delete_sym.nil? ? res : omit_deleted(res)
end

def process_schema_includes(schema, at_path, global_vars)
return schema unless schema.class == Hash
return schema unless schema.instance_of?(Hash)

schema, included_schemas = extract_include(schema, at_path)
if included_schemas.empty?
Expand All @@ -98,7 +99,7 @@ def process_schema_includes(schema, at_path, global_vars)
end

def process_schemas(config, at_path, global_vars)
return config unless config.class == Hash
return config unless config.instance_of?(Hash)

config = config.map do |k, v|
new_v = process_schemas(v, at_path + [k], global_vars)
Expand Down Expand Up @@ -149,10 +150,10 @@ def extract_include_base(config, sym, at_path)
end
end

def extract_special(config, key, at_path)
def extract_special(config, key, at_path, &block)
case config[key]
when nil then [config, []]
when Array then [config.reject { |k| k == key }, config[key].map { |e| yield e }]
when Array then [config.reject { |k| k == key }, config[key].map(&block)]
else raise "At #{build_path(at_path)}: illegal value for #{key}: #{config[key].inspect}"
end
end
Expand Down Expand Up @@ -182,7 +183,7 @@ def omit_deleted(config)
# - `global_vars`: the global variables
# - `include_conf`: the $include or $content_include configuration
def build_symbol_table(root_config, at_path, config, global_vars, include_conf)
extra_vars = (include_conf['vars'] || {}).map { |k, v| [k, root_config.dig(*v.split('.'))] }.to_h
extra_vars = (include_conf['vars'] || {}).transform_values { |v| root_config.dig(*v.split('.')) }
extra_consts = include_conf['constants'] || {}

omit_deleted(config ? merge_at(root_config, at_path, config) : root_config)
Expand Down
2 changes: 0 additions & 2 deletions lib/frise/loader/lazy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ def __target_object__
@__target_object__ ||= @callable.call
end

# rubocop:disable Style/MethodMissingSuper
def method_missing(method_name, *args, &block)
__target_object__.send(method_name, *args, &block)
end
# rubocop:enable Style/MethodMissingSuper

def respond_to_missing?(method_name, include_private = false)
__target_object__.respond_to?(method_name, include_private)
Expand Down
24 changes: 19 additions & 5 deletions lib/frise/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Validator
attr_reader :errors

def initialize(root, validators = nil)
super()

@root = root
@validators = validators
@errors = []
Expand All @@ -33,7 +35,7 @@ def add_validation_error(path, msg)

def get_full_schema(schema)
case schema
when Hash then
when Hash
default_type = schema[:enum] || schema[:one_of] ? 'Object' : 'Hash'
{ type: default_type }.merge(schema)
when Symbol then { type: 'Object', validate: schema }
Expand Down Expand Up @@ -124,7 +126,7 @@ def validate_spec_keys(full_schema, obj, path, processed_keys)
def validate_remaining_keys(full_schema, obj, path, processed_keys)
expected_types = get_expected_types(full_schema)
if expected_types.size == 1 && expected_types[0].ancestors.member?(Enumerable)
hash = obj.is_a?(Hash) ? obj : Hash[obj.map.with_index { |x, i| [i, x] }]
hash = obj.is_a?(Hash) ? obj : obj.map.with_index { |x, i| [i, x] }.to_h
hash.each do |key, value|
validate_object(path, key, full_schema[:all_keys]) if full_schema[:all_keys] && !key.is_a?(Symbol)

Expand Down Expand Up @@ -156,8 +158,8 @@ def validate_object(path, obj, schema)
def self.parse_symbols(obj)
case obj
when Array then obj.map { |e| parse_symbols(e) }
when Hash then Hash[obj.map { |k, v| [parse_symbols(k), parse_symbols(v)] }]
when String then obj.start_with?('$') ? obj[1..-1].to_sym : obj
when Hash then obj.map { |k, v| [parse_symbols(k), parse_symbols(v)] }.to_h
when String then obj.start_with?('$') ? obj[1..].to_sym : obj
else obj
end
end
Expand All @@ -166,7 +168,17 @@ def self.validate_obj(config, schema, options = {})
validate_obj_at(config, [], schema, **options)
end

def self.validate_obj_at(config, at_path, schema, path_prefix: nil, validators: nil, print: nil, fatal: nil, raise_error: nil)
def self.validate_obj_at(
config,
at_path,
schema,
path_prefix: nil,
validators: nil,
print: nil,
fatal: nil,
raise_error: nil
)

schema = parse_symbols(schema)
at_path.reverse.each { |key| schema = { key => schema, :allow_unknown_keys => true } }

Expand Down Expand Up @@ -202,6 +214,8 @@ class ValidationError < StandardError
attr_reader :errors

def initialize(errors)
super()

@errors = errors
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/frise/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Frise
VERSION = '0.4.2.pre'
VERSION = '0.5.0.pre'
end

0 comments on commit afd0f06

Please sign in to comment.