bluepan-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +37 -0
- data/app/assets/stylesheets/bluepan_rails/application.css +15 -0
- data/app/controllers/bluepan/application_controller.rb +4 -0
- data/app/helpers/bluepan/application_helper.rb +4 -0
- data/app/jobs/bluepan/application_job.rb +7 -0
- data/app/jobs/bluepan/sync_cities_job.rb +9 -0
- data/app/jobs/bluepan/sync_provinces_job.rb +9 -0
- data/app/models/bluepan/city.rb +7 -0
- data/app/models/bluepan/province.rb +7 -0
- data/app/services/bluepan/create_or_update_cities.rb +15 -0
- data/app/services/bluepan/create_or_update_city.rb +25 -0
- data/app/services/bluepan/create_or_update_province.rb +20 -0
- data/app/services/bluepan/create_or_update_provinces.rb +15 -0
- data/app/services/bluepan/enqueue_sync_cities_job.rb +12 -0
- data/app/services/bluepan/get_cities.rb +13 -0
- data/app/services/bluepan/get_provinces.rb +13 -0
- data/app/services/bluepan/initialize_bluepan_client.rb +15 -0
- data/app/services/bluepan/load_sidekiq_cron_schedule.rb +13 -0
- data/app/services/bluepan/sync_cities.rb +15 -0
- data/app/services/bluepan/sync_city.rb +13 -0
- data/app/services/bluepan/sync_province.rb +14 -0
- data/app/services/bluepan/sync_provinces.rb +15 -0
- data/app/views/layouts/bluepan/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/config/sidekiq_cron.yml +3 -0
- data/db/migrate/20161111021217_create_bluepan_provinces.rb +13 -0
- data/db/migrate/20161111084120_create_bluepan_cities.rb +11 -0
- data/lib/bluepan-rails.rb +1 -0
- data/lib/bluepan.rb +13 -0
- data/lib/bluepan/engine.rb +5 -0
- data/lib/bluepan/factories.rb +16 -0
- data/lib/bluepan/version.rb +3 -0
- data/lib/tasks/bluepan_rails_tasks.rake +4 -0
- metadata +232 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1015928b0b69557980295f8c6cd4da2ff8c84517
|
4
|
+
data.tar.gz: 647a4fe392ba7fa6a289e1b3f75b195bcdb69a6c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c65e803f7b0319d2359517e0be3fb484139bc7e28f9acbdfcbd3a025391b0b34a893b66a5fbe7653491f80a17374bb04c17eb5d441332bd6d07a09c6fffaac2
|
7
|
+
data.tar.gz: c21db593d6f4f4c83d962835a1481cd3e9d8adaf1a90bbffb8338c7f00d2638e1f43abdba5cc129efbf7aa63eac1f05bcabffca9c495d02f121a28daca3729d2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Ramon Tayag
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Bluepan'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bluepan
|
2
|
+
class CreateOrUpdateCities
|
3
|
+
|
4
|
+
extend LightService::Action
|
5
|
+
expects :remote_cities
|
6
|
+
promises :cities
|
7
|
+
|
8
|
+
executed do |c|
|
9
|
+
c.cities = c.remote_cities.map do |remote_city|
|
10
|
+
SyncCity.(remote_city)[:city]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bluepan
|
2
|
+
class CreateOrUpdateCity
|
3
|
+
|
4
|
+
extend LightService::Action
|
5
|
+
expects :remote_city
|
6
|
+
promises :city
|
7
|
+
|
8
|
+
executed do |c|
|
9
|
+
province = Bluepan::Province.
|
10
|
+
find_by!(external_id: c.remote_city.provinceseq)
|
11
|
+
|
12
|
+
city = province.cities.
|
13
|
+
where(external_id: c.remote_city.cityseq).
|
14
|
+
first_or_initialize
|
15
|
+
|
16
|
+
city.update_attributes!(
|
17
|
+
name_en: c.remote_city.cityname_en,
|
18
|
+
name_cn: c.remote_city.cityname_cn,
|
19
|
+
)
|
20
|
+
|
21
|
+
c.city = city
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Bluepan
|
2
|
+
class CreateOrUpdateProvince
|
3
|
+
|
4
|
+
extend LightService::Action
|
5
|
+
expects :remote_province
|
6
|
+
promises :province
|
7
|
+
|
8
|
+
executed do |c|
|
9
|
+
province = Bluepan::Province.
|
10
|
+
where(external_id: c.remote_province.provinceseq).
|
11
|
+
first_or_initialize
|
12
|
+
province.update_attributes!(
|
13
|
+
name_en: c.remote_province.provincename_en,
|
14
|
+
name_cn: c.remote_province.provincename_cn,
|
15
|
+
)
|
16
|
+
c.province = province
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bluepan
|
2
|
+
class CreateOrUpdateProvinces
|
3
|
+
|
4
|
+
extend LightService::Action
|
5
|
+
expects :remote_provinces
|
6
|
+
promises :provinces
|
7
|
+
|
8
|
+
executed do |c|
|
9
|
+
c.provinces = c.remote_provinces.map do |remote_province|
|
10
|
+
SyncProvince.(remote_province)[:province]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Bluepan
|
2
|
+
class LoadSidekiqCronSchedule
|
3
|
+
|
4
|
+
def self.call
|
5
|
+
schedule_file = Bluepan::Engine.root.join("config", "sidekiq_cron.yml")
|
6
|
+
|
7
|
+
return nil if !File.exists?(schedule_file) || !Sidekiq.server?
|
8
|
+
|
9
|
+
Sidekiq::Cron::Job.load_from_hash(YAML.load_file(schedule_file))
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Bluepan</title>
|
5
|
+
<%= stylesheet_link_tag "bluepan/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "bluepan/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateBluepanProvinces < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :bluepan_provinces do |t|
|
4
|
+
t.integer :external_id
|
5
|
+
t.string :name_en
|
6
|
+
t.string :name_cn
|
7
|
+
|
8
|
+
t.timestamps null: false
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :bluepan_provinces, :external_id
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "bluepan"
|
data/lib/bluepan.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :bluepan_province, class: "Bluepan::Province" do
|
4
|
+
sequence(:external_id) { |n| n }
|
5
|
+
name_en "English Name"
|
6
|
+
name_cn "Chinese Name"
|
7
|
+
end
|
8
|
+
|
9
|
+
factory :bluepan_city, class: "Bluepan::City" do
|
10
|
+
sequence(:province_id) { |n| n }
|
11
|
+
sequence(:external_id) { |n| n }
|
12
|
+
name_en "English Name"
|
13
|
+
name_cn "Chinese Name"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bluepan-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramon Tayag
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: light-service
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bluepan_client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: factory_girl_rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: shoulda-matchers
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: vcr
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: database_cleaner
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: Rails Engine for use with Bluepan
|
168
|
+
email:
|
169
|
+
- ramon.tayag@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- MIT-LICENSE
|
175
|
+
- Rakefile
|
176
|
+
- app/assets/stylesheets/bluepan_rails/application.css
|
177
|
+
- app/controllers/bluepan/application_controller.rb
|
178
|
+
- app/helpers/bluepan/application_helper.rb
|
179
|
+
- app/jobs/bluepan/application_job.rb
|
180
|
+
- app/jobs/bluepan/sync_cities_job.rb
|
181
|
+
- app/jobs/bluepan/sync_provinces_job.rb
|
182
|
+
- app/models/bluepan/city.rb
|
183
|
+
- app/models/bluepan/province.rb
|
184
|
+
- app/services/bluepan/create_or_update_cities.rb
|
185
|
+
- app/services/bluepan/create_or_update_city.rb
|
186
|
+
- app/services/bluepan/create_or_update_province.rb
|
187
|
+
- app/services/bluepan/create_or_update_provinces.rb
|
188
|
+
- app/services/bluepan/enqueue_sync_cities_job.rb
|
189
|
+
- app/services/bluepan/get_cities.rb
|
190
|
+
- app/services/bluepan/get_provinces.rb
|
191
|
+
- app/services/bluepan/initialize_bluepan_client.rb
|
192
|
+
- app/services/bluepan/load_sidekiq_cron_schedule.rb
|
193
|
+
- app/services/bluepan/sync_cities.rb
|
194
|
+
- app/services/bluepan/sync_city.rb
|
195
|
+
- app/services/bluepan/sync_province.rb
|
196
|
+
- app/services/bluepan/sync_provinces.rb
|
197
|
+
- app/views/layouts/bluepan/application.html.erb
|
198
|
+
- config/routes.rb
|
199
|
+
- config/sidekiq_cron.yml
|
200
|
+
- db/migrate/20161111021217_create_bluepan_provinces.rb
|
201
|
+
- db/migrate/20161111084120_create_bluepan_cities.rb
|
202
|
+
- lib/bluepan-rails.rb
|
203
|
+
- lib/bluepan.rb
|
204
|
+
- lib/bluepan/engine.rb
|
205
|
+
- lib/bluepan/factories.rb
|
206
|
+
- lib/bluepan/version.rb
|
207
|
+
- lib/tasks/bluepan_rails_tasks.rake
|
208
|
+
homepage: https://github.com/imacchiato/bluepan-rails
|
209
|
+
licenses:
|
210
|
+
- MIT
|
211
|
+
metadata: {}
|
212
|
+
post_install_message:
|
213
|
+
rdoc_options: []
|
214
|
+
require_paths:
|
215
|
+
- lib
|
216
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
|
+
requirements:
|
223
|
+
- - ">="
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
version: '0'
|
226
|
+
requirements: []
|
227
|
+
rubyforge_project:
|
228
|
+
rubygems_version: 2.5.1
|
229
|
+
signing_key:
|
230
|
+
specification_version: 4
|
231
|
+
summary: Rails Engine for use with Bluepan
|
232
|
+
test_files: []
|