Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rdoc fixes

  • Loading branch information...
commit f62f6f2f6cc905875a8bdb65e75e62ba9831fc3d 1 parent c9addec
Rufus Post authored
20 README.rdoc
View
@@ -20,8 +20,6 @@ Say we have a csv file called <tt>sample.csv</tt> with 220 rows:
res = conn.exec("SELECT count(*) FROM #{agent.table_name}")
res.getvalue(0,0)
- => 220
-
== Basic usage with Active Record and a simple object
conn = ActiveRecord::Base.connection.raw_connection
@@ -29,22 +27,20 @@ Say we have a csv file called <tt>sample.csv</tt> with 220 rows:
agent = Theman::Agency.new(conn, 'sample.csv')
agent.create!
- model = Theman::Object(agent.table_name, ActiveRecord::Base)
+ model = Theman::Object.new(agent.table_name, ActiveRecord::Base)
model.count
- => 220
-
== Advanced usage with Active Record and an existing model
Theman will call the <tt>create!</tt> method if you pass in a block.
conn = ActiveRecord::Base.connection.raw_connection
- agent = Theman::Agency.new conn, 'ugly.csv' |ag|
- ag.nulls /"N"/, /"UNKNOWN"/, /""/
- ag.seds "-n -e :a -e '1,15!{P;N;D;};N;ba'"
- ag.delimiter "|"
- ag.table do |t|
+ agent = Theman::Agency.new conn, 'ugly.csv' do |smith|
+ smith.nulls /"N"/, /"UNKNOWN"/, /""/
+ smith.seds "-n -e :a -e '1,15!{P;N;D;};N;ba'"
+ smith.delimiter "|"
+ smith.table do |t|
t.string :name, :limit => 50
t.date :date
t.integer :ext_id
@@ -56,8 +52,6 @@ Theman will call the <tt>create!</tt> method if you pass in a block.
MyModel.table_name = agent.table_name
MyModel.where(:exited => true).count
- => 220
-
In the above example we omitted the last 15 rows, made some things null and
specified some column data types.
@@ -65,7 +59,7 @@ If you do not provide a table block your columns will be VARCHAR(255); you
can cherry pick the columns that you want to change the data types for.
The temp table has no id column by default, but you can add one by calling
-+add_primary_key!+, this will add the +agents_pkey+ column.
+<tt>add_primary_key!</tt>, this will add the <tt>agents_pkey</tt> column.
== Drop on commit
20 lib/theman/agency.rb
View
@@ -11,7 +11,7 @@ class Agency
# * +options+ - Additional options are <tt>:temporary</tt>,
# <tt>:on_commit</tt> and <tt>:headers</tt>
#
- # ==== Examples
+ # ==== Example
# # Update all customers with the given attributes
# conn = PGconn.open(:dbname => 'test')
# agent = Theman::Agency.new(conn, 'sample.csv')
@@ -40,14 +40,14 @@ def transaction(&block)
connection.exec "COMMIT;"
end
- def create_stream_columns #:nodoc
+ def create_stream_columns #:nodoc:
@stream_columns_set = true
headers.split(delimiter_regexp).each do |column|
@columns.string column
end
end
- def headers #:nodoc
+ def headers #:nodoc:
File.open(@stream, "r"){ |infile| infile.gets }
end
@@ -83,7 +83,7 @@ def delimiter(arg)
@delimiter = arg
end
- def psql_copy(psql = []) #:nodoc
+ def psql_copy(psql = []) #:nodoc:
psql << "COPY #{table_name} FROM STDIN WITH"
psql << "DELIMITER '#{@delimiter}'" unless @delimiter.nil?
psql << "CSV"
@@ -91,25 +91,25 @@ def psql_copy(psql = []) #:nodoc
psql
end
- def psql_command(psql = []) #:nodoc
+ def psql_command(psql = []) #:nodoc:
psql << "SET DATESTYLE TO #{@datestyle}" unless @datestyle.nil?
psql << psql_copy.join(" ")
psql
end
- def sed_command(sed = []) #:nodoc
+ def sed_command(sed = []) #:nodoc:
sed << nulls_to_sed unless @nulls.nil?
sed << @seds unless @seds.nil?
sed
end
- def nulls_to_sed #:nodoc
+ def nulls_to_sed #:nodoc:
@nulls.map do |regex|
"-e 's/#{regex.source}//g'"
end
end
- def delimiter_regexp #:nodoc
+ def delimiter_regexp #:nodoc:
@delimiter_regexp ||= Regexp.new(@delimiter.nil? ? "," : "\\#{@delimiter}")
end
@@ -143,7 +143,7 @@ def drop!
@table_name = nil
end
- def system_command #:nodoc
+ def system_command #:nodoc:
unless sed_command.empty?
"cat #{@stream} | sed #{sed_command.join(" | sed ")}"
else
@@ -151,7 +151,7 @@ def system_command #:nodoc
end
end
- def pipe_it(l = "") #:nodoc
+ def pipe_it(l = "") #:nodoc:
connection.exec psql_command.join("; ")
f = IO.popen(system_command)
begin
10 lib/theman/agency/columns.rb
View
@@ -9,7 +9,7 @@ def initialize(conn)
@columns = []
end
- def to_sql #:nodoc
+ def to_sql #:nodoc:
@columns.map{|column| column_to_sql(*column)}.join(', ')
end
@@ -21,11 +21,11 @@ def #{type}(name, *args)
EOV
end
- def symbolize(name) #:nodoc
+ def symbolize(name) #:nodoc:
name.is_a?(Symbol) ? name : name.gsub(/ /,"_").gsub(/\W/, "").downcase.to_sym
end
- def column(name, type, *args) #:nodoc
+ def column(name, type, *args) #:nodoc:
sym_col = symbolize(name)
@columns.each_with_index do |column, index|
if column[0] == sym_col
@@ -40,7 +40,7 @@ def include?(sym_col)
@columns.map{|column| column[0] }.include?(sym_col)
end
- def column_to_sql(name, type, options = {}) #:nodoc
+ def column_to_sql(name, type, options = {}) #:nodoc:
sql = [quote_column_name(name)]
case type
when 'integer'
@@ -91,7 +91,7 @@ def column_to_sql(name, type, options = {}) #:nodoc
sql.join(' ')
end
- def quote_column_name(name) #:nodoc
+ def quote_column_name(name) #:nodoc:
@connection.quote_ident(name.to_s)
end
end
8 lib/theman/object.rb
View
@@ -1,5 +1,13 @@
module Theman
class Object
+ # create a new basic model object
+ # ==== Parameters
+ # * +table_name+ - the name of the table created by Theman::Agency
+ # * +parent+ - optional parent object for the new basic model object
+ # usually ActiveRecord::Base
+ # * +conn+ - optional pg connection
+ # ==== Example
+ # my_model = Theman::Object.new(agent.table_name, ActiveRecord::Base)
def self.new(table_name, parent = ::Object, conn = nil)
Class.new(parent) do
unless conn.nil?
2  lib/theman/version.rb
View
@@ -1,3 +1,3 @@
module Theman
- VERSION = "0.1.1"
+ VERSION = "0.1.2"
end
Please sign in to comment.
Something went wrong with that request. Please try again.