Methods

Class Index

Quicksearch

Arrow::DataSource::TestData

Locally-stored mock data to be used for testing purposes.

Attributes

data_path[RW]
The path where all stored TestData objects are located. Note that this isn‘t useful by default.
real_source[R]
The identifier string for the data being copied.

Public Class Methods

create(source, name) click to toggle source

Turns a normal DataSource object into a TestData object

     # File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 111
111:             def create(source, name)
112:                 testdata = self.new(source.source, name)
113:                 source.singleton_methods.each {|meth|
114:                     next if /=/.match(meth)
115:                     testdata.instance_eval "def \#{meth}; @\#{meth}; end\ndef \#{meth}=(o); @\#{meth} = o; end\n"
116:                     obj = source.send(meth)
117:                     testdata.send(meth+"=", obj)
118:                 }
119:             end
load(name) click to toggle source

Loads a test data file given by the name provided.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 95
 95:             def load(name)
 96:                 if File.exists?(name)
 97:                 elsif File.exists?(File.join(self.data_path, name))
 98:                     name = File.join(self.data_path, name)
 99:                 else
100:                     raise Arrow::LoadError.new( "No such testdata file to load: '%s'" % name )
101:                 end
102:                 data = nil
103:                 File.open(name) {|file|
104:                     data = file.read
105:                 }
106:                 obj = Yaml.load(data)
107:             end
new(source, name) click to toggle source

Creates a new TestData object with the given identifier, and either loads the pre-existing data from disk, or creates it.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 136
136:         def initialize(source, name)
137:             @real_source = source
138:             @source = source + "/" + name
139:         end

Public Instance Methods

save() click to toggle source

Saves the test data to the data directory.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 142
142:         def save 
143:             name = File.join(TestData.data_path,@source)
144:             File.new(name, "w") {|file|
145:                 file.write(@data.to_yaml)
146:             }
147:         end

secsequence

--- SEC00044

seccomment

--- ""

attributes

--- 
- name: data_path
  rw: RW
  a_desc: |+
    
    The path where all stored <a href="TestData.html">TestData</a> objects are
    located. Note that this isn&#8216;t useful by default.
    
- name: real_source
  rw: R
  a_desc: |+
    
    The identifier string for the data being copied.
    

method_list

--- 
- methods: 
  - visibility: public
    aref: M000381
    name: create
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 111</span>\n\
      111:             <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">create</span>(<span class=\"ruby-identifier\">source</span>, <span class=\"ruby-identifier\">name</span>)\n\
      112:                 <span class=\"ruby-identifier\">testdata</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">source</span>.<span class=\"ruby-identifier\">source</span>, <span class=\"ruby-identifier\">name</span>)\n\
      113:                 <span class=\"ruby-identifier\">source</span>.<span class=\"ruby-identifier\">singleton_methods</span>.<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">meth</span><span class=\"ruby-operator\">|</span>\n\
      114:                     <span class=\"ruby-keyword kw\">next</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-regexp re\">/=/</span>.<span class=\"ruby-identifier\">match</span>(<span class=\"ruby-identifier\">meth</span>)\n\
      115:                     <span class=\"ruby-identifier\">testdata</span>.<span class=\"ruby-identifier\">instance_eval</span> <span class=\"ruby-value str\">&quot;def \\#{meth}; @\\#{meth}; end\\ndef \\#{meth}=(o); @\\#{meth} = o; end\\n&quot;</span>\n\
      116:                     <span class=\"ruby-identifier\">obj</span> = <span class=\"ruby-identifier\">source</span>.<span class=\"ruby-identifier\">send</span>(<span class=\"ruby-identifier\">meth</span>)\n\
      117:                     <span class=\"ruby-identifier\">testdata</span>.<span class=\"ruby-identifier\">send</span>(<span class=\"ruby-identifier\">meth</span><span class=\"ruby-operator\">+</span><span class=\"ruby-value str\">&quot;=&quot;</span>, <span class=\"ruby-identifier\">obj</span>)\n\
      118:                 }\n\
      119:             <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Turns a normal <a href="../DataSource.html">DataSource</a> object into a <a
      href="TestData.html">TestData</a> object
      </p>
    params: (source, name)
  - visibility: public
    aref: M000380
    name: load
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 95</span>\n 95:             <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">load</span>(<span class=\"ruby-identifier\">name</span>)\n 96:                 <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">exists?</span>(<span class=\"ruby-identifier\">name</span>)\n 97:                 <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">exists?</span>(<span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">data_path</span>, <span class=\"ruby-identifier\">name</span>))\n 98:                     <span class=\"ruby-identifier\">name</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">data_path</span>, <span class=\"ruby-identifier\">name</span>)\n 99:                 <span class=\"ruby-keyword kw\">else</span>\n\
      100:                     <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">LoadError</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-value str\">&quot;No such testdata file to load: '%s'&quot;</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">name</span> )\n\
      101:                 <span class=\"ruby-keyword kw\">end</span>\n\
      102:                 <span class=\"ruby-identifier\">data</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      103:                 <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">open</span>(<span class=\"ruby-identifier\">name</span>) {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">file</span><span class=\"ruby-operator\">|</span>\n\
      104:                     <span class=\"ruby-identifier\">data</span> = <span class=\"ruby-identifier\">file</span>.<span class=\"ruby-identifier\">read</span>\n\
      105:                 }\n\
      106:                 <span class=\"ruby-identifier\">obj</span> = <span class=\"ruby-constant\">Yaml</span>.<span class=\"ruby-identifier\">load</span>(<span class=\"ruby-identifier\">data</span>)\n\
      107:             <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Loads a test data file given by the name provided.
      </p>
    params: (name)
  - visibility: public
    aref: M000382
    name: new
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 136</span>\n\
      136:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>(<span class=\"ruby-identifier\">source</span>, <span class=\"ruby-identifier\">name</span>)\n\
      137:             <span class=\"ruby-ivar\">@real_source</span> = <span class=\"ruby-identifier\">source</span>\n\
      138:             <span class=\"ruby-ivar\">@source</span> = <span class=\"ruby-identifier\">source</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">&quot;/&quot;</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">name</span>\n\
      139:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Creates a <a href="TestData.html#M000382">new</a> <a
      href="TestData.html">TestData</a> object with the given identifier, and
      either loads the pre-existing data from disk, or creates it.
      </p>
    params: (source, name)
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000383
    name: save
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/datasource.rb, line 142</span>\n\
      142:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">save</span> \n\
      143:             <span class=\"ruby-identifier\">name</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-constant\">TestData</span>.<span class=\"ruby-identifier\">data_path</span>,<span class=\"ruby-ivar\">@source</span>)\n\
      144:             <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-value str\">&quot;w&quot;</span>) {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">file</span><span class=\"ruby-operator\">|</span>\n\
      145:                 <span class=\"ruby-identifier\">file</span>.<span class=\"ruby-identifier\">write</span>(<span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">to_yaml</span>)\n\
      146:             }\n\
      147:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Saves the test data to the data directory.
      </p>
    params: ()
  category: Instance
  type: Public

sectitle

--- 

aliases

--- 
- old_name: load
  new_name: "[]"

[Validate]

Generated with the Darkfish Rdoc Generator.