Commit 888f221b by ivan Lan

User WeatherModel instead of Weather::Model

parent ec609d63
module SourceSchema
ShanghaiTen = {
schema: {
date: :date,
cityname: :string,
temp_high: :string,
weather_text: :string,
},
options: {
index: [:cityname],
dad: nil,
son: nil
}
}
end
# ===> there need to be
# 先 定义类完成
# 再 检查对应数据表 并 创建 或 完善
Source::Mysql.subclasses.each do |source|
unless source.table_exists?
# create table
else
# update table
end
end
def self.check_table
# create_table
# 增减量
# attrs = self.attributes
# names_now = attrs.map(&:name)
# names_last = Schema.keys
# incr_column = ( names_now | names_last ) - names_last
# del_column = ( names_now | names_last ) - names_now
end
# ShanghaiTen
# create_table :deck_study_sessions do |t|
# t.integer :deck_id
# t.integer :study_session_id
# end
# class CreateDeckStudySessionsTable < ActiveRecord::Migration
# def up
# puts 'ran up method'
# end
# def down
# drop_table :deck_study_sessions
# puts 'ran down method'
# end
# end
# =====
# $ rake create migration
require "rails/generators/actions/create_migration"
migration_exists?('db/migrate/', 'create_sources')
migration_template local_file, "db/migrate/create_sources.rb"
require 'weather/model/version'
require 'weather-model/version'
module Weather
module Model
require 'source_schema'
module WeatherModel
require 'weather-model/source_schema'
def self.create_classes
Weather::Model::SourceSchema.each do |source|
Object.const_set("#{source}::Mysql", Class.new(Source::Mysql))
Object.const_set("#{source}::Ohm", Class.new(Source::Ohm))
end
end
end
end
module Weather
module Model
module WeatherModel
class Engine < Rails::Engine
end
end
end
\ No newline at end of file
module Weather
module Model
module WeatherModel
module SourceSchema
ShanghaiTen = {
table_name: :forecasts,
......@@ -20,6 +19,5 @@ module Weather
}
}
end
end
end
module Weather
module Model
module WeatherModel
module Storer
class Mysql < ActiveRecord::Base
@@source = self.name[0..-8]
......@@ -33,5 +32,4 @@ module Weather
end
end
end
end
end
module Weather
module Model
module WeatherModel
VERSION = "0.1.0"
end
end
require "spec_helper"
RSpec.describe Weather::Model do
require 'active_record'
RSpec.describe WeatherModel do
it "has a version number" do
expect(Weather::Model::VERSION).not_to be nil
expect(WeatherModel::VERSION).not_to be nil
end
it "does something useful" do
expect(false).to eq(true)
end
# before do
# # Dir['db/migrate/*.rb'].each { |file| require '../' + file }
# ActiveRecord::Base.establish_connection(
# :adapter => 'sqlite3',
# :database => 'weather-model-test.sqlite3'
# )
# CreateForecasts.migrate(:up)
# end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment