Add method Referator::Command#data_kwargs!
This commit is contained in:
parent
d6a0c92252
commit
eedb9ede3d
|
@ -18,6 +18,12 @@ module Referator
|
|||
@data = freeze_data JSON.parse json
|
||||
end
|
||||
|
||||
def data_kwargs!
|
||||
raise 'Expected command data to be a hash' unless data.instance_of? Hash
|
||||
|
||||
@data_kwargs ||= data.transform_keys(&:to_sym).freeze
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def freeze_data(object)
|
||||
|
|
|
@ -45,7 +45,7 @@ module Referator
|
|||
##########
|
||||
|
||||
def do_register_script(command)
|
||||
@config.scripts.register(**command.data.transform_keys(&:to_sym))
|
||||
@config.scripts.register(**command.data_kwargs!)
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -55,12 +55,12 @@ module Referator
|
|||
end
|
||||
|
||||
def do_register_format(command)
|
||||
@config.formats.register(**command.data.transform_keys(&:to_sym))
|
||||
@config.formats.register(**command.data_kwargs!)
|
||||
nil
|
||||
end
|
||||
|
||||
def do_register_ref(command)
|
||||
@config.repo.register_ref(**command.data.transform_keys(&:to_sym))
|
||||
@config.repo.register_ref(**command.data_kwargs!)
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -70,7 +70,7 @@ module Referator
|
|||
|
||||
def do_ref(command)
|
||||
@config.freeze
|
||||
@config.repo[command.data['category'], command.data['id']].to_h
|
||||
@config.repo[*category_and_id(**command.data_kwargs!)].to_h
|
||||
end
|
||||
|
||||
############
|
||||
|
@ -79,7 +79,7 @@ module Referator
|
|||
|
||||
def do_make_ref(command)
|
||||
@config.freeze
|
||||
@footnotes.make_ref(command.data['category'], command.data['id']).to_h
|
||||
@footnotes.make_ref(*category_and_id(**command.data_kwargs!)).to_h
|
||||
end
|
||||
|
||||
#############
|
||||
|
@ -93,7 +93,7 @@ module Referator
|
|||
|
||||
def do_fetch_note(command)
|
||||
@config.freeze
|
||||
@footnotes.fetch_note(command.data['category'], command.data['id']).to_h
|
||||
@footnotes.fetch_note(*category_and_id(**command.data_kwargs!)).to_h
|
||||
end
|
||||
|
||||
def do_render_footnotes(command)
|
||||
|
@ -103,7 +103,13 @@ module Referator
|
|||
|
||||
def do_render_cite_sup(command)
|
||||
@config.freeze
|
||||
String @footnotes.render_cite_sup(**command.data.transform_keys(&:to_sym))
|
||||
String @footnotes.render_cite_sup(**command.data_kwargs!)
|
||||
end
|
||||
|
||||
#########
|
||||
# Utils #
|
||||
#########
|
||||
|
||||
def category_and_id(category:, id:) = [category, id]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue