lib/thinreports/layout/format.rb in thinreports-0.7.0 vs lib/thinreports/layout/format.rb in thinreports-0.7.5
- old
+ new
@@ -25,11 +25,10 @@
private
# @param [String] filename
# @param [Hash] options
# @option options [Boolean] :force (false)
- # @private
def build_internal(filename, options = {})
build_once(filename, options[:force]) do |content, id|
raw_format = parse_json(content)
# Check the compatibility of specified layout file.
@@ -37,21 +36,29 @@
info = [filename, raw_format['version'],
ThinReports::Layout::Version.inspect_required_rules]
raise ThinReports::Errors::IncompatibleLayoutFormat.new(*info)
end
+ compact_format!(raw_format)
+
# Build and initialize format.
new(raw_format, id) do |f|
build_layout(f) do |type, shape_format|
Core::Shape::Format(type).build(shape_format)
end
clean(f.layout)
end
end
end
- # @private
+ # @param [Hash] raw_format A parsed json.
+ def compact_format!(raw_format)
+ %w( finger-print state version ).each {|attr| raw_format.delete(attr) }
+ end
+
+ # @param [String] filename
+ # @param [Boolean] force (false)
def build_once(filename, force = false, &block)
content = read_format_file(filename)
if force
block.call(content, nil)
@@ -59,15 +66,16 @@
id = Digest::SHA1.hexdigest(content).to_sym
built_format_registry[id] ||= block.call(content, id)
end
end
- # @private
+ # @param [String] filename
+ # @return [String]
def read_format_file(filename)
File.open(filename, 'r:UTF-8') {|f| f.read }
end
- # @private
+ # @return [Hash]
def built_format_registry
@built_format_registry ||= {}
end
end
end