Module: IMW::Metadata::DSL
- Included in:
- Dataset
- Defined in:
- lib/imw/metadata/dsl.rb
Overview
A module which defines a DSL that can be used to define metadata for an object.
Instance Method Summary collapse
- #field(name, options = {}) ⇒ Object
- #has_many(name, options = {}, &block) ⇒ Object
- #has_one(name, options = {}, &block) ⇒ Object
-
#metadata(arg = nil, options = {}, &block) ⇒ IMW::Metadata
When called without a block return this object’s metadata.
-
#open(uri, options = {}, &block) ⇒ IMW::Resource
Open a new resource at the given URI.
- #open!(uri, options = {}, &block) ⇒ Object
- #schema(resource, options = {}, &block) ⇒ Object
Instance Method Details
#field(name, options = {}) ⇒ Object
71 72 73 |
# File 'lib/imw/metadata/dsl.rb', line 71 def field name, ={} accumulate_field Field.new(.merge(:name => name)) end |
#has_many(name, options = {}, &block) ⇒ Object
81 82 83 84 85 |
# File 'lib/imw/metadata/dsl.rb', line 81 def has_many name, ={}, &block new_field_accumulator! yield accumulate_field Field.new(.merge(:name => name, :has_many => last_field_accumulator!)) end |
#has_one(name, options = {}, &block) ⇒ Object
75 76 77 78 79 |
# File 'lib/imw/metadata/dsl.rb', line 75 def has_one name, ={}, &block new_field_accumulator! yield accumulate_field Field.new(.merge(:name => name, :has_one => last_field_accumulator!)) end |
#metadata(arg = nil, options = {}, &block) ⇒ IMW::Metadata
When called without a block return this object’s metadata.
#=> { '/path/to/file' => [...], '/path/to/other/file' => [...], ... }
When called with a block, accumulate schema and fields into this object’s metadata
do
schema "/path/to/file" do
# ...
end
schema "/path/to/other/file" do
# ...
end
end
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/imw/metadata/dsl.rb', line 51 def arg=nil, ={}, &block case arg when Hash @metadata ||= Metadata.new(arg, ) when nil @metadata ||= Metadata.new nil, else @metadata ||= Metadata.load(arg, ) end @metadata.base = [:base] if [:base] return @metadata unless block_given? yield end |
#open(uri, options = {}, &block) ⇒ IMW::Resource
Open a new resource at the given URI.
If this dataset has metadata and it describes the resource then configure the resource to understand its schema..
The schema
property passed via the options hash will override this.
20 21 22 23 |
# File 'lib/imw/metadata/dsl.rb', line 20 def open uri, ={}, &block = ([:schema].nil? && && .describe?(uri)) ? {:schema => [uri]} : {} IMW.open(uri, .merge(), &block) end |
#open!(uri, options = {}, &block) ⇒ Object
25 26 27 |
# File 'lib/imw/metadata/dsl.rb', line 25 def open! uri, ={}, &block self.open(uri, .merge(:mode => 'w'), &block) end |