Class: Pants
- Inherits:
-
Object
- Object
- Pants
- Extended by:
- LogSwitch
- Defined in:
- lib/pants.rb,
lib/pants/core.rb,
lib/pants/seam.rb,
lib/pants/error.rb,
lib/pants/logger.rb,
lib/pants/version.rb,
lib/pants/network_helpers.rb,
lib/pants/readers/udp_reader.rb,
lib/pants/writers/udp_writer.rb,
lib/pants/readers/base_reader.rb,
lib/pants/readers/file_reader.rb,
lib/pants/writers/base_writer.rb,
lib/pants/writers/file_writer.rb
Overview
This base class provides some helpers for doing quick, non-complex reading and writing. Check docs on readers and writers for more information.
Defined Under Namespace
Modules: NetworkHelpers, Readers, Writers Classes: Core, Error, Seam
Constant Summary collapse
- DEFAULT_URI_TO_READER_MAP =
[ { uri_scheme: nil, klass: Pants::Readers::FileReader, args: [:path] }, { uri_scheme: 'file', klass: Pants::Readers::FileReader, args: [:path] }, { uri_scheme: 'udp', klass: Pants::Readers::UDPReader, args: [:host, :port] } ]
- DEFAULT_URI_TO_WRITER_MAP =
[ { uri_scheme: nil, klass: Pants::Writers::FileWriter, args: [:path] }, { uri_scheme: 'file', klass: Pants::Writers::FileWriter, args: [:path] }, { uri_scheme: 'udp', klass: Pants::Writers::UDPWriter, args: [:host, :port] } ]
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.read(uri, &block) ⇒ Object
Convenience method; doing something like:.
-
.readers ⇒ Array<Hash>
The list of mappings of URIs to Reader class types.
-
.writers ⇒ Array<Hash>
The list of mappings of URIs to Writer class types.
Class Method Details
.read(uri, &block) ⇒ Object
Convenience method; doing something like:
pants = Pants::Core.new
reader = pants.read('udp://0.0.0.0:1234')
reader.add_writer('udp://1.2.3.4:5999')
reader.add_writer('udp_data.raw')
pants.run
…becomes:
Pants.read('udp://0.0.0.1234') do |seam|
seam.add_writer('udp://1.2.3.4:5999')
seam.add_writer('udp_data.raw')
end
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pants.rb', line 73 def self.read(uri, &block) pants = Pants::Core.new(&block) if uri.kind_of? Pants::Readers::BaseReader pants.add_reader(uri) else pants.read(uri) end pants.run end |
.readers ⇒ Array<Hash>
The list of mappings of URIs to Reader class types. These mappings allow Pants to look up the URI scheme and find what type of object should be created when creating a Reader by giving it a URI. It also defines the arguments that the Reader class takes; these should Symbols that represent names of methods that can be called on objects of the URI type.
You can register new mappings here by pushing new mappings to the list. Mappings should be in the form:
{ uri_scheme: 'my_scheme', klass: MyReaderClass, args: [:arg] }
Note that if you’re wanting to add to this list, and URI doesn’t recognize the URI scheme that you’re adding for, you’ll need to define that within URI. An example is given here: www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI.html
If you want to use your own reader but don’t want to go through all of this hassle, you can add your reader using a different method. See the docs for Pants::Core for more info.
43 44 45 |
# File 'lib/pants.rb', line 43 def self.readers @readers ||= DEFAULT_URI_TO_READER_MAP end |
.writers ⇒ Array<Hash>
The list of mappings of URIs to Writer class types. See the docs for .readers for more info.
52 53 54 |
# File 'lib/pants.rb', line 52 def self.writers @writers ||= DEFAULT_URI_TO_WRITER_MAP end |