From f62f6f2f6cc905875a8bdb65e75e62ba9831fc3d Mon Sep 17 00:00:00 2001 From: Rufus Post Date: Mon, 28 Feb 2011 11:07:07 +1100 Subject: [PATCH] rdoc fixes --- README.rdoc | 20 +++++++------------- lib/theman/agency.rb | 20 ++++++++++---------- lib/theman/agency/columns.rb | 10 +++++----- lib/theman/object.rb | 8 ++++++++ lib/theman/version.rb | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.rdoc b/README.rdoc index ec41540..227a0c3 100644 --- a/README.rdoc +++ b/README.rdoc @@ -20,8 +20,6 @@ Say we have a csv file called sample.csv 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 sample.csv 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 create! 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 create! 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. +add_primary_key!, this will add the agents_pkey column. == Drop on commit diff --git a/lib/theman/agency.rb b/lib/theman/agency.rb index dae7184..16e1aa0 100644 --- a/lib/theman/agency.rb +++ b/lib/theman/agency.rb @@ -11,7 +11,7 @@ class Agency # * +options+ - Additional options are :temporary, # :on_commit and :headers # - # ==== 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 diff --git a/lib/theman/agency/columns.rb b/lib/theman/agency/columns.rb index bfdb1b1..044bbb8 100644 --- a/lib/theman/agency/columns.rb +++ b/lib/theman/agency/columns.rb @@ -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 diff --git a/lib/theman/object.rb b/lib/theman/object.rb index c8b7d25..be18bda 100644 --- a/lib/theman/object.rb +++ b/lib/theman/object.rb @@ -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? diff --git a/lib/theman/version.rb b/lib/theman/version.rb index 5e640cb..3d4573d 100644 --- a/lib/theman/version.rb +++ b/lib/theman/version.rb @@ -1,3 +1,3 @@ module Theman - VERSION = "0.1.1" + VERSION = "0.1.2" end