lib/transcriber/resource.rb in transcriber-0.0.13 vs lib/transcriber/resource.rb in transcriber-0.0.14
- old
+ new
@@ -50,15 +50,15 @@
def self.not_allowed_names
%w(resource_id resource link)
end
- def to_input
+ def to_input(options = {})
input = {}
- self.class.keys.each do |key|
+ keys_to_input(options).each do |key|
value = __send__("#{key.name}")
- parsed_value = key.to_input(value)
+ parsed_value = key.to_input(value, options.fetch(key.name, {}))
path = key.input_path
if path.any?
last = path.pop
key_input = path.inject(input) {|buffer, key| buffer[key] = {}; buffer[key]}
@@ -66,8 +66,17 @@
else
input.merge!(parsed_value)
end
end
input.with_indifferent_access
+ end
+
+ private
+
+ def keys_to_input(options)
+ self.class.keys.clone.tap do |keys|
+ keys.reject! {|k| k.kind_of?(Relation)} unless options.fetch(:relations, true)
+ keys.reject! {|k| Array(options[:without]).include?(k.name)}
+ end
end
end
end