Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weather-model
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
weather-model
Commits
888f221b
Commit
888f221b
authored
May 15, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User WeatherModel instead of Weather::Model
parent
ec609d63
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
118 deletions
+21
-118
Untitled-1.rb
Untitled-1.rb
+0
-95
weather-model.rb
lib/weather-model.rb
+3
-7
engine.rb
lib/weather-model/engine.rb
+1
-4
source_schema.rb
lib/weather-model/source_schema.rb
+1
-3
storer.rb
lib/weather-model/storer.rb
+1
-3
version.rb
lib/weather-model/version.rb
+1
-3
weather-model_spec.rb
spec/weather-model_spec.rb
+14
-3
No files found.
Untitled-1.rb
deleted
100644 → 0
View file @
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"
lib/weather
/
model.rb
→
lib/weather
-
model.rb
View file @
888f221b
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
lib/weather
/
model/engine.rb
→
lib/weather
-
model/engine.rb
View file @
888f221b
module
Weather
module
Model
module
WeatherModel
class
Engine
<
Rails
::
Engine
end
end
end
\ No newline at end of file
lib/weather
/
model/source_schema.rb
→
lib/weather
-
model/source_schema.rb
View file @
888f221b
module
Weather
module
Model
module
WeatherModel
module
SourceSchema
ShanghaiTen
=
{
table_name: :forecasts
,
...
...
@@ -20,6 +19,5 @@ module Weather
}
}
end
end
end
lib/weather
/
model/storer.rb
→
lib/weather
-
model/storer.rb
View file @
888f221b
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
lib/weather
/
model/version.rb
→
lib/weather
-
model/version.rb
View file @
888f221b
module
Weather
module
Model
module
WeatherModel
VERSION
=
"0.1.0"
end
end
spec/weather
/
model_spec.rb
→
spec/weather
-
model_spec.rb
View file @
888f221b
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment