Skip to content

Commit

Permalink
Merge pull request #69 from mcorino/mco-ruby-upgrades
Browse files Browse the repository at this point in the history
simplify by using Ruby safe nav
  • Loading branch information
mcorino authored May 12, 2022
2 parents 667f76f + 3dbfa26 commit 547fd0f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/ridl/delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Delegator
@@pragma_handlers = {}

def self.add_pragma_handler(key, h = nil, &block)
raise 'add_pragma_handler requires a callable object or a block' unless (h && h.respond_to?(:call)) || block_given?
raise 'add_pragma_handler requires a callable object or a block' unless h&.respond_to?(:call) || block_given?
@@pragma_handlers[key] = block_given? ? block : h
end

Expand Down
7 changes: 3 additions & 4 deletions lib/ridl/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1316,8 +1316,8 @@ def instantiate(instantiation_context, _enclosure)
end

def set_component_and_key(comp, key)
unless comp && comp.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::TemplateParam)
unless comp && comp.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::Component)
unless comp&.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::TemplateParam)
unless comp&.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::Component)
raise (comp ?
"invalid managed component for #{typename} #{scoped_lm_name}: #{comp.typename}" :
"missing managed component specification for #{typename} #{scoped_lm_name}")
Expand All @@ -1327,7 +1327,7 @@ def set_component_and_key(comp, key)
end
@resolved_comp = comp.resolved_type.node
end
unless key && key.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::TemplateParam)
unless key&.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::TemplateParam)
## TODO : add check for Components::PrimaryKeyBase base type
unless key.nil? || (key.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::Valuetype))
raise "invalid primary key for #{typename} #{scoped_lm_name}: #{key.typename}"
Expand Down Expand Up @@ -2776,4 +2776,3 @@ def instantiate(instantiation_context, _enclosure)
end
end # Typedef
end

2 changes: 1 addition & 1 deletion lib/ridl/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def parse_annotation(in_comment = false)
@scan_comment = false
end
# check identifier for keywords
if token && token.first == :identifier
if token&.first == :identifier
# keyword check
if (a = KEYWORDS.assoc(token.last.to_s)).nil?
token = [ :identifier, Identifier.new(token.last.to_s, chk_identifier(token.last.to_s), token.last.unescaped_name) ]
Expand Down

0 comments on commit 547fd0f

Please sign in to comment.