Skip to content

Commit

Permalink
Merge pull request #136 from transitland/feed-report-card-attrs
Browse files Browse the repository at this point in the history
expand Feed and Operator data models to support feed report attributes
  • Loading branch information
drewda committed Aug 17, 2015
2 parents 789ca09 + b0aab0b commit 66f85c0
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 46 deletions.
47 changes: 36 additions & 11 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
#
# Table name: feeds
#
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# license_name :string
# license_url :string
# license_use_without_attribution :string
# license_create_derived_product :string
# license_redistribute :string
#
# Indexes
#
Expand All @@ -32,6 +37,15 @@ class Feed < ActiveRecord::Base

validates :url, presence: true
validates :url, format: { with: URI.regexp }, if: Proc.new { |feed| feed.url.present? }
validates :license_url, format: { with: URI.regexp }, if: Proc.new { |feed| feed.license_url.present? }

extend Enumerize
enumerize :feed_format, in: [:gtfs]
enumerize :license_use_without_attribution, in: [:yes, :no, :unknown]
enumerize :license_create_derived_product, in: [:yes, :no, :unknown]
enumerize :license_redistribute, in: [:yes, :no, :unknown]

after_initialize :set_default_values

def fetch_and_check_for_updated_version
begin
Expand Down Expand Up @@ -101,4 +115,15 @@ def self.fetch_and_check_for_updated_version(feed_onestop_ids = [])
end
feeds_with_updated_versions
end

private

def set_default_values
if self.new_record?
self.feed_format ||= 'gtfs'
self.license_use_without_attribution ||= 'unknown'
self.license_create_derived_product ||= 'unknown'
self.license_redistribute ||= 'unknown'
end
end
end
7 changes: 7 additions & 0 deletions app/models/operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# version :integer
# identifiers :string default([]), is an Array
# timezone :string
# short_name :string
# website :string
# country :string
# state :string
# metro :string
#
# Indexes
#
Expand All @@ -29,6 +34,8 @@ class BaseOperator < ActiveRecord::Base
PER_PAGE = 50

attr_accessor :serves, :does_not_serve

validates :website, format: { with: URI.regexp }, if: Proc.new { |operator| operator.website.present? }
end

class Operator < BaseOperator
Expand Down
32 changes: 21 additions & 11 deletions app/serializers/feed_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
#
# Table name: feeds
#
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# license_name :string
# license_url :string
# license_use_without_attribution :string
# license_create_derived_product :string
# license_redistribute :string
#
# Indexes
#
Expand All @@ -26,6 +31,11 @@ class FeedSerializer < ApplicationSerializer
:feed_format,
:operator_onestop_ids_in_feed,
:tags,
:license_name,
:license_url,
:license_use_without_attribution,
:license_create_derived_product,
:license_redistribute,
:last_sha1,
:last_fetched_at,
:last_imported_at,
Expand Down
10 changes: 10 additions & 0 deletions app/serializers/operator_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# version :integer
# identifiers :string default([]), is an Array
# timezone :string
# short_name :string
# website :string
# country :string
# state :string
# metro :string
#
# Indexes
#
Expand All @@ -25,9 +30,14 @@

class OperatorSerializer < CurrentEntitySerializer
attributes :name,
:short_name,
:onestop_id,
:geometry,
:tags,
:website,
:country,
:state,
:metro,
:timezone,
:created_at,
:updated_at
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20150817150332_add_attributes_for_feed_report_card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AddAttributesForFeedReportCard < ActiveRecord::Migration
def change
add_column :feeds, :license_name, :string
add_column :feeds, :license_url, :string
add_column :feeds, :license_use_without_attribution, :string
add_column :feeds, :license_create_derived_product, :string
add_column :feeds, :license_redistribute, :string

[:current_operators, :old_operators].each do |table|
add_column table, :short_name, :string
add_column table, :website, :string
add_column table, :country, :string
add_column table, :state, :string
add_column table, :metro, :string
end
end
end
19 changes: 17 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150814191424) do
ActiveRecord::Schema.define(version: 20150817150332) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -46,6 +46,11 @@
t.integer "version"
t.string "identifiers", default: [], array: true
t.string "timezone"
t.string "short_name"
t.string "website"
t.string "country"
t.string "state"
t.string "metro"
end

add_index "current_operators", ["created_or_updated_in_changeset_id"], name: "#c_operators_cu_in_changeset_id_index", using: :btree
Expand Down Expand Up @@ -183,12 +188,17 @@
t.string "url"
t.string "feed_format"
t.hstore "tags"
t.string "operator_onestop_ids_in_feed", default: [], array: true
t.string "operator_onestop_ids_in_feed", default: [], array: true
t.string "last_sha1"
t.datetime "last_fetched_at"
t.datetime "last_imported_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "license_name"
t.string "license_url"
t.string "license_use_without_attribution"
t.string "license_create_derived_product"
t.string "license_redistribute"
end

add_index "feeds", ["onestop_id"], name: "index_feeds_on_onestop_id", using: :btree
Expand All @@ -207,6 +217,11 @@
t.integer "version"
t.string "identifiers", default: [], array: true
t.string "timezone"
t.string "short_name"
t.string "website"
t.string "country"
t.string "state"
t.string "metro"
end

add_index "old_operators", ["created_or_updated_in_changeset_id"], name: "o_operators_cu_in_changeset_id_index", using: :btree
Expand Down
27 changes: 16 additions & 11 deletions spec/factories/feed_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
#
# Table name: feeds
#
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# license_name :string
# license_url :string
# license_use_without_attribution :string
# license_create_derived_product :string
# license_redistribute :string
#
# Indexes
#
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/operator_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# version :integer
# identifiers :string default([]), is an Array
# timezone :string
# short_name :string
# website :string
# country :string
# state :string
# metro :string
#
# Indexes
#
Expand Down
27 changes: 16 additions & 11 deletions spec/models/feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
#
# Table name: feeds
#
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# id :integer not null, primary key
# onestop_id :string
# url :string
# feed_format :string
# tags :hstore
# operator_onestop_ids_in_feed :string default([]), is an Array
# last_sha1 :string
# last_fetched_at :datetime
# last_imported_at :datetime
# created_at :datetime
# updated_at :datetime
# license_name :string
# license_url :string
# license_use_without_attribution :string
# license_create_derived_product :string
# license_redistribute :string
#
# Indexes
#
Expand Down
5 changes: 5 additions & 0 deletions spec/models/operator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# version :integer
# identifiers :string default([]), is an Array
# timezone :string
# short_name :string
# website :string
# country :string
# state :string
# metro :string
#
# Indexes
#
Expand Down

0 comments on commit 66f85c0

Please sign in to comment.