diff options
| author | Luc Donnet | 2017-09-15 16:10:04 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-09-15 16:10:04 +0200 |
| commit | 6dd60124b8b136b4b32abb835b16588e1b2492c0 (patch) | |
| tree | 6b263e45de5e60865361fff2802b329ab9a464f9 | |
| parent | 9e48ab0851290c65daaf212e3178bed1536b0bd7 (diff) | |
| download | chouette-core-6dd60124b8b136b4b32abb835b16588e1b2492c0.tar.bz2 | |
Initialize first model for compliance_control STI Refs #3550 @4
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 3 | ||||
| -rw-r--r-- | app/models/compliance_control.rb | 5 | ||||
| -rw-r--r-- | app/models/generic_attribute_min_max.rb | 27 | ||||
| -rw-r--r-- | db/migrate/20170915100935_change_crticity_type_for_compliance_control.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 51 |
6 files changed, 53 insertions, 39 deletions
@@ -120,6 +120,7 @@ gem 'acts-as-taggable-on', '~> 4.0.0' gem 'acts_as_list', '~> 0.6.0' gem 'acts_as_tree', '~> 2.1.0', require: 'acts_as_tree' +gem "hstore_accessor", "~> 1.1" gem 'rabl' gem 'carrierwave', '~> 1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1e2ac3cf8..fef3270a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,6 +255,8 @@ GEM hashdiff (0.3.4) highline (1.7.8) hike (1.2.3) + hstore_accessor (1.1.0) + activerecord (>= 4.0.0) htmlbeautifier (1.3.1) httparty (0.14.0) multi_xml (>= 0.5.2) @@ -602,6 +604,7 @@ DEPENDENCIES georuby-ext (= 0.0.5) google-analytics-rails has_array_of! + hstore_accessor (~> 1.1) htmlbeautifier i18n-tasks inherited_resources diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb index 64556b524..12ff4737a 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -2,8 +2,11 @@ class ComplianceControl < ActiveRecord::Base belongs_to :compliance_control_set belongs_to :compliance_control_block - enum criticity: [:info, :warning, :error] + extend Enumerize + enumerize :criticity, in: %i(info warning error), scope: true, default: :info + validates :criticity, presence: true validates :name, presence: true validates :code, presence: true + validates :compliance_control_set, presence: true end diff --git a/app/models/generic_attribute_min_max.rb b/app/models/generic_attribute_min_max.rb new file mode 100644 index 000000000..e9a127c56 --- /dev/null +++ b/app/models/generic_attribute_min_max.rb @@ -0,0 +1,27 @@ +#module ComplianceControls + + class GenericAttributeMinMax < ComplianceControl + + + hstore_accessor :control_attributes, minimum: :integer, maximum: :integer + #attribute :minimum, type: :integer, optionnal: true + #attribute :maximum, type: :integer, optionnal: true + # #attribute :target, type: ModelAttribute + + @@default_criticity = :warning + @@default_code = "3-Generic-2" + + validate :min_max_values + def min_max_values + true + end + + after_initialize do + self.name = 'GenericAttributeMinMax' + self.code = @@default_code + self.criticity = @@default_criticity + end + + end + +#end diff --git a/db/migrate/20170915100935_change_crticity_type_for_compliance_control.rb b/db/migrate/20170915100935_change_crticity_type_for_compliance_control.rb new file mode 100644 index 000000000..f3e7e7339 --- /dev/null +++ b/db/migrate/20170915100935_change_crticity_type_for_compliance_control.rb @@ -0,0 +1,5 @@ +class ChangeCrticityTypeForComplianceControl < ActiveRecord::Migration + def change + change_column :compliance_controls, :criticity, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5e2edf33d..7b6731d3f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170913074922) do +ActiveRecord::Schema.define(version: 20170915100935) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -237,7 +237,7 @@ ActiveRecord::Schema.define(version: 20170913074922) do t.json "control_attributes" t.string "name" t.string "code" - t.integer "criticity" + t.string "criticity" t.text "comment" t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -270,22 +270,6 @@ ActiveRecord::Schema.define(version: 20170913074922) do add_index "connection_links", ["objectid"], name: "connection_links_objectid_key", unique: true, using: :btree - create_table "delayed_jobs", id: :bigserial, force: :cascade do |t| - t.integer "priority", default: 0 - t.integer "attempts", default: 0 - t.text "handler" - t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" - t.string "locked_by", limit: 255 - t.string "queue", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree - create_table "exports", id: :bigserial, force: :cascade do |t| t.integer "referential_id", limit: 8 t.string "status" @@ -407,11 +391,11 @@ ActiveRecord::Schema.define(version: 20170913074922) do t.datetime "started_at" t.datetime "ended_at" t.string "token_download" - t.string "type", limit: 255 + t.string "type" t.integer "parent_id", limit: 8 t.string "parent_type" - t.integer "current_step", default: 0 - t.integer "total_steps", default: 0 + t.integer "current_step", default: 0 + t.integer "total_steps", default: 0 t.datetime "notified_parent_at" t.string "creator" end @@ -564,11 +548,6 @@ ActiveRecord::Schema.define(version: 20170913074922) do add_index "networks", ["objectid"], name: "networks_objectid_key", unique: true, using: :btree add_index "networks", ["registration_number"], name: "networks_registration_number_key", using: :btree - create_table "object_id_factories", id: :bigserial, force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "organisations", id: :bigserial, force: :cascade do |t| t.string "name" t.datetime "created_at" @@ -745,7 +724,7 @@ ActiveRecord::Schema.define(version: 20170913074922) do create_table "stop_areas", id: :bigserial, force: :cascade do |t| t.integer "parent_id", limit: 8 - t.string "objectid", null: false + t.string "objectid", null: false t.integer "object_version", limit: 8 t.string "creator_id" t.string "name" @@ -754,8 +733,8 @@ ActiveRecord::Schema.define(version: 20170913074922) do t.string "registration_number" t.string "nearest_topic_name" t.integer "fare_code" - t.decimal "longitude", precision: 19, scale: 16 - t.decimal "latitude", precision: 19, scale: 16 + t.decimal "longitude", precision: 19, scale: 16 + t.decimal "latitude", precision: 19, scale: 16 t.string "long_lat_type" t.string "country_code" t.string "street_name" @@ -773,7 +752,7 @@ ActiveRecord::Schema.define(version: 20170913074922) do t.datetime "deleted_at" t.datetime "created_at" t.datetime "updated_at" - t.string "stif_type", limit: 255 + t.string "stif_type" end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree @@ -844,18 +823,18 @@ ActiveRecord::Schema.define(version: 20170913074922) do add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree create_table "time_tables", id: :bigserial, force: :cascade do |t| - t.string "objectid", null: false - t.integer "object_version", limit: 8, default: 1 + t.string "objectid", null: false + t.integer "object_version", limit: 8, default: 1 t.string "creator_id" t.string "version" t.string "comment" - t.integer "int_day_types", default: 0 + t.integer "int_day_types", default: 0 t.date "start_date" t.date "end_date" t.integer "calendar_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" - t.string "color", limit: 255 + t.string "color" t.integer "created_from_id" t.string "checksum" t.text "checksum_source" @@ -999,13 +978,9 @@ ActiveRecord::Schema.define(version: 20170913074922) do add_foreign_key "compliance_controls", "compliance_control_blocks" add_foreign_key "compliance_controls", "compliance_control_sets" add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", on_delete: :cascade - add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", on_delete: :nullify add_foreign_key "journey_frequencies", "timebands", on_delete: :nullify - add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", on_delete: :nullify add_foreign_key "journey_frequencies", "vehicle_journeys", on_delete: :nullify - add_foreign_key "journey_pattern_sections", "journey_patterns", name: "journey_pattern_sections_journey_pattern_id_fk", on_delete: :cascade add_foreign_key "journey_pattern_sections", "journey_patterns", on_delete: :cascade - add_foreign_key "journey_pattern_sections", "route_sections", name: "journey_pattern_sections_route_section_id_fk", on_delete: :cascade add_foreign_key "journey_pattern_sections", "route_sections", on_delete: :cascade add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", on_delete: :cascade add_foreign_key "journey_patterns", "stop_points", column: "arrival_stop_point_id", name: "arrival_point_fkey", on_delete: :nullify |
