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 WeatherModel
module Model require 'weather-model/source_schema'
require 'source_schema'
def self.create_classes def self.create_classes
Weather::Model::SourceSchema.each do |source| Weather::Model::SourceSchema.each do |source|
Object.const_set("#{source}::Mysql", Class.new(Source::Mysql)) Object.const_set("#{source}::Mysql", Class.new(Source::Mysql))
Object.const_set("#{source}::Ohm", Class.new(Source::Ohm)) Object.const_set("#{source}::Ohm", Class.new(Source::Ohm))
end end
end end
end
end end
module Weather module WeatherModel
module Model
class Engine < Rails::Engine class Engine < Rails::Engine
end end
end
end end
\ No newline at end of file
module Weather module WeatherModel
module Model
module SourceSchema module SourceSchema
ShanghaiTen = { ShanghaiTen = {
table_name: :forecasts, table_name: :forecasts,
...@@ -20,6 +19,5 @@ module Weather ...@@ -20,6 +19,5 @@ module Weather
} }
} }
end end
end
end end
module Weather module WeatherModel
module Model
module Storer module Storer
class Mysql < ActiveRecord::Base class Mysql < ActiveRecord::Base
@@source = self.name[0..-8] @@source = self.name[0..-8]
...@@ -33,5 +32,4 @@ module Weather ...@@ -33,5 +32,4 @@ module Weather
end end
end end
end end
end
end end
module Weather module WeatherModel
module Model
VERSION = "0.1.0" VERSION = "0.1.0"
end
end end
require "spec_helper" require "spec_helper"
require 'active_record'
RSpec.describe Weather::Model do RSpec.describe WeatherModel do
it "has a version number" do it "has a version number" do
expect(Weather::Model::VERSION).not_to be nil expect(WeatherModel::VERSION).not_to be nil
end end
it "does something useful" do it "does something useful" do
expect(false).to eq(true) expect(false).to eq(true)
end 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 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