Module: ContentData
- Defined in:
- lib/content_data.rb,
lib/content_data/version.rb,
lib/content_data/content_data.rb,
lib/content_data/dynamic_content_data.rb
Overview
Data structure for an abstract layer over files. Each binary sequence is a content, each file is content instance.
Defined Under Namespace
Classes: Content, ContentData, ContentInstance, DynamicContentData
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
-
#validate(params = nil) ⇒ Boolean
Validates index against file system that all instances hold a correct data regarding files that they represrents.
Instance Method Details
#validate(params = nil) ⇒ Boolean
Validates index against file system that all instances hold a correct data regarding files that they represrents.
There are two levels of validation, controlled by instance_check_level system parameter:
-
shallow - quick, tests instance for file existence and attributes.
-
deep - can take more time, in addition to shallow recalculates hash sum.
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/content_data/content_data.rb', line 576 def validate(params = nil) # used to answer whether specific param was set param_exists = Proc.new do |param| !(params.nil? || params[param].nil?) end # used to process method parameters centrally process_params = Proc.new do |values| # values is a Hash with keys: :content, :instance and value appropriate to key if param_exists.call :failed unless values[:content].nil? params[:failed].add_content values[:content] end unless values[:instance].nil? # appropriate content should be already added params[:failed].add_instance values[:instance] end end end is_valid = true instances.each_value do |instance| unless check_instance instance is_valid = false unless params.nil? || params.empty? process_params.call :content => contents[instance.checksum], :instance => instance end end end is_valid end |