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
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
172 deletions
+77
-172
Untitled-1.rb
Untitled-1.rb
+0
-95
weather-model.rb
lib/weather-model.rb
+8
-12
engine.rb
lib/weather-model/engine.rb
+3
-4
source_schema.rb
lib/weather-model/source_schema.rb
+21
-23
storer.rb
lib/weather-model/storer.rb
+29
-31
version.rb
lib/weather-model/version.rb
+2
-4
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'
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
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
end
lib/weather
/
model/engine.rb
→
lib/weather
-
model/engine.rb
View file @
888f221b
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
lib/weather
/
model/source_schema.rb
→
lib/weather
-
model/source_schema.rb
View file @
888f221b
module
Weather
module
WeatherModel
module
Model
module
SourceSchema
module
SourceSchema
ShanghaiTen
=
{
ShanghaiTen
=
{
table_name: :forecasts
,
table_name: :forecasts
,
schema:
{
schema:
{
datetime: :datetime
,
datetime: :datetime
,
cityname: :string
,
cityname: :string
,
temp_high: :string
,
temp_high: :string
,
temp_low: :string
,
temp_low: :string
,
weather_text: :string
,
weather_text: :string
,
weather_pic: :string
,
weather_pic: :string
,
win_dir: :string
,
win_dir: :string
,
win_speed: :string
,
win_speed: :string
,
},
},
options:
{
options:
{
index:
[
:cityname
],
index:
[
:cityname
],
father:
nil
,
father:
nil
,
son:
nil
son:
nil
}
}
}
}
end
end
end
end
end
lib/weather
/
model/storer.rb
→
lib/weather
-
model/storer.rb
View file @
888f221b
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
]
@@settings
=
Source
::
Schema
.
const_get
(
self
.
name
[
0
..-
8
])
@@settings
=
Source
::
Schema
.
const_get
(
self
.
name
[
0
..-
8
])
self
.
table_name
=
@@settings
[
:table_name
]
self
.
table_name
=
@@settings
[
:table_name
]
end
end
class
Ohm
<
Ohm
::
Model
class
Ohm
<
Ohm
::
Model
require
"ohm/expire"
require
"ohm/expire"
include
Ohm
::
Expire
include
Ohm
::
Expire
TTL
=
5
TTL
=
5
attribute
Schema
.
keys
attribute
Schema
.
keys
[
:index
,
:unique
].
each
do
|
x
|
[
:index
,
:unique
].
each
do
|
x
|
method
(
x
).
call
Schema
::
Setting
[
x
]
method
(
x
).
call
Schema
::
Setting
[
x
]
end
end
expire
TTL
expire
TTL
private
private
def
son
his_son
# input like :Post
def
son
his_son
# input like :Post
# collection :posts, :Post
# collection :posts, :Post
collection
(
his_son
.
to_s
.
underscore
.
pluralize
.
to_sym
,
his_son
)
if
SourceSchema
.
const_defined?
(
his_son
)
collection
(
his_son
.
to_s
.
underscore
.
pluralize
.
to_sym
,
his_son
)
if
SourceSchema
.
const_defined?
(
his_son
)
end
end
def
dad
his_dad
# input like :Post
def
dad
his_dad
# input like :Post
# reference :post, :Post
# reference :post, :Post
reference
(
his_dad
.
to_s
.
underscore
.
to_sym
,
his_dad
)
if
his_dad
SourceSchema
.
const_defined?
(
his_son
)
reference
(
his_dad
.
to_s
.
underscore
.
to_sym
,
his_dad
)
if
his_dad
SourceSchema
.
const_defined?
(
his_son
)
end
end
end
end
end
end
end
end
end
lib/weather
/
model/version.rb
→
lib/weather
-
model/version.rb
View file @
888f221b
module
Weather
module
WeatherModel
module
Model
VERSION
=
"0.1.0"
VERSION
=
"0.1.0"
end
end
end
spec/weather
/
model_spec.rb
→
spec/weather
-
model_spec.rb
View file @
888f221b
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
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