diff options
160 files changed, 3211 insertions, 4046 deletions
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index bc5bedd7f..ec695bcbf 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -77,7 +77,7 @@ class CompaniesController < InheritedResources::Base def decorate_companies(companies) ModelDecorator.decorate( companies, - with: CompanyDecorator, + with: Chouette::CompanyDecorator, context: { referential: line_referential } diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb index 546158fa8..f217dccb3 100644 --- a/app/controllers/journey_patterns_collections_controller.rb +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -48,7 +48,7 @@ class JourneyPatternsCollectionsController < ChouetteController end def user_permissions - policy = policy(:journey_pattern) + policy = policy(:"chouette/journey_pattern") @perms = %w{create destroy update}.inject({}) do | permissions, action | permissions.merge( "journey_patterns.#{action}" => policy.authorizes_action?(action) ) diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index cf2908500..49a8ca2c5 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -15,7 +15,7 @@ class LinesController < InheritedResources::Base index! do |format| @lines = ModelDecorator.decorate( @lines, - with: LineDecorator, + with: Chouette::LineDecorator, context: { line_referential: @line_referential, current_organisation: current_organisation diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index 98c840777..d90af0ed8 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -85,7 +85,7 @@ class NetworksController < InheritedResources::Base def decorate_networks(networks) ModelDecorator.decorate( networks, - with: NetworkDecorator, + with: Chouette::NetworkDecorator, context: { line_referential: line_referential } diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index b9f8c0050..75e574da3 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -29,7 +29,7 @@ class ReferentialLinesController < ChouetteController @routes = ModelDecorator.decorate( @routes, - with: RouteDecorator, + with: Chouette::RouteDecorator, context: { referential: referential, line: @line diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 93f30f4d5..bf3078c59 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -48,7 +48,7 @@ class RoutesController < ChouetteController @route_sp = ModelDecorator.decorate( @route_sp, - with: StopPointDecorator + with: Chouette::StopPointDecorator ) end end diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index 6c3da5980..8261373a6 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -14,7 +14,7 @@ class RoutingConstraintZonesController < ChouetteController index! do |format| @routing_constraint_zones = ModelDecorator.decorate( @routing_constraint_zones, - with: RoutingConstraintZoneDecorator, + with: Chouette::RoutingConstraintZoneDecorator, context: { referential: referential, line: parent diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 1d6f88068..2732c5f99 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -56,7 +56,7 @@ class StopAreasController < InheritedResources::Base @stop_areas = ModelDecorator.decorate( @stop_areas, - with: StopAreaDecorator + with: Chouette::StopAreaDecorator ) } end diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0c1769ad7..34b1ca89d 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -168,7 +168,7 @@ class TimeTablesController < ChouetteController def decorate_time_tables(time_tables) ModelDecorator.decorate( time_tables, - with: TimeTableDecorator, + with: Chouette::TimeTableDecorator, context: { referential: @referential } diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index 050f2f219..e74957ffc 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -158,7 +158,7 @@ class VehicleJourneysController < ChouetteController end def user_permissions - policy = policy(:vehicle_journey) + policy = policy(:"chouette/vehicle_journey") @perms = %w{create destroy update}.inject({}) do | permissions, action | permissions.merge( "vehicle_journeys.#{action}" => policy.authorizes_action?(action) ) diff --git a/app/decorators/chouette/company_decorator.rb b/app/decorators/chouette/company_decorator.rb index adf1e856f..e6353f009 100644 --- a/app/decorators/chouette/company_decorator.rb +++ b/app/decorators/chouette/company_decorator.rb @@ -1,53 +1,54 @@ -class Chouette::CompanyDecorator < Draper::Decorator - decorates Chouette::Company +module Chouette + class CompanyDecorator < Draper::Decorator + decorates Chouette::Company - delegate_all + delegate_all - def self.collection_decorator_class - PaginatingDecorator - end - - def linecount - object.lines.count - end + def self.collection_decorator_class + PaginatingDecorator + end - # Requires: - # context: { - # referential: - # } - def action_links - links = [] - - if h.policy(Chouette::Company).create? - links << Link.new( - content: h.t('companies.actions.new'), - href: h.new_line_referential_company_path(context[:referential]) - ) + def linecount + object.lines.count end - if h.policy(object).update? - links << Link.new( - content: h.t('companies.actions.edit'), - href: h.edit_line_referential_company_path( - context[:referential], - object + # Requires: + # context: { + # referential: + # } + def action_links + links = [] + + if h.policy(Chouette::Company).create? + links << Link.new( + content: h.t('companies.actions.new'), + href: h.new_line_referential_company_path(context[:referential]) ) - ) - end + end + + if h.policy(object).update? + links << Link.new( + content: h.t('companies.actions.edit'), + href: h.edit_line_referential_company_path( + context[:referential], + object + ) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: t('companies.actions.destroy'), + href: h.line_referential_company_path( + context[:referential], + object + ), + method: :delete, + data: { confirm: h.t('companies.actions.destroy_confirm') } + ) + end - if h.policy(object).destroy? - links << Link.new( - content: t('companies.actions.destroy'), - href: h.line_referential_company_path( - context[:referential], - object - ), - method: :delete, - data: { confirm: h.t('companies.actions.destroy_confirm') } - ) + links end - - links end - -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/line_decorator.rb b/app/decorators/chouette/line_decorator.rb index 02caaed56..3a16dfd94 100644 --- a/app/decorators/chouette/line_decorator.rb +++ b/app/decorators/chouette/line_decorator.rb @@ -1,45 +1,47 @@ -class Chouette::LineDecorator < Draper::Decorator - decorates Chouette::Line +module Chouette + class LineDecorator < Draper::Decorator + decorates Chouette::Line - delegate_all + delegate_all - # Requires: - # context: { - # line_referential: , - # current_organisation: - # } - def action_links - links = [] + # Requires: + # context: { + # line_referential: , + # current_organisation: + # } + def action_links + links = [] - links << Link.new( - content: h.t('lines.actions.show_network'), - href: [context[:line_referential], object.network] - ) - - links << Link.new( - content: h.t('lines.actions.show_company'), - href: [context[:line_referential], object.company] - ) - - if h.policy(Chouette::Line).create? && - context[:line_referential].organisations.include?( - context[:current_organisation] - ) links << Link.new( - content: h.t('lines.actions.new'), - href: h.new_line_referential_line_path(context[:line_referential]) + content: h.t('lines.actions.show_network'), + href: [context[:line_referential], object.network] ) - end - if h.policy(object).destroy? links << Link.new( - content: h.destroy_link_content('lines.actions.destroy_confirm'), - href: h.line_referential_line_path(context[:line_referential], object), - method: :delete, - data: { confirm: h.t('lines.actions.destroy_confirm') } + content: h.t('lines.actions.show_company'), + href: [context[:line_referential], object.company] ) - end - links + if h.policy(Chouette::Line).create? && + context[:line_referential].organisations.include?( + context[:current_organisation] + ) + links << Link.new( + content: h.t('lines.actions.new'), + href: h.new_line_referential_line_path(context[:line_referential]) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('lines.actions.destroy_confirm'), + href: h.line_referential_line_path(context[:line_referential], object), + method: :delete, + data: { confirm: h.t('lines.actions.destroy_confirm') } + ) + end + + links + end end -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/network_decorator.rb b/app/decorators/chouette/network_decorator.rb index b674d3f27..fb6588689 100644 --- a/app/decorators/chouette/network_decorator.rb +++ b/app/decorators/chouette/network_decorator.rb @@ -1,44 +1,46 @@ -class Chouette::NetworkDecorator < Draper::Decorator - decorates Chouette::Network +module Chouette + class NetworkDecorator < Draper::Decorator + decorates Chouette::Network - delegate_all + delegate_all - # Requires: - # context: { - # line_referential: , - # } - def action_links - links = [] + # Requires: + # context: { + # line_referential: , + # } + def action_links + links = [] - if h.policy(Chouette::Network).create? - links << Link.new( - content: h.t('networks.actions.new'), - href: h.new_line_referential_network_path(context[:line_referential]) - ) - end + if h.policy(Chouette::Network).create? + links << Link.new( + content: h.t('networks.actions.new'), + href: h.new_line_referential_network_path(context[:line_referential]) + ) + end - if h.policy(object).update? - links << Link.new( - content: h.t('networks.actions.edit'), - href: h.edit_line_referential_network_path( - context[:line_referential], - object + if h.policy(object).update? + links << Link.new( + content: h.t('networks.actions.edit'), + href: h.edit_line_referential_network_path( + context[:line_referential], + object + ) ) - ) - end + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('networks.actions.destroy'), - href: h.line_referential_network_path( - context[:line_referential], - object - ), - method: :delete, - data: { confirm: t('networks.actions.destroy_confirm') } - ) - end + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('networks.actions.destroy'), + href: h.line_referential_network_path( + context[:line_referential], + object + ), + method: :delete, + data: { confirm: t('networks.actions.destroy_confirm') } + ) + end - links + links + end end -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/route_decorator.rb b/app/decorators/chouette/route_decorator.rb index b03b03607..479847f00 100644 --- a/app/decorators/chouette/route_decorator.rb +++ b/app/decorators/chouette/route_decorator.rb @@ -1,75 +1,77 @@ -class Chouette::RouteDecorator < Draper::Decorator - decorates Chouette::Route +module Chouette + class RouteDecorator < Draper::Decorator + decorates Chouette::Route - delegate_all + delegate_all - # Requires: - # context: { - # referential: , - # line: - # } - def action_links - links = [] + # Requires: + # context: { + # referential: , + # line: + # } + def action_links + links = [] - if object.stop_points.any? - links << Link.new( - content: h.t('journey_patterns.index.title'), - href: [ - context[:referential], - context[:line], - object, - :journey_patterns_collection - ] - ) - end + if object.stop_points.any? + links << Link.new( + content: h.t('journey_patterns.index.title'), + href: [ + context[:referential], + context[:line], + object, + :journey_patterns_collection + ] + ) + end + + if object.journey_patterns.present? + links << Link.new( + content: h.t('vehicle_journeys.actions.index'), + href: [ + context[:referential], + context[:line], + object, + :vehicle_journeys + ] + ) + end - if object.journey_patterns.present? links << Link.new( - content: h.t('vehicle_journeys.actions.index'), - href: [ + content: h.t('vehicle_journey_exports.new.title'), + href: h.referential_line_route_vehicle_journey_exports_path( context[:referential], context[:line], object, - :vehicle_journeys - ] + format: :zip + ) ) - end - links << Link.new( - content: h.t('vehicle_journey_exports.new.title'), - href: h.referential_line_route_vehicle_journey_exports_path( - context[:referential], - context[:line], - object, - format: :zip - ) - ) + if h.policy(object).duplicate? + links << Link.new( + content: h.t('routes.duplicate.title'), + href: h.duplicate_referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :post + ) + end - if h.policy(object).duplicate? - links << Link.new( - content: h.t('routes.duplicate.title'), - href: h.duplicate_referential_line_route_path( - context[:referential], - context[:line], - object - ), - method: :post - ) - end + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :delete, + data: { confirm: h.t('routes.actions.destroy_confirm') } + ) + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_line_route_path( - context[:referential], - context[:line], - object - ), - method: :delete, - data: { confirm: h.t('routes.actions.destroy_confirm') } - ) + links end - - links end -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/routing_constraint_zone_decorator.rb b/app/decorators/chouette/routing_constraint_zone_decorator.rb index 83f3411b2..bd5ccbf30 100644 --- a/app/decorators/chouette/routing_constraint_zone_decorator.rb +++ b/app/decorators/chouette/routing_constraint_zone_decorator.rb @@ -1,42 +1,44 @@ -class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator - decorates Chouette::RoutingConstraintZone +module Chouette + class RoutingConstraintZoneDecorator < Draper::Decorator + decorates Chouette::RoutingConstraintZone - delegate_all + delegate_all - # Requires: - # context: { - # referential: , - # line: - # } - def action_links - links = [] + # Requires: + # context: { + # referential: , + # line: + # } + def action_links + links = [] - if h.policy(object).update? - links << Link.new( - content: h.t('actions.edit'), - href: h.edit_referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object + if h.policy(object).update? + links << Link.new( + content: h.t('actions.edit'), + href: h.edit_referential_line_routing_constraint_zone_path( + context[:referential], + context[:line], + object + ) ) - ) - end + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ), - method: :delete, - data: { - confirm: h.t('routing_constraint_zones.actions.destroy_confirm') - } - ) - end + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_line_routing_constraint_zone_path( + context[:referential], + context[:line], + object + ), + method: :delete, + data: { + confirm: h.t('routing_constraint_zones.actions.destroy_confirm') + } + ) + end - links + links + end end -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/stop_area_decorator.rb b/app/decorators/chouette/stop_area_decorator.rb index 132b6320a..7525a9a27 100644 --- a/app/decorators/chouette/stop_area_decorator.rb +++ b/app/decorators/chouette/stop_area_decorator.rb @@ -1,43 +1,45 @@ -class Chouette::StopAreaDecorator < Draper::Decorator - decorates Chouette::StopArea +module Chouette + class StopAreaDecorator < Draper::Decorator + decorates Chouette::StopArea - delegate_all + delegate_all - def action_links(stop_area = nil) - links = [] - stop_area ||= object + def action_links(stop_area = nil) + links = [] + stop_area ||= object - if h.policy(Chouette::StopArea).new? - links << Link.new( - content: h.t('stop_areas.actions.new'), - href: h.new_stop_area_referential_stop_area_path( - stop_area.stop_area_referential + if h.policy(Chouette::StopArea).new? + links << Link.new( + content: h.t('stop_areas.actions.new'), + href: h.new_stop_area_referential_stop_area_path( + stop_area.stop_area_referential + ) ) - ) - end + end - if h.policy(stop_area).update? - links << Link.new( - content: h.t('stop_areas.actions.edit'), - href: h.edit_stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area + if h.policy(stop_area).update? + links << Link.new( + content: h.t('stop_areas.actions.edit'), + href: h.edit_stop_area_referential_stop_area_path( + stop_area.stop_area_referential, + stop_area + ) ) - ) - end + end - if h.policy(stop_area).destroy? - links << Link.new( - content: h.destroy_link_content('stop_areas.actions.destroy'), - href: h.stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ), - method: :delete, - data: { confirm: t('stop_areas.actions.destroy_confirm') } - ) - end + if h.policy(stop_area).destroy? + links << Link.new( + content: h.destroy_link_content('stop_areas.actions.destroy'), + href: h.stop_area_referential_stop_area_path( + stop_area.stop_area_referential, + stop_area + ), + method: :delete, + data: { confirm: t('stop_areas.actions.destroy_confirm') } + ) + end - links + links + end end -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/stop_point_decorator.rb b/app/decorators/chouette/stop_point_decorator.rb index 9e540ff50..a9be5459c 100644 --- a/app/decorators/chouette/stop_point_decorator.rb +++ b/app/decorators/chouette/stop_point_decorator.rb @@ -1,9 +1,11 @@ -class Chouette::StopPointDecorator < StopAreaDecorator - decorates Chouette::StopPoint +module Chouette + class StopPointDecorator < Chouette::StopAreaDecorator + decorates Chouette::StopPoint - delegate_all + delegate_all - def action_links - super(object.stop_area) + def action_links + super(object.stop_area) + end end -end +end
\ No newline at end of file diff --git a/app/decorators/chouette/time_table_decorator.rb b/app/decorators/chouette/time_table_decorator.rb index 419a0942e..86906cbe4 100644 --- a/app/decorators/chouette/time_table_decorator.rb +++ b/app/decorators/chouette/time_table_decorator.rb @@ -1,55 +1,57 @@ -class Chouette::TimeTableDecorator < Draper::Decorator - decorates Chouette::TimeTable +module Chouette + class TimeTableDecorator < Draper::Decorator + decorates Chouette::TimeTable - delegate_all + delegate_all - # Requires: - # context: { - # referential: , - # } - def action_links - links = [] + # Requires: + # context: { + # referential: , + # } + def action_links + links = [] - if object.calendar - links << Link.new( - content: h.t('actions.actualize'), - href: h.actualize_referential_time_table_path( - context[:referential], - object - ), - method: :post - ) - end + if object.calendar + links << Link.new( + content: h.t('actions.actualize'), + href: h.actualize_referential_time_table_path( + context[:referential], + object + ), + method: :post + ) + end - if h.policy(object).edit? - links << Link.new( - content: h.t('actions.combine'), - href: h.new_referential_time_table_time_table_combination_path( - context[:referential], - object + if h.policy(object).edit? + links << Link.new( + content: h.t('actions.combine'), + href: h.new_referential_time_table_time_table_combination_path( + context[:referential], + object + ) ) - ) - end + end - if h.policy(object).duplicate? - links << Link.new( - content: h.t('actions.duplicate'), - href: h.duplicate_referential_time_table_path( - context[:referential], - object + if h.policy(object).duplicate? + links << Link.new( + content: h.t('actions.duplicate'), + href: h.duplicate_referential_time_table_path( + context[:referential], + object + ) ) - ) - end + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_time_table_path(context[:referential], object), - method: :delete, - data: { confirm: h.t('time_tables.actions.destroy_confirm') } - ) - end + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_time_table_path(context[:referential], object), + method: :delete, + data: { confirm: h.t('time_tables.actions.destroy_confirm') } + ) + end - links + links + end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/access_link.rb b/app/models/chouette/access_link.rb index 9ecd401bb..46fbcb631 100644 --- a/app/models/chouette/access_link.rb +++ b/app/models/chouette/access_link.rb @@ -1,64 +1,66 @@ -class Chouette::AccessLink < Chouette::TridentActiveRecord - include ObjectidSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class AccessLink < Chouette::TridentActiveRecord + include ObjectidSupport + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - attr_accessor :access_link_type, :link_orientation_type, :link_key + attr_accessor :access_link_type, :link_orientation_type, :link_key - belongs_to :access_point, :class_name => 'Chouette::AccessPoint' - belongs_to :stop_area, :class_name => 'Chouette::StopArea' + belongs_to :access_point, :class_name => 'Chouette::AccessPoint' + belongs_to :stop_area, :class_name => 'Chouette::StopArea' - validates_presence_of :name - validates_presence_of :link_orientation + validates_presence_of :name + validates_presence_of :link_orientation - def self.nullable_attributes - [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, - :mobility_restricted_traveller_duration, :link_type] - end + def self.nullable_attributes + [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, + :mobility_restricted_traveller_duration, :link_type] + end - def access_link_type - link_type && Chouette::ConnectionLinkType.new(link_type.underscore) - end + def access_link_type + link_type && Chouette::ConnectionLinkType.new(link_type.underscore) + end - def access_link_type=(access_link_type) - self.link_type = (access_link_type ? access_link_type.camelcase : nil) - end + def access_link_type=(access_link_type) + self.link_type = (access_link_type ? access_link_type.camelcase : nil) + end - @@access_link_types = nil - def self.access_link_types - @@access_link_types ||= Chouette::ConnectionLinkType.all - end + @@access_link_types = nil + def self.access_link_types + @@access_link_types ||= Chouette::ConnectionLinkType.all + end - def link_orientation_type - link_orientation && Chouette::LinkOrientationType.new(link_orientation.underscore) - end + def link_orientation_type + link_orientation && Chouette::LinkOrientationType.new(link_orientation.underscore) + end - def link_orientation_type=(link_orientation_type) - self.link_orientation = (link_orientation_type ? link_orientation_type.camelcase : nil) - end + def link_orientation_type=(link_orientation_type) + self.link_orientation = (link_orientation_type ? link_orientation_type.camelcase : nil) + end - @@link_orientation_types = nil - def self.link_orientation_types - @@link_orientation_types ||= Chouette::LinkOrientationType.all - end + @@link_orientation_types = nil + def self.link_orientation_types + @@link_orientation_types ||= Chouette::LinkOrientationType.all + end - def geometry - GeoRuby::SimpleFeatures::LineString.from_points( [ access_point.geometry, stop_area.geometry], 4326) if access_point.geometry and stop_area.geometry - end + def geometry + GeoRuby::SimpleFeatures::LineString.from_points( [ access_point.geometry, stop_area.geometry], 4326) if access_point.geometry and stop_area.geometry + end - def link_key - Chouette::AccessLink.build_link_key(access_point,stop_area,link_orientation_type) - end - - def self.build_link_key(access_point,stop_area,link_orientation_type) - if link_orientation_type == "access_point_to_stop_area" - "A_#{access_point.id}-S_#{stop_area.id}" - else - "S_#{stop_area.id}-A_#{access_point.id}" + def link_key + Chouette::AccessLink.build_link_key(access_point,stop_area,link_orientation_type) + end + + def self.build_link_key(access_point,stop_area,link_orientation_type) + if link_orientation_type == "access_point_to_stop_area" + "A_#{access_point.id}-S_#{stop_area.id}" + else + "S_#{stop_area.id}-A_#{access_point.id}" + end end - end - def geometry_presenter - Chouette::Geometry::AccessLinkPresenter.new self + def geometry_presenter + Chouette::Geometry::AccessLinkPresenter.new self + end end end
\ No newline at end of file diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb index 679d3862b..7757fdcfb 100644 --- a/app/models/chouette/access_point.rb +++ b/app/models/chouette/access_point.rb @@ -1,168 +1,170 @@ require 'geokit' require 'geo_ruby' -class Chouette::AccessPoint < Chouette::ActiveRecord - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class AccessPoint < Chouette::ActiveRecord + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - include Geokit::Mappable - include ProjectionFields - include ObjectidSupport + include Geokit::Mappable + include ProjectionFields + include ObjectidSupport - has_many :access_links, :dependent => :destroy - belongs_to :stop_area + has_many :access_links, :dependent => :destroy + belongs_to :stop_area - attr_accessor :access_point_type - attr_writer :coordinates + attr_accessor :access_point_type + attr_writer :coordinates - validates_presence_of :name - validates_presence_of :access_type + validates_presence_of :name + validates_presence_of :access_type - validates_presence_of :latitude, :if => :longitude - validates_presence_of :longitude, :if => :latitude - validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true - validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true + validates_presence_of :latitude, :if => :longitude + validates_presence_of :longitude, :if => :latitude + validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true + validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true - validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true - before_save :coordinates_to_lat_lng - def self.nullable_attributes - [:street_name, :country_code, :comment, :long_lat_type, :zip_code, :city_name] - end + validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true + before_save :coordinates_to_lat_lng + def self.nullable_attributes + [:street_name, :country_code, :comment, :long_lat_type, :zip_code, :city_name] + end - def referential - @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! - end + def referential + @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! + end - def combine_lat_lng - if self.latitude.nil? || self.longitude.nil? - "" - else - self.latitude.to_s+","+self.longitude.to_s + def combine_lat_lng + if self.latitude.nil? || self.longitude.nil? + "" + else + self.latitude.to_s+","+self.longitude.to_s + end end - end - def coordinates - @coordinates || combine_lat_lng - end + def coordinates + @coordinates || combine_lat_lng + end - def coordinates_to_lat_lng - if ! @coordinates.nil? - if @coordinates.empty? - self.latitude = nil - self.longitude = nil - else - self.latitude = BigDecimal.new(@coordinates.split(",").first) - self.longitude = BigDecimal.new(@coordinates.split(",").last) + def coordinates_to_lat_lng + if ! @coordinates.nil? + if @coordinates.empty? + self.latitude = nil + self.longitude = nil + else + self.latitude = BigDecimal.new(@coordinates.split(",").first) + self.longitude = BigDecimal.new(@coordinates.split(",").last) + end + @coordinates = nil end - @coordinates = nil end - end - def to_lat_lng - Geokit::LatLng.new(latitude, longitude) if latitude and longitude - end + def to_lat_lng + Geokit::LatLng.new(latitude, longitude) if latitude and longitude + end - def geometry - GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude - end + def geometry + GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude + end - def geometry=(geometry) - geometry = geometry.to_wgs84 - self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" - end + def geometry=(geometry) + geometry = geometry.to_wgs84 + self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" + end - def position - geometry - end + def position + geometry + end - def position=(position) - position = nil if String === position && position == "" - position = Geokit::LatLng.normalize(position), 4326 if String === position - self.latitude = position.lat - self.longitude = position.lng - end + def position=(position) + position = nil if String === position && position == "" + position = Geokit::LatLng.normalize(position), 4326 if String === position + self.latitude = position.lat + self.longitude = position.lng + end - def default_position - stop_area.geometry or stop_area.default_position - end + def default_position + stop_area.geometry or stop_area.default_position + end - def access_point_type - access_type && Chouette::AccessPointType.new(access_type.underscore) - end + def access_point_type + access_type && Chouette::AccessPointType.new(access_type.underscore) + end - def access_point_type=(access_point_type) - self.access_type = (access_point_type ? access_point_type.camelcase : nil) - end + def access_point_type=(access_point_type) + self.access_type = (access_point_type ? access_point_type.camelcase : nil) + end - @@access_point_types = nil - def self.access_point_types - @@access_point_types ||= Chouette::AccessPointType.all.select do |access_point_type| - access_point_type.to_i >= 0 + @@access_point_types = nil + def self.access_point_types + @@access_point_types ||= Chouette::AccessPointType.all.select do |access_point_type| + access_point_type.to_i >= 0 + end end - end - def generic_access_link_matrix - matrix = Array.new - hash = Hash.new - access_links.each do |link| - hash[link.link_key] = link - end - key=Chouette::AccessLink.build_link_key(self,stop_area,"access_point_to_stop_area") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = stop_area - link.link_orientation_type = "access_point_to_stop_area" - matrix << link - end - key=Chouette::AccessLink.build_link_key(self,stop_area,"stop_area_to_access_point") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = stop_area - link.link_orientation_type = "stop_area_to_access_point" - matrix << link - end - matrix - end + def generic_access_link_matrix + matrix = Array.new + hash = Hash.new + access_links.each do |link| + hash[link.link_key] = link + end + key=Chouette::AccessLink.build_link_key(self,stop_area,"access_point_to_stop_area") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = stop_area + link.link_orientation_type = "access_point_to_stop_area" + matrix << link + end + key=Chouette::AccessLink.build_link_key(self,stop_area,"stop_area_to_access_point") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = stop_area + link.link_orientation_type = "stop_area_to_access_point" + matrix << link + end + matrix + end - def detail_access_link_matrix - matrix = Array.new - hash = Hash.new - access_links.each do |link| - hash[link.link_key] = link - end - stop_area.children_at_base.each do |child| - key=Chouette::AccessLink.build_link_key(self,child,"access_point_to_stop_area") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = child - link.link_orientation_type = "access_point_to_stop_area" - matrix << link - end - key=Chouette::AccessLink.build_link_key(self,child,"stop_area_to_access_point") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = child - link.link_orientation_type = "stop_area_to_access_point" - matrix << link - end - end - matrix - end + def detail_access_link_matrix + matrix = Array.new + hash = Hash.new + access_links.each do |link| + hash[link.link_key] = link + end + stop_area.children_at_base.each do |child| + key=Chouette::AccessLink.build_link_key(self,child,"access_point_to_stop_area") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = child + link.link_orientation_type = "access_point_to_stop_area" + matrix << link + end + key=Chouette::AccessLink.build_link_key(self,child,"stop_area_to_access_point") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = child + link.link_orientation_type = "stop_area_to_access_point" + matrix << link + end + end + matrix + end - def geometry_presenter - Chouette::Geometry::AccessPointPresenter.new self + def geometry_presenter + Chouette::Geometry::AccessPointPresenter.new self + end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/access_point_type.rb b/app/models/chouette/access_point_type.rb index 94d28e5ae..f7439a428 100644 --- a/app/models/chouette/access_point_type.rb +++ b/app/models/chouette/access_point_type.rb @@ -1,50 +1,52 @@ -class Chouette::AccessPointType < ActiveSupport::StringInquirer +module Chouette + class AccessPointType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - def to_i - @numerical_code - end + def to_i + @numerical_code + end - def inspect - "#{to_s}/#{to_i}" - end + def inspect + "#{to_s}/#{to_i}" + end - def name - camelize - end + def name + camelize + end - @@definitions = [ - ["in", 0], - ["out", 1], - ["in_out", 2] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@definitions = [ + ["in", 0], + ["out", 1], + ["in_out", 2] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/command.rb b/app/models/chouette/command.rb index d2995a000..b735747bf 100644 --- a/app/models/chouette/command.rb +++ b/app/models/chouette/command.rb @@ -10,85 +10,85 @@ require 'tmpdir' end #end -class Chouette::Command +module Chouette + class Command - include Chouette::CommandLineSupport + include Chouette::CommandLineSupport - @@command = "chouette" - cattr_accessor :command + @@command = "chouette" + cattr_accessor :command - attr_accessor :database, :schema, :host, :user, :password, :port + attr_accessor :database, :schema, :host, :user, :password, :port - def initialize(options = {}) - database_options_from_active_record.merge(options).each do |k,v| - send "#{k}=", v + def initialize(options = {}) + database_options_from_active_record.merge(options).each do |k,v| + send "#{k}=", v + end end - end - def database_options_from_active_record - config = Chouette::ActiveRecord.connection_pool.spec.config - { - :database => config[:database], - :user => config[:username], - :password => config[:password], - :port => config[:port], - :host => (config[:host] or "localhost") - } - end + def database_options_from_active_record + config = Chouette::ActiveRecord.connection_pool.spec.config + { + :database => config[:database], + :user => config[:username], + :password => config[:password], + :port => config[:port], + :host => (config[:host] or "localhost") + } + end - def run!(options = {}) - Dir.mktmpdir do |config_dir| - chouette_properties = File.join(config_dir, "chouette.properties") - open(chouette_properties, "w") do |f| - f.puts "database.name = #{database}" - f.puts "database.schema = #{schema}" - #f.puts "database.showsql = true" - f.puts "hibernate.username = #{user}" - f.puts "hibernate.password = #{password}" - f.puts "jdbc.url=jdbc:postgresql://#{host}:#{port}/#{database}" - f.puts "jdbc.username = #{user}" - f.puts "jdbc.password = #{password}" - #f.puts "database.hbm2ddl.auto=update" - end + def run!(options = {}) + Dir.mktmpdir do |config_dir| + chouette_properties = File.join(config_dir, "chouette.properties") + open(chouette_properties, "w") do |f| + f.puts "database.name = #{database}" + f.puts "database.schema = #{schema}" + #f.puts "database.showsql = true" + f.puts "hibernate.username = #{user}" + f.puts "hibernate.password = #{password}" + f.puts "jdbc.url=jdbc:postgresql://#{host}:#{port}/#{database}" + f.puts "jdbc.username = #{user}" + f.puts "jdbc.password = #{password}" + #f.puts "database.hbm2ddl.auto=update" + end - logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}" + logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}" - command_line = "#{command} -classpath #{config_dir} #{command_options(options)}" - logger.debug "Execute '#{command_line}'" + command_line = "#{command} -classpath #{config_dir} #{command_options(options)}" + logger.debug "Execute '#{command_line}'" - execute! command_line + execute! command_line + end end - end - class Option + class Option - attr_accessor :key, :value + attr_accessor :key, :value - def initialize(key, value) - @key, @value = key.to_s, value - end + def initialize(key, value) + @key, @value = key.to_s, value + end - def command_key - key.camelize(:lower) - end + def command_key + key.camelize(:lower) + end - def to_s - unless value == true - "-#{command_key} #{value}" - else - "-#{command_key}" + def to_s + unless value == true + "-#{command_key} #{value}" + else + "-#{command_key}" + end end + end - end + def command_options(options) + options.collect do |key, value| + Option.new(key, value) + end.sort_by(&:key).join(' ') + end - def command_options(options) - options.collect do |key, value| - Option.new(key, value) - end.sort_by(&:key).join(' ') end - - - -end +end
\ No newline at end of file diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb index 148329f2e..a06bf5d91 100644 --- a/app/models/chouette/company.rb +++ b/app/models/chouette/company.rb @@ -1,19 +1,20 @@ -class Chouette::Company < Chouette::ActiveRecord - include CompanyRestrictions - include LineReferentialSupport - include ObjectidSupport +module Chouette + class Company < Chouette::ActiveRecord + include CompanyRestrictions + include LineReferentialSupport + include ObjectidSupport - has_many :lines + has_many :lines - validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true - validates_presence_of :name - validates_presence_of :objectid_format - validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true - - def self.nullable_attributes - [:organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :url, :time_zone] - end + validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true + validates_presence_of :name + validates_presence_of :objectid_format + validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true + def self.nullable_attributes + [:organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :url, :time_zone] + end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/connection_link.rb b/app/models/chouette/connection_link.rb index b3d999152..d19b53974 100644 --- a/app/models/chouette/connection_link.rb +++ b/app/models/chouette/connection_link.rb @@ -1,49 +1,50 @@ -class Chouette::ConnectionLink < Chouette::TridentActiveRecord - include ObjectidSupport - include ConnectionLinkRestrictions - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class ConnectionLink < Chouette::TridentActiveRecord + include ObjectidSupport + include ConnectionLinkRestrictions + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - attr_accessor :connection_link_type + attr_accessor :connection_link_type - belongs_to :departure, :class_name => 'Chouette::StopArea' - belongs_to :arrival, :class_name => 'Chouette::StopArea' + belongs_to :departure, :class_name => 'Chouette::StopArea' + belongs_to :arrival, :class_name => 'Chouette::StopArea' - validates_presence_of :name + validates_presence_of :name - def self.nullable_attributes - [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, - :mobility_restricted_traveller_duration, :link_type] - end + def self.nullable_attributes + [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, + :mobility_restricted_traveller_duration, :link_type] + end - def connection_link_type - link_type && Chouette::ConnectionLinkType.new( link_type.underscore) - end + def connection_link_type + link_type && Chouette::ConnectionLinkType.new( link_type.underscore) + end - def connection_link_type=(connection_link_type) - self.link_type = (connection_link_type ? connection_link_type.camelcase : nil) - end - - @@connection_link_types = nil - def self.connection_link_types - @@connection_link_types ||= Chouette::ConnectionLinkType.all - end + def connection_link_type=(connection_link_type) + self.link_type = (connection_link_type ? connection_link_type.camelcase : nil) + end - def possible_areas - Chouette::StopArea.where("area_type != 'ITL'") - end + @@connection_link_types = nil + def self.connection_link_types + @@connection_link_types ||= Chouette::ConnectionLinkType.all + end - def stop_areas - Chouette::StopArea.where(:id => [self.departure_id,self.arrival_id]) - end + def possible_areas + Chouette::StopArea.where("area_type != 'ITL'") + end - def geometry - GeoRuby::SimpleFeatures::LineString.from_points( [ departure.geometry, arrival.geometry], 4326) if departure.geometry and arrival.geometry - end + def stop_areas + Chouette::StopArea.where(:id => [self.departure_id,self.arrival_id]) + end - def geometry_presenter - Chouette::Geometry::ConnectionLinkPresenter.new self - end + def geometry + GeoRuby::SimpleFeatures::LineString.from_points( [ departure.geometry, arrival.geometry], 4326) if departure.geometry and arrival.geometry + end -end + def geometry_presenter + Chouette::Geometry::ConnectionLinkPresenter.new self + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/connection_link_type.rb b/app/models/chouette/connection_link_type.rb index 41635f48c..ca27ed5da 100644 --- a/app/models/chouette/connection_link_type.rb +++ b/app/models/chouette/connection_link_type.rb @@ -1,51 +1,52 @@ -class Chouette::ConnectionLinkType < ActiveSupport::StringInquirer +module Chouette + class ConnectionLinkType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - - def to_i - @numerical_code - end - def inspect - "#{to_s}/#{to_i}" - end + def to_i + @numerical_code + end - def name - camelize - end + def inspect + "#{to_s}/#{to_i}" + end - @@definitions = [ - ["underground", 0], - ["mixed", 1], - ["overground", 2] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + def name + camelize end - end -end + @@definitions = [ + ["underground", 0], + ["mixed", 1], + ["overground", 2] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/direction.rb b/app/models/chouette/direction.rb index 93bc1318b..41d703b56 100644 --- a/app/models/chouette/direction.rb +++ b/app/models/chouette/direction.rb @@ -1,60 +1,61 @@ -class Chouette::Direction < ActiveSupport::StringInquirer +module Chouette + class Direction < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - - def to_i - @numerical_code - end - def inspect - "#{to_s}/#{to_i}" - end + def to_i + @numerical_code + end - def name - to_s - end + def inspect + "#{to_s}/#{to_i}" + end - @@definitions = [ - ["straight_forward", 0], - ["backward", 1], - ["clock_wise", 2], - ["counter_clock_wise", 3], - ["north", 4], - ["north_west", 5], - ["west", 6], - ["south_west", 7], - ["south", 8], - ["south_east", 9], - ["east", 10], - ["north_east", 11] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + def name + to_s end - end -end + @@definitions = [ + ["straight_forward", 0], + ["backward", 1], + ["clock_wise", 2], + ["counter_clock_wise", 3], + ["north", 4], + ["north_west", 5], + ["west", 6], + ["south_west", 7], + ["south", 8], + ["south_east", 9], + ["east", 10], + ["north_east", 11] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/exporter.rb b/app/models/chouette/exporter.rb index df85a9dde..98cab7269 100644 --- a/app/models/chouette/exporter.rb +++ b/app/models/chouette/exporter.rb @@ -1,32 +1,34 @@ -class Chouette::Exporter +module Chouette + class Exporter - attr_reader :schema + attr_reader :schema - def initialize(schema) - @schema = schema - end + def initialize(schema) + @schema = schema + end - def chouette_command - @chouette_command ||= Chouette::Command.new(:schema => schema) - end + def chouette_command + @chouette_command ||= Chouette::Command.new(:schema => schema) + end - def export(file, options = {}) - options = { - :format => :neptune - }.merge(options) - - command_options = { - :c => "export", - :o => "line", - :format => options.delete(:format).to_s.upcase, - :output_file => File.expand_path(file), - :optimize_memory => true - }.merge(options) - - logger.info "Export #{file} in schema #{schema}" - chouette_command.run! command_options - end + def export(file, options = {}) + options = { + :format => :neptune + }.merge(options) - include Chouette::CommandLineSupport + command_options = { + :c => "export", + :o => "line", + :format => options.delete(:format).to_s.upcase, + :output_file => File.expand_path(file), + :optimize_memory => true + }.merge(options) -end + logger.info "Export #{file} in schema #{schema}" + chouette_command.run! command_options + end + + include Chouette::CommandLineSupport + + end +end
\ No newline at end of file diff --git a/app/models/chouette/file_validator.rb b/app/models/chouette/file_validator.rb index 513648a62..98453c71c 100644 --- a/app/models/chouette/file_validator.rb +++ b/app/models/chouette/file_validator.rb @@ -1,47 +1,49 @@ -class Chouette::FileValidator +module Chouette + class FileValidator - attr_reader :schema, :database, :user, :password, :host + attr_reader :schema, :database, :user, :password, :host - def initialize(schema) - @schema = schema + def initialize(schema) + @schema = schema - Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| - @database = config[:database] - @user = config[:username] - @password = config[:password] - @host = (config[:host] or "localhost") + Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| + @database = config[:database] + @user = config[:username] + @password = config[:password] + @host = (config[:host] or "localhost") + end end - end - def self.chouette_command=(command) - Chouette::Command.command = command - end + def self.chouette_command=(command) + Chouette::Command.command = command + end - class << self - deprecate :chouette_command= => "Use Chouette::Command.command =" - end + class << self + deprecate :chouette_command= => "Use Chouette::Command.command =" + end - def chouette_command - @chouette_command ||= Chouette::Command.new(:schema => schema) - end + def chouette_command + @chouette_command ||= Chouette::Command.new(:schema => schema) + end - def validate(file, options = {}) - options = { - :format => :neptune - }.merge(options) + def validate(file, options = {}) + options = { + :format => :neptune + }.merge(options) - command_options = { - :c => "validate", - :o => "line", - :input_file => File.expand_path(file), - :optimize_memory => true - }.merge(options) + command_options = { + :c => "validate", + :o => "line", + :input_file => File.expand_path(file), + :optimize_memory => true + }.merge(options) - logger.info "Validate #{file}" - chouette_command.run! command_options - end + logger.info "Validate #{file}" + chouette_command.run! command_options + end - include Chouette::CommandLineSupport + include Chouette::CommandLineSupport -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/footnote.rb b/app/models/chouette/footnote.rb index 1664faf23..051027cea 100644 --- a/app/models/chouette/footnote.rb +++ b/app/models/chouette/footnote.rb @@ -1,13 +1,15 @@ -class Chouette::Footnote < Chouette::ActiveRecord - include ChecksumSupport +module Chouette + class Footnote < Chouette::ActiveRecord + include ChecksumSupport - belongs_to :line, inverse_of: :footnotes - has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' + belongs_to :line, inverse_of: :footnotes + has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' - validates_presence_of :line + validates_presence_of :line - def checksum_attributes - attrs = ['code', 'label'] - self.slice(*attrs).values + def checksum_attributes + attrs = ['code', 'label'] + self.slice(*attrs).values + end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb index 006a7c039..3023d23ed 100644 --- a/app/models/chouette/group_of_line.rb +++ b/app/models/chouette/group_of_line.rb @@ -1,31 +1,33 @@ -class Chouette::GroupOfLine < Chouette::ActiveRecord - include ObjectidSupport - include GroupOfLineRestrictions - include LineReferentialSupport +module Chouette + class GroupOfLine < Chouette::ActiveRecord + include ObjectidSupport + include GroupOfLineRestrictions + include LineReferentialSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - has_and_belongs_to_many :lines, :class_name => 'Chouette::Line', :order => 'lines.name' + has_and_belongs_to_many :lines, :class_name => 'Chouette::Line', :order => 'lines.name' - validates_presence_of :name + validates_presence_of :name - attr_reader :line_tokens + attr_reader :line_tokens - def self.nullable_attributes - [:comment] - end + def self.nullable_attributes + [:comment] + end - def commercial_stop_areas - Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :group_of_lines] ] ]).where(:group_of_lines => {:id => self.id}).uniq - end + def commercial_stop_areas + Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :group_of_lines] ] ]).where(:group_of_lines => {:id => self.id}).uniq + end - def stop_areas - Chouette::StopArea.joins(:stop_points => [:route => [:line => :group_of_lines] ]).where(:group_of_lines => {:id => self.id}) - end + def stop_areas + Chouette::StopArea.joins(:stop_points => [:route => [:line => :group_of_lines] ]).where(:group_of_lines => {:id => self.id}) + end - def line_tokens=(ids) - self.line_ids = ids.split(",") - end + def line_tokens=(ids) + self.line_ids = ids.split(",") + end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/journey_frequency.rb b/app/models/chouette/journey_frequency.rb index ace2db24c..1b4efe96e 100644 --- a/app/models/chouette/journey_frequency.rb +++ b/app/models/chouette/journey_frequency.rb @@ -1,33 +1,35 @@ -class Chouette::JourneyFrequencyValidator < ActiveModel::Validator - def validate(record) - timeband = record.timeband - if timeband - first_departure_time = record.first_departure_time.utc.strftime( "%H%M%S%N" ) - last_departure_time = record.last_departure_time.utc.strftime( "%H%M%S%N" ) - timeband_start_time = timeband.start_time.utc.strftime( "%H%M%S%N" ) - timeband_end_time = timeband.end_time.utc.strftime( "%H%M%S%N" ) +module Chouette + class JourneyFrequencyValidator < ActiveModel::Validator + def validate(record) + timeband = record.timeband + if timeband + first_departure_time = record.first_departure_time.utc.strftime( "%H%M%S%N" ) + last_departure_time = record.last_departure_time.utc.strftime( "%H%M%S%N" ) + timeband_start_time = timeband.start_time.utc.strftime( "%H%M%S%N" ) + timeband_end_time = timeband.end_time.utc.strftime( "%H%M%S%N" ) - unless first_departure_time.between? timeband_start_time, timeband_end_time - record.errors[:first_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.start_must_be_after_timeband') + unless first_departure_time.between? timeband_start_time, timeband_end_time + record.errors[:first_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.start_must_be_after_timeband') + end + unless last_departure_time.between? timeband_start_time, timeband_end_time + record.errors[:last_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.end_must_be_before_timeband') + end end - unless last_departure_time.between? timeband_start_time, timeband_end_time - record.errors[:last_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.end_must_be_before_timeband') + if record.first_departure_time == record.last_departure_time + record.errors[:last_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.end_must_be_different_from_first') + end + if record.scheduled_headway_interval.blank? || (record.scheduled_headway_interval.strftime( "%H%M%S%N" ) == Time.current.midnight.strftime( "%H%M%S%N" )) + record.errors[:scheduled_headway_interval] << I18n.t('activerecord.errors.models.journey_frequency.scheduled_headway_interval_greater_than_zero') end - end - if record.first_departure_time == record.last_departure_time - record.errors[:last_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.end_must_be_different_from_first') - end - if record.scheduled_headway_interval.blank? || (record.scheduled_headway_interval.strftime( "%H%M%S%N" ) == Time.current.midnight.strftime( "%H%M%S%N" )) - record.errors[:scheduled_headway_interval] << I18n.t('activerecord.errors.models.journey_frequency.scheduled_headway_interval_greater_than_zero') end end -end -class Chouette::JourneyFrequency < ActiveRecord::Base - belongs_to :vehicle_journey_frequency, foreign_key: 'vehicle_journey_id' - belongs_to :timeband - validates :first_departure_time, presence: true - validates :last_departure_time, presence: true - validates :scheduled_headway_interval, presence: true - validates_with Chouette::JourneyFrequencyValidator + class JourneyFrequency < ActiveRecord + belongs_to :vehicle_journey_frequency, foreign_key: 'vehicle_journey_id' + belongs_to :timeband + validates :first_departure_time, presence: true + validates :last_departure_time, presence: true + validates :scheduled_headway_interval, presence: true + validates_with Chouette::JourneyFrequencyValidator + end end
\ No newline at end of file diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index b52e27a6b..fb30ab69e 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -1,184 +1,186 @@ -class Chouette::JourneyPattern < Chouette::TridentActiveRecord - include ChecksumSupport - include JourneyPatternRestrictions - include ObjectidSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - belongs_to :route - has_many :vehicle_journeys, :dependent => :destroy - has_many :vehicle_journey_at_stops, :through => :vehicle_journeys - has_and_belongs_to_many :stop_points, -> { order("stop_points.position") }, :before_add => :vjas_add, :before_remove => :vjas_remove, :after_add => :shortcuts_update_for_add, :after_remove => :shortcuts_update_for_remove - has_many :stop_areas, through: :stop_points - has_many :journey_pattern_sections - has_many :route_sections, through: :journey_pattern_sections, dependent: :destroy - - validates_presence_of :route - validates_presence_of :name - - #validates :stop_points, length: { minimum: 2, too_short: :minimum }, on: :update - enum section_status: { todo: 0, completed: 1, control: 2 } - - attr_accessor :control_checked - after_update :control_route_sections, :unless => "control_checked" - - - def local_id - "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.id}" - end +module Chouette + class JourneyPattern < Chouette::TridentActiveRecord + include ChecksumSupport + include JourneyPatternRestrictions + include ObjectidSupport + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + + belongs_to :route + has_many :vehicle_journeys, :dependent => :destroy + has_many :vehicle_journey_at_stops, :through => :vehicle_journeys + has_and_belongs_to_many :stop_points, -> { order("stop_points.position") }, :before_add => :vjas_add, :before_remove => :vjas_remove, :after_add => :shortcuts_update_for_add, :after_remove => :shortcuts_update_for_remove + has_many :stop_areas, through: :stop_points + has_many :journey_pattern_sections + has_many :route_sections, through: :journey_pattern_sections, dependent: :destroy + + validates_presence_of :route + validates_presence_of :name + + #validates :stop_points, length: { minimum: 2, too_short: :minimum }, on: :update + enum section_status: { todo: 0, completed: 1, control: 2 } + + attr_accessor :control_checked + after_update :control_route_sections, :unless => "control_checked" + + + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.id}" + end - def checksum_attributes - values = self.slice(*['name', 'published_name', 'registration_number']).values - values << self.stop_points.map(&:stop_area).map(&:user_objectid) - values.flatten - end + def checksum_attributes + values = self.slice(*['name', 'published_name', 'registration_number']).values + values << self.stop_points.map(&:stop_area).map(&:user_objectid) + values.flatten + end - def self.state_update route, state - transaction do - state.each do |item| - item.delete('errors') - jp = find_by(objectid: item['object_id']) || state_create_instance(route, item) - next if item['deletable'] && jp.persisted? && jp.destroy - # Update attributes and stop_points associations - jp.update_attributes(state_permited_attributes(item)) unless item['new_record'] - jp.state_stop_points_update(item) if !jp.errors.any? && jp.persisted? - item['errors'] = jp.errors if jp.errors.any? + def self.state_update route, state + transaction do + state.each do |item| + item.delete('errors') + jp = find_by(objectid: item['object_id']) || state_create_instance(route, item) + next if item['deletable'] && jp.persisted? && jp.destroy + # Update attributes and stop_points associations + jp.update_attributes(state_permited_attributes(item)) unless item['new_record'] + jp.state_stop_points_update(item) if !jp.errors.any? && jp.persisted? + item['errors'] = jp.errors if jp.errors.any? + end + + if state.any? {|item| item['errors']} + state.map {|item| item.delete('object_id') if item['new_record']} + raise ::ActiveRecord::Rollback + end end - if state.any? {|item| item['errors']} - state.map {|item| item.delete('object_id') if item['new_record']} - raise ActiveRecord::Rollback - end + state.map {|item| item.delete('new_record')} + state.delete_if {|item| item['deletable']} end - state.map {|item| item.delete('new_record')} - state.delete_if {|item| item['deletable']} - end - - def self.state_permited_attributes item - { - name: item['name'], - published_name: item['published_name'], - registration_number: item['registration_number'] - } - end - - def self.state_create_instance route, item - # Flag new record, so we can unset object_id if transaction rollback - jp = route.journey_patterns.create(state_permited_attributes(item)) + def self.state_permited_attributes item + { + name: item['name'], + published_name: item['published_name'], + registration_number: item['registration_number'] + } + end - # FIXME - # DefaultAttributesSupport will trigger some weird validation on after save - # wich will call to valid?, wich will populate errors - # In this case, we mark jp to be valid if persisted? return true - jp.errors.clear if jp.persisted? + def self.state_create_instance route, item + # Flag new record, so we can unset object_id if transaction rollback + jp = route.journey_patterns.create(state_permited_attributes(item)) - item['object_id'] = jp.objectid - item['new_record'] = true - jp - end + # FIXME + # DefaultAttributesSupport will trigger some weird validation on after save + # wich will call to valid?, wich will populate errors + # In this case, we mark jp to be valid if persisted? return true + jp.errors.clear if jp.persisted? - def state_stop_points_update item - item['stop_points'].each do |sp| - exist = stop_area_ids.include?(sp['id']) - next if exist && sp['checked'] + item['object_id'] = jp.objectid + item['new_record'] = true + jp + end - stop_point = route.stop_points.find_by(stop_area_id: sp['id']) - if !exist && sp['checked'] - stop_points << stop_point - end - if exist && !sp['checked'] - stop_points.delete(stop_point) + def state_stop_points_update item + item['stop_points'].each do |sp| + exist = stop_area_ids.include?(sp['id']) + next if exist && sp['checked'] + + stop_point = route.stop_points.find_by(stop_area_id: sp['id']) + if !exist && sp['checked'] + stop_points << stop_point + end + if exist && !sp['checked'] + stop_points.delete(stop_point) + end end end - end - # TODO: this a workarround - # otherwise, we loose the first stop_point - # when creating a new journey_pattern - def special_update - bck_sp = self.stop_points.map {|s| s} - self.update_attributes :stop_points => [] - self.update_attributes :stop_points => bck_sp - end + # TODO: this a workarround + # otherwise, we loose the first stop_point + # when creating a new journey_pattern + def special_update + bck_sp = self.stop_points.map {|s| s} + self.update_attributes :stop_points => [] + self.update_attributes :stop_points => bck_sp + end - def departure_stop_point - return unless departure_stop_point_id - Chouette::StopPoint.find( departure_stop_point_id) - end + def departure_stop_point + return unless departure_stop_point_id + Chouette::StopPoint.find( departure_stop_point_id) + end - def arrival_stop_point - return unless arrival_stop_point_id - Chouette::StopPoint.find( arrival_stop_point_id) - end + def arrival_stop_point + return unless arrival_stop_point_id + Chouette::StopPoint.find( arrival_stop_point_id) + end - def shortcuts_update_for_add( stop_point) - stop_points << stop_point unless stop_points.include?( stop_point) + def shortcuts_update_for_add( stop_point) + stop_points << stop_point unless stop_points.include?( stop_point) - ordered_stop_points = stop_points - ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? + ordered_stop_points = stop_points + ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? - self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), - :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) - end + self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), + :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) + end - def shortcuts_update_for_remove( stop_point) - stop_points.delete( stop_point) if stop_points.include?( stop_point) + def shortcuts_update_for_remove( stop_point) + stop_points.delete( stop_point) if stop_points.include?( stop_point) - ordered_stop_points = stop_points - ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? + ordered_stop_points = stop_points + ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? - self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), - :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) - end + self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), + :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) + end - def vjas_add( stop_point) - return if new_record? + def vjas_add( stop_point) + return if new_record? - vehicle_journeys.each do |vj| - vjas = vj.vehicle_journey_at_stops.create :stop_point_id => stop_point.id + vehicle_journeys.each do |vj| + vjas = vj.vehicle_journey_at_stops.create :stop_point_id => stop_point.id + end end - end - def vjas_remove( stop_point) - return if new_record? + def vjas_remove( stop_point) + return if new_record? - vehicle_journey_at_stops.where( :stop_point_id => stop_point.id).each do |vjas| - vjas.destroy + vehicle_journey_at_stops.where( :stop_point_id => stop_point.id).each do |vjas| + vjas.destroy + end end - end - def control_route_sections - stop_area_ids = self.stop_points.map(&:stop_area_id) - control_route_sections_by_stop_areas(stop_area_ids) - end + def control_route_sections + stop_area_ids = self.stop_points.map(&:stop_area_id) + control_route_sections_by_stop_areas(stop_area_ids) + end - def control_route_sections_by_stop_areas(stop_area_ids) - journey_pattern_section_all - i = 0 - to_control = false - stop_area_ids.each_cons(2) do |a| - jps = @route_sections_orders[i] - i += 1 - unless jps - to_control = true - next - end - unless [jps.route_section.departure.id, jps.route_section.arrival.id] == a - jps.destroy - to_control = true + def control_route_sections_by_stop_areas(stop_area_ids) + journey_pattern_section_all + i = 0 + to_control = false + stop_area_ids.each_cons(2) do |a| + jps = @route_sections_orders[i] + i += 1 + unless jps + to_control = true + next + end + unless [jps.route_section.departure.id, jps.route_section.arrival.id] == a + jps.destroy + to_control = true + end end + self.control_checked = true + to_control ? self.control! : self.completed! end - self.control_checked = true - to_control ? self.control! : self.completed! - end - protected + protected - def journey_pattern_section_all - @route_sections_orders = {} - self.journey_pattern_sections.all.map do |journey_pattern_section| - @route_sections_orders[journey_pattern_section.rank] = journey_pattern_section + def journey_pattern_section_all + @route_sections_orders = {} + self.journey_pattern_sections.all.map do |journey_pattern_section| + @route_sections_orders[journey_pattern_section.rank] = journey_pattern_section + end end end end
\ No newline at end of file diff --git a/app/models/chouette/journey_pattern_section.rb b/app/models/chouette/journey_pattern_section.rb index 3ccba8ec0..226a50c27 100644 --- a/app/models/chouette/journey_pattern_section.rb +++ b/app/models/chouette/journey_pattern_section.rb @@ -1,20 +1,22 @@ -class Chouette::JourneyPatternSection < Chouette::ActiveRecord - belongs_to :journey_pattern - belongs_to :route_section +module Chouette + class JourneyPatternSection < Chouette::ActiveRecord + belongs_to :journey_pattern + belongs_to :route_section - validates :journey_pattern_id, presence: true - validates :route_section_id, presence: true - validates :rank, presence: true, numericality: :only_integer - validates :journey_pattern_id, uniqueness: { scope: [:route_section_id, :rank] } + validates :journey_pattern_id, presence: true + validates :route_section_id, presence: true + validates :rank, presence: true, numericality: :only_integer + validates :journey_pattern_id, uniqueness: { scope: [:route_section_id, :rank] } - default_scope { order(:rank) } + default_scope { order(:rank) } - def self.update_by_journey_pattern_rank(journey_pattern_id, route_section_id, rank) - jps = self.find_or_initialize_by(journey_pattern_id: journey_pattern_id, rank: rank) - if route_section_id.present? - jps.update_attributes(route_section_id: route_section_id) - else - jps.destroy + def self.update_by_journey_pattern_rank(journey_pattern_id, route_section_id, rank) + jps = self.find_or_initialize_by(journey_pattern_id: journey_pattern_id, rank: rank) + if route_section_id.present? + jps.update_attributes(route_section_id: route_section_id) + else + jps.destroy + end end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index cae4e7c3f..780f6473f 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -1,81 +1,83 @@ -class Chouette::Line < Chouette::ActiveRecord - include LineRestrictions - include LineReferentialSupport - include ObjectidSupport - extend StifTransportModeEnumerations - extend StifTransportSubmodeEnumerations +module Chouette + class Line < Chouette::ActiveRecord + include LineRestrictions + include LineReferentialSupport + include ObjectidSupport + extend StifTransportModeEnumerations + extend StifTransportSubmodeEnumerations - extend ActiveModel::Naming + extend ActiveModel::Naming - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - belongs_to :company - belongs_to :network - belongs_to :line_referential + belongs_to :company + belongs_to :network + belongs_to :line_referential - has_array_of :secondary_companies, class_name: 'Chouette::Company' + has_array_of :secondary_companies, class_name: 'Chouette::Company' - has_many :routes, :dependent => :destroy - has_many :journey_patterns, :through => :routes - has_many :vehicle_journeys, :through => :journey_patterns - has_many :routing_constraint_zones, through: :routes + has_many :routes, :dependent => :destroy + has_many :journey_patterns, :through => :routes + has_many :vehicle_journeys, :through => :journey_patterns + has_many :routing_constraint_zones, through: :routes - has_and_belongs_to_many :group_of_lines, :class_name => 'Chouette::GroupOfLine', :order => 'group_of_lines.name' + has_and_belongs_to_many :group_of_lines, :class_name => 'Chouette::GroupOfLine', :order => 'group_of_lines.name' - has_many :footnotes, :inverse_of => :line, :validate => :true, :dependent => :destroy - accepts_nested_attributes_for :footnotes, :reject_if => :all_blank, :allow_destroy => true + has_many :footnotes, :inverse_of => :line, :validate => :true, :dependent => :destroy + accepts_nested_attributes_for :footnotes, :reject_if => :all_blank, :allow_destroy => true - attr_reader :group_of_line_tokens + attr_reader :group_of_line_tokens - # validates_presence_of :network - # validates_presence_of :company + # validates_presence_of :network + # validates_presence_of :company - validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :stable_id, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :text_color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :stable_id, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :text_color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true - validates_presence_of :name + validates_presence_of :name - scope :by_text, ->(text) { where('lower(name) LIKE :t or lower(published_name) LIKE :t or lower(objectid) LIKE :t or lower(comment) LIKE :t or lower(number) LIKE :t', - t: "%#{text.downcase}%") } + scope :by_text, ->(text) { where('lower(name) LIKE :t or lower(published_name) LIKE :t or lower(objectid) LIKE :t or lower(comment) LIKE :t or lower(number) LIKE :t', + t: "%#{text.downcase}%") } - def self.nullable_attributes - [:published_name, :number, :comment, :url, :color, :text_color, :stable_id] - end + def self.nullable_attributes + [:published_name, :number, :comment, :url, :color, :text_color, :stable_id] + end - def geometry_presenter - Chouette::Geometry::LinePresenter.new self - end + def geometry_presenter + Chouette::Geometry::LinePresenter.new self + end - def commercial_stop_areas - Chouette::StopArea.joins(:children => [:stop_points => [:route => :line] ]).where(:lines => {:id => self.id}).uniq - end + def commercial_stop_areas + Chouette::StopArea.joins(:children => [:stop_points => [:route => :line] ]).where(:lines => {:id => self.id}).uniq + end - def stop_areas - Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}) - end + def stop_areas + Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}) + end - def stop_areas_last_parents - Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}).collect(&:root).flatten.uniq - end + def stop_areas_last_parents + Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}).collect(&:root).flatten.uniq + end - def group_of_line_tokens=(ids) - self.group_of_line_ids = ids.split(",") - end + def group_of_line_tokens=(ids) + self.group_of_line_ids = ids.split(",") + end - def vehicle_journey_frequencies? - self.vehicle_journeys.unscoped.where(journey_category: 1).count > 0 - end + def vehicle_journey_frequencies? + self.vehicle_journeys.unscoped.where(journey_category: 1).count > 0 + end - def display_name - [self.get_objectid.local_id, number, name, company.try(:name)].compact.join(' - ') - end + def display_name + [self.get_objectid.local_id, number, name, company.try(:name)].compact.join(' - ') + end - def companies - line_referential.companies.where(id: ([company_id] + Array(secondary_company_ids)).compact) - end + def companies + line_referential.companies.where(id: ([company_id] + Array(secondary_company_ids)).compact) + end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/link_orientation_type.rb b/app/models/chouette/link_orientation_type.rb index ec279aba3..c3addf4b4 100644 --- a/app/models/chouette/link_orientation_type.rb +++ b/app/models/chouette/link_orientation_type.rb @@ -1,49 +1,51 @@ -class Chouette::LinkOrientationType < ActiveSupport::StringInquirer +module Chouette + class LinkOrientationType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - def to_i - @numerical_code - end + def to_i + @numerical_code + end - def inspect - "#{to_s}/#{to_i}" - end + def inspect + "#{to_s}/#{to_i}" + end - def name - camelize - end + def name + camelize + end - @@definitions = [ - ["access_point_to_stop_area", 0], - ["stop_area_to_access_point", 1] - ] - cattr_reader :definitions + @@definitions = [ + ["access_point_to_stop_area", 0], + ["stop_area_to_access_point", 1] + ] + cattr_reader :definitions - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/loader.rb b/app/models/chouette/loader.rb index 40a2be4ee..7ab696dab 100644 --- a/app/models/chouette/loader.rb +++ b/app/models/chouette/loader.rb @@ -1,110 +1,112 @@ -class Chouette::Loader +module Chouette + class Loader - attr_reader :schema, :database, :user, :password, :host + attr_reader :schema, :database, :user, :password, :host - def initialize(schema) - @schema = schema + def initialize(schema) + @schema = schema - Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| - @database = config[:database] - @user = config[:username] - @password = config[:password] - @host = (config[:host] or "localhost") + Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| + @database = config[:database] + @user = config[:username] + @password = config[:password] + @host = (config[:host] or "localhost") + end end - end - # Load dump where datas are in schema 'chouette' - def load_dump(file) - logger.info "Load #{file} in schema #{schema}" - with_pg_password do - execute!("sed -e 's/ chouette/ \"#{schema}\"/' -e 's/ OWNER TO .*;/ OWNER TO #{user};/' #{file} | psql #{pg_options} --set ON_ERROR_ROLLBACK=1 --set ON_ERROR_STOP=1") + # Load dump where datas are in schema 'chouette' + def load_dump(file) + logger.info "Load #{file} in schema #{schema}" + with_pg_password do + execute!("sed -e 's/ chouette/ \"#{schema}\"/' -e 's/ OWNER TO .*;/ OWNER TO #{user};/' #{file} | psql #{pg_options} --set ON_ERROR_ROLLBACK=1 --set ON_ERROR_STOP=1") + end + self end - self - end - def self.chouette_command=(command) - Chouette::Command.command = command - end + def self.chouette_command=(command) + Chouette::Command.command = command + end - class << self - deprecate :chouette_command= => "Use Chouette::Command.command =" - end + class << self + deprecate :chouette_command= => "Use Chouette::Command.command =" + end - def chouette_command - @chouette_command ||= Chouette::Command.new(:schema => schema) - end + def chouette_command + @chouette_command ||= Chouette::Command.new(:schema => schema) + end - def import(file, options = {}) - options = { - :format => :neptune - }.merge(options) - - command_options = { - :c => "import", - :o => "line", - :format => options.delete(:format).to_s.upcase, - :input_file => File.expand_path(file), - :optimize_memory => true - }.merge(options) - - logger.info "Import #{file} in schema #{schema}" - chouette_command.run! command_options - end + def import(file, options = {}) + options = { + :format => :neptune + }.merge(options) + + command_options = { + :c => "import", + :o => "line", + :format => options.delete(:format).to_s.upcase, + :input_file => File.expand_path(file), + :optimize_memory => true + }.merge(options) + + logger.info "Import #{file} in schema #{schema}" + chouette_command.run! command_options + end - def backup(file) - logger.info "Backup schema #{schema} in #{file}" + def backup(file) + logger.info "Backup schema #{schema} in #{file}" - with_pg_password do - execute!("pg_dump -n #{schema} -f #{file} #{pg_options}") - end + with_pg_password do + execute!("pg_dump -n #{schema} -f #{file} #{pg_options}") + end - self - end + self + end - def pg_options - [].tap do |options| - options << "-U #{user}" if user - options << "-h #{host}" if host - options << database - end.join(" ") - end + def pg_options + [].tap do |options| + options << "-U #{user}" if user + options << "-h #{host}" if host + options << database + end.join(" ") + end - def create - logger.info "Create schema #{schema}" - with_pg_password do - execute!("psql -c 'CREATE SCHEMA \"#{schema}\";' #{pg_options}") + def create + logger.info "Create schema #{schema}" + with_pg_password do + execute!("psql -c 'CREATE SCHEMA \"#{schema}\";' #{pg_options}") + end + self end - self - end - def drop - logger.info "Drop schema #{schema}" - with_pg_password do - execute!("psql -c 'DROP SCHEMA \"#{schema}\" CASCADE;' #{pg_options}") + def drop + logger.info "Drop schema #{schema}" + with_pg_password do + execute!("psql -c 'DROP SCHEMA \"#{schema}\" CASCADE;' #{pg_options}") + end + self end - self - end - def with_pg_password(&block) - ENV['PGPASSWORD'] = password.to_s if password - begin - yield - ensure - ENV['PGPASSWORD'] = nil + def with_pg_password(&block) + ENV['PGPASSWORD'] = password.to_s if password + begin + yield + ensure + ENV['PGPASSWORD'] = nil + end end - end - @@binarisation_command = "binarisation" - cattr_accessor :binarisation_command + @@binarisation_command = "binarisation" + cattr_accessor :binarisation_command - def binarize(period, target_directory) - # TODO check these computed daybefore/dayafter - day_before = Date.today - period.begin - day_after = period.end - period.begin + def binarize(period, target_directory) + # TODO check these computed daybefore/dayafter + day_before = Date.today - period.begin + day_after = period.end - period.begin - execute! "#{binarisation_command} --host=#{host} --dbname=#{database} --user=#{user} --password=#{password} --schema=#{schema} --daybefore=#{day_before} --dayafter=#{day_after} --targetdirectory=#{target_directory}" - end + execute! "#{binarisation_command} --host=#{host} --dbname=#{database} --user=#{user} --password=#{password} --schema=#{schema} --daybefore=#{day_before} --dayafter=#{day_after} --targetdirectory=#{target_directory}" + end - include Chouette::CommandLineSupport + include Chouette::CommandLineSupport -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb index d4c9a19dd..c51de3984 100644 --- a/app/models/chouette/network.rb +++ b/app/models/chouette/network.rb @@ -1,50 +1,51 @@ -class Chouette::Network < Chouette::ActiveRecord - include NetworkRestrictions - include LineReferentialSupport - include ObjectidSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class Network < Chouette::ActiveRecord + include NetworkRestrictions + include LineReferentialSupport + include ObjectidSupport + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - has_many :lines + has_many :lines - attr_accessor :source_type_name + attr_accessor :source_type_name - validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true - validates_presence_of :name - validates_presence_of :objectid_format + validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true + validates_presence_of :name + validates_presence_of :objectid_format - def self.object_id_key - "PTNetwork" - end - - def self.nullable_attributes - [:source_name, :source_type, :source_identifier, :comment] - end + def self.object_id_key + "PTNetwork" + end - def commercial_stop_areas - Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :network] ] ]).where(:networks => {:id => self.id}).uniq - end + def self.nullable_attributes + [:source_name, :source_type, :source_identifier, :comment] + end - def stop_areas - Chouette::StopArea.joins(:stop_points => [:route => [:line => :network] ]).where(:networks => {:id => self.id}) - end + def commercial_stop_areas + Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :network] ] ]).where(:networks => {:id => self.id}).uniq + end - def source_type_name - # return nil if source_type is nil - source_type && Chouette::SourceType.new( source_type.underscore) - end + def stop_areas + Chouette::StopArea.joins(:stop_points => [:route => [:line => :network] ]).where(:networks => {:id => self.id}) + end - def source_type_name=(source_type_name) - self.source_type = (source_type_name ? source_type_name.camelcase : nil) - end + def source_type_name + # return nil if source_type is nil + source_type && Chouette::SourceType.new( source_type.underscore) + end - @@source_type_names = nil - def self.source_type_names - @@source_type_names ||= Chouette::SourceType.all.select do |source_type_name| - source_type_name.to_i > 0 + def source_type_name=(source_type_name) + self.source_type = (source_type_name ? source_type_name.camelcase : nil) end - end + @@source_type_names = nil + def self.source_type_names + @@source_type_names ||= Chouette::SourceType.all.select do |source_type_name| + source_type_name.to_i > 0 + end + end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/netex.rb b/app/models/chouette/objectid/netex.rb index b83ef7b8d..7953c6b12 100644 --- a/app/models/chouette/objectid/netex.rb +++ b/app/models/chouette/objectid/netex.rb @@ -1,29 +1,33 @@ -class Chouette::Objectid::Netex - include ActiveModel::Model +module Chouette + module Objectid + class Netex + include ActiveModel::Model - attr_accessor :provider_id, :object_type, :local_id, :creation_id - validates_presence_of :provider_id, :object_type, :local_id, :creation_id - validate :must_respect_format + attr_accessor :provider_id, :object_type, :local_id, :creation_id + validates_presence_of :provider_id, :object_type, :local_id, :creation_id + validate :must_respect_format - def initialize(**attributes) - @provider_id ||= (attributes[:provider_id] ||= 'chouette') - @object_type = attributes[:object_type] - @local_id = attributes[:local_id] - @creation_id = (attributes[:creation_id] ||= 'LOC') - end + def initialize(**attributes) + @provider_id ||= (attributes[:provider_id] ||= 'chouette') + @object_type = attributes[:object_type] + @local_id = attributes[:local_id] + @creation_id = (attributes[:creation_id] ||= 'LOC') + end - @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ - cattr_reader :format + @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ + cattr_reader :format - def to_s - "#{self.provider_id}:#{self.object_type}:#{self.local_id}:#{self.creation_id}" - end + def to_s + "#{self.provider_id}:#{self.object_type}:#{self.local_id}:#{self.creation_id}" + end - def must_respect_format - self.to_s.match(format) - end + def must_respect_format + self.to_s.match(format) + end - def short_id - local_id + def short_id + local_id + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_codifligne.rb b/app/models/chouette/objectid/stif_codifligne.rb index 21d2463eb..a1e40f0a1 100644 --- a/app/models/chouette/objectid/stif_codifligne.rb +++ b/app/models/chouette/objectid/stif_codifligne.rb @@ -1,20 +1,24 @@ -class Chouette::Objectid::StifCodifligne < Chouette::Objectid::Netex +module Chouette + module Objectid + class StifCodifligne < Chouette::Objectid::Netex - attr_accessor :sync_id - validates_presence_of :sync_id - validates :creation_id, presence: false + attr_accessor :sync_id + validates_presence_of :sync_id + validates :creation_id, presence: false - @@format = /^([A-Za-z_]+):([A-Za-z]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ + @@format = /^([A-Za-z_]+):([A-Za-z]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ - def initialize(**attributes) - @provider_id = attributes[:provider_id] - @object_type = attributes[:object_type] - @local_id = attributes[:local_id] - @sync_id = attributes[:sync_id] - super - end + def initialize(**attributes) + @provider_id = attributes[:provider_id] + @object_type = attributes[:object_type] + @local_id = attributes[:local_id] + @sync_id = attributes[:sync_id] + super + end - def to_s - "#{self.provider_id}:#{self.sync_id}:#{self.object_type}:#{self.local_id}" + def to_s + "#{self.provider_id}:#{self.sync_id}:#{self.object_type}:#{self.local_id}" + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb index 26700bf4b..80208af56 100644 --- a/app/models/chouette/objectid/stif_netex.rb +++ b/app/models/chouette/objectid/stif_netex.rb @@ -1,11 +1,15 @@ -class Chouette::Objectid::StifNetex < Chouette::Objectid::Netex +module Chouette + module Objectid + class StifNetex < Chouette::Objectid::Netex - def initialize(**attributes) - @provider_id = (attributes[:provider_id] ||= 'stif') - super - end + def initialize(**attributes) + @provider_id = (attributes[:provider_id] ||= 'stif') + super + end - def short_id - local_id.try(:split, "-").try(:[], -1) + def short_id + local_id.try(:split, "-").try(:[], -1) + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_reflex.rb b/app/models/chouette/objectid/stif_reflex.rb index 57dbede2e..69a3f52fa 100644 --- a/app/models/chouette/objectid/stif_reflex.rb +++ b/app/models/chouette/objectid/stif_reflex.rb @@ -1,20 +1,23 @@ -class Chouette::Objectid::StifReflex < Chouette::Objectid::Netex +module Chouette + module Objectid + class StifReflex < Chouette::Objectid::Netex - attr_accessor :country_code, :zip_code - validates_presence_of :country_code, :zip_code - validates :creation_id, presence: false + attr_accessor :country_code, :zip_code + validates_presence_of :country_code, :zip_code + validates :creation_id, presence: false - @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ + @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ - def initialize(**attributes) - @provider_id = attributes[:provider_id] - @country_code = attributes[:country_code] - @zip_code = attributes[:zip_code] - super - end + def initialize(**attributes) + @provider_id = attributes[:provider_id] + @country_code = attributes[:country_code] + @zip_code = attributes[:zip_code] + super + end - def to_s - "#{self.country_code}:#{self.zip_code}:#{self.object_type}:#{self.local_id}:#{self.provider_id}" + def to_s + "#{self.country_code}:#{self.zip_code}:#{self.object_type}:#{self.local_id}:#{self.provider_id}" + end + end end - end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/netex.rb b/app/models/chouette/objectid_formatter/netex.rb index 35bb43ab8..7279fdaa5 100644 --- a/app/models/chouette/objectid_formatter/netex.rb +++ b/app/models/chouette/objectid_formatter/netex.rb @@ -1,14 +1,18 @@ -class Chouette::ObjectidFormatter::Netex - def before_validation(model) - model.update_attributes(objectid: Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub(/Chouette::/,'')).to_s) unless model.read_attribute(:objectid) - end +module Chouette + module ObjectidFormatter + class Netex + def before_validation(model) + model.update_attributes(objectid: Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub(/Chouette::/,'')).to_s) unless model.read_attribute(:objectid) + end - def after_commit(model) - # unused method in this context - end + def after_commit(model) + # unused method in this context + end - def get_objectid(definition) - parts = definition.try(:split, ":") - Chouette::Objectid::Netex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) rescue nil + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::Netex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) rescue nil + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/stif_codifligne.rb b/app/models/chouette/objectid_formatter/stif_codifligne.rb index d9849ef1e..0624fc8a8 100644 --- a/app/models/chouette/objectid_formatter/stif_codifligne.rb +++ b/app/models/chouette/objectid_formatter/stif_codifligne.rb @@ -1,14 +1,18 @@ -class Chouette::ObjectidFormatter::StifCodifligne - def before_validation(model) - # unused method in this context - end +module Chouette + module ObjectidFormatter + class Chouette::ObjectidFormatter::StifCodifligne + def before_validation(model) + # unused method in this context + end - def after_commit(model) - # unused method in this context - end + def after_commit(model) + # unused method in this context + end - def get_objectid(definition) - parts = definition.try(:split, ":") - Chouette::Objectid::StifCodifligne.new(provider_id: parts[0], sync_id: parts[1], object_type: parts[2], local_id: parts[3]) rescue nil + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::StifCodifligne.new(provider_id: parts[0], sync_id: parts[1], object_type: parts[2], local_id: parts[3]) rescue nil + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/stif_netex.rb b/app/models/chouette/objectid_formatter/stif_netex.rb index fa73e9cbd..0256754bf 100644 --- a/app/models/chouette/objectid_formatter/stif_netex.rb +++ b/app/models/chouette/objectid_formatter/stif_netex.rb @@ -1,14 +1,18 @@ -class Chouette::ObjectidFormatter::StifNetex - def before_validation(model) - model.attributes = {objectid: "__pending_id__#{SecureRandom.uuid}"} unless model.read_attribute(:objectid) - end +module Chouette + module ObjectidFormatter + class Chouette::ObjectidFormatter::StifNetex + def before_validation(model) + model.attributes = {objectid: "__pending_id__#{SecureRandom.uuid}"} unless model.read_attribute(:objectid) + end - def after_commit(model) - model.update_attributes(objectid: Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub(/Chouette::/,''), local_id: model.local_id).to_s) - end + def after_commit(model) + model.update_attributes(objectid: Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub(/Chouette::/,''), local_id: model.local_id).to_s) + end - def get_objectid(definition) - parts = definition.try(:split, ":") - Chouette::Objectid::StifNetex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) rescue nil + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::StifNetex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) rescue nil + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/stif_reflex.rb b/app/models/chouette/objectid_formatter/stif_reflex.rb index fc2971ca7..5637f2806 100644 --- a/app/models/chouette/objectid_formatter/stif_reflex.rb +++ b/app/models/chouette/objectid_formatter/stif_reflex.rb @@ -1,14 +1,18 @@ -class Chouette::ObjectidFormatter::StifReflex - def before_validation(model) - # unused method in this context - end +module Chouette + module ObjectidFormatter + class Chouette::ObjectidFormatter::StifReflex + def before_validation(model) + # unused method in this context + end - def after_commit(model) - # unused method in this context - end + def after_commit(model) + # unused method in this context + end - def get_objectid(definition) - parts = definition.try(:split, ":") - Chouette::Objectid::StifReflex.new(country_code: parts[0], zip_code: parts[1], object_type: parts[2], local_id: parts[3], provider_id: parts[4]) rescue nil + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::StifReflex.new(country_code: parts[0], zip_code: parts[1], object_type: parts[2], local_id: parts[3], provider_id: parts[4]) rescue nil + end + end end end
\ No newline at end of file diff --git a/app/models/chouette/pt_link.rb b/app/models/chouette/pt_link.rb index 8a4e368ea..5bf77da02 100644 --- a/app/models/chouette/pt_link.rb +++ b/app/models/chouette/pt_link.rb @@ -1,37 +1,37 @@ require 'geokit' -class Chouette::PtLink < Chouette::ActiveRecord - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class PtLink < Chouette::ActiveRecord + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - include Geokit::Mappable + include Geokit::Mappable - def geometry - the_geom - end + def geometry + the_geom + end - def self.import_csv - csv_file = Rails.root + "chouette_pt_links.csv" - if File.exists?( csv_file) - csv = CSV::Reader.parse(File.read(csv_file)) + def self.import_csv + csv_file = Rails.root + "chouette_pt_links.csv" + if File.exists?( csv_file) + csv = CSV::Reader.parse(File.read(csv_file)) - slug = csv.shift.first + slug = csv.shift.first - Network::Base.find_by_slug( slug).tune_connection + Network::Base.find_by_slug( slug).tune_connection - csv.each do |row| - origin = Chouette::StopArea.find_by_objectid( row[0]) - destination = Chouette::StopArea.find_by_objectid( row[1]) + csv.each do |row| + origin = Chouette::StopArea.find_by_objectid( row[0]) + destination = Chouette::StopArea.find_by_objectid( row[1]) - raise "unknown origin #{row[0]}" unless origin - raise "unknown destination #{row[1]}" unless destination + raise "unknown origin #{row[0]}" unless origin + raise "unknown destination #{row[1]}" unless destination - Chouette::PtLink.create( :departure_id => origin.id, - :arrival_id => destination.id, - :the_geom => GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb( row[2])) + Chouette::PtLink.create( :departure_id => origin.id, + :arrival_id => destination.id, + :the_geom => GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb( row[2])) + end end end - end - -end +end
\ No newline at end of file diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 451510b79..6794ba3e4 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -1,198 +1,200 @@ -class Chouette::Route < Chouette::TridentActiveRecord - include RouteRestrictions - include ChecksumSupport - include ObjectidSupport +module Chouette + class Route < Chouette::TridentActiveRecord + include RouteRestrictions + include ChecksumSupport + include ObjectidSupport - extend Enumerize - extend ActiveModel::Naming + extend Enumerize + extend ActiveModel::Naming - enumerize :direction, in: %i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east) - enumerize :wayback, in: %i(outbound inbound), default: :outbound + enumerize :direction, in: %i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east) + enumerize :wayback, in: %i(outbound inbound), default: :outbound - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - def self.nullable_attributes - [:published_name, :comment, :number, :name, :direction, :wayback] - end + def self.nullable_attributes + [:published_name, :comment, :number, :name, :direction, :wayback] + end - belongs_to :line - belongs_to :opposite_route, :class_name => 'Chouette::Route', :foreign_key => :opposite_route_id + belongs_to :line + belongs_to :opposite_route, :class_name => 'Chouette::Route', :foreign_key => :opposite_route_id - has_many :routing_constraint_zones - has_many :journey_patterns, :dependent => :destroy - has_many :vehicle_journeys, :dependent => :destroy do - def timeless - Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + has_many :routing_constraint_zones + has_many :journey_patterns, :dependent => :destroy + has_many :vehicle_journeys, :dependent => :destroy do + def timeless + Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + end end - end - has_many :vehicle_journey_frequencies, :dependent => :destroy do - # Todo : I think there is a better way to do this. - def timeless - Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + has_many :vehicle_journey_frequencies, :dependent => :destroy do + # Todo : I think there is a better way to do this. + def timeless + Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + end end - end - has_many :stop_points, -> { order("position") }, :dependent => :destroy do - def find_by_stop_area(stop_area) - stop_area_ids = Integer === stop_area ? [stop_area] : (stop_area.children_in_depth + [stop_area]).map(&:id) - where( :stop_area_id => stop_area_ids).first or - raise ActiveRecord::RecordNotFound.new("Can't find a StopArea #{stop_area.inspect} in Route #{proxy_owner.id.inspect}'s StopPoints") - end - - def between(departure, arrival) - between_positions = [departure, arrival].collect do |endpoint| - case endpoint - when Chouette::StopArea - find_by_stop_area(endpoint).position - when Chouette::StopPoint - endpoint.position - when Integer - endpoint - else - raise ActiveRecord::RecordNotFound.new("Can't determine position in route #{proxy_owner.id} with #{departure.inspect}") + has_many :stop_points, -> { order("position") }, :dependent => :destroy do + def find_by_stop_area(stop_area) + stop_area_ids = Integer === stop_area ? [stop_area] : (stop_area.children_in_depth + [stop_area]).map(&:id) + where( :stop_area_id => stop_area_ids).first or + raise ActiveRecord::RecordNotFound.new("Can't find a StopArea #{stop_area.inspect} in Route #{proxy_owner.id.inspect}'s StopPoints") + end + + def between(departure, arrival) + between_positions = [departure, arrival].collect do |endpoint| + case endpoint + when Chouette::StopArea + find_by_stop_area(endpoint).position + when Chouette::StopPoint + endpoint.position + when Integer + endpoint + else + raise ActiveRecord::RecordNotFound.new("Can't determine position in route #{proxy_owner.id} with #{departure.inspect}") + end end + where(" position between ? and ? ", between_positions.first, between_positions.last) end - where(" position between ? and ? ", between_positions.first, between_positions.last) end - end - has_many :stop_areas, -> { order('stop_points.position ASC') }, :through => :stop_points do - def between(departure, arrival) - departure, arrival = [departure, arrival].map do |endpoint| - String === endpoint ? Chouette::StopArea.find_by_objectid(endpoint) : endpoint + has_many :stop_areas, -> { order('stop_points.position ASC') }, :through => :stop_points do + def between(departure, arrival) + departure, arrival = [departure, arrival].map do |endpoint| + String === endpoint ? Chouette::StopArea.find_by_objectid(endpoint) : endpoint + end + proxy_owner.stop_points.between(departure, arrival).includes(:stop_area).collect(&:stop_area) end - proxy_owner.stop_points.between(departure, arrival).includes(:stop_area).collect(&:stop_area) end - end - accepts_nested_attributes_for :stop_points, :allow_destroy => :true + accepts_nested_attributes_for :stop_points, :allow_destroy => :true - validates_presence_of :name - validates_presence_of :published_name - validates_presence_of :line + validates_presence_of :name + validates_presence_of :published_name + validates_presence_of :line - # validates_presence_of :direction - # validates_presence_of :wayback + # validates_presence_of :direction + # validates_presence_of :wayback - validates :wayback, inclusion: { in: self.wayback.values } + validates :wayback, inclusion: { in: self.wayback.values } - after_commit :journey_patterns_control_route_sections + after_commit :journey_patterns_control_route_sections - def duplicate - overrides = { - 'opposite_route_id' => nil - } - keys_for_create = attributes.keys - %w{id objectid created_at updated_at} - atts_for_create = attributes - .slice(*keys_for_create) - .merge(overrides) - new_route = self.class.create!(atts_for_create) - duplicate_stop_points(for_route: new_route) - new_route - end + def duplicate + overrides = { + 'opposite_route_id' => nil + } + keys_for_create = attributes.keys - %w{id objectid created_at updated_at} + atts_for_create = attributes + .slice(*keys_for_create) + .merge(overrides) + new_route = self.class.create!(atts_for_create) + duplicate_stop_points(for_route: new_route) + new_route + end - def duplicate_stop_points(for_route:) - stop_points.each(&duplicate_stop_point(for_route: for_route)) - end - def duplicate_stop_point(for_route:) - -> stop_point do - stop_point.duplicate(for_route: for_route) + def duplicate_stop_points(for_route:) + stop_points.each(&duplicate_stop_point(for_route: for_route)) + end + def duplicate_stop_point(for_route:) + -> stop_point do + stop_point.duplicate(for_route: for_route) + end end - end - def local_id - "IBOO-#{self.referential.id}-#{self.line.get_objectid.local_id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.line.get_objectid.local_id}-#{self.id}" + end - def geometry_presenter - Chouette::Geometry::RoutePresenter.new self - end + def geometry_presenter + Chouette::Geometry::RoutePresenter.new self + end - @@opposite_waybacks = { outbound: :inbound, inbound: :outbound} - def opposite_wayback - @@opposite_waybacks[wayback.to_sym] - end + @@opposite_waybacks = { outbound: :inbound, inbound: :outbound} + def opposite_wayback + @@opposite_waybacks[wayback.to_sym] + end + + def opposite_route_candidates + if opposite_wayback + line.routes.where(opposite_route: [nil, self], wayback: opposite_wayback) + else + self.class.none + end + end - def opposite_route_candidates - if opposite_wayback - line.routes.where(opposite_route: [nil, self], wayback: opposite_wayback) - else - self.class.none + validate :check_opposite_route + def check_opposite_route + return unless opposite_route && opposite_wayback + unless opposite_route_candidates.include?(opposite_route) + errors.add(:opposite_route_id, :invalid) + end end - end - validate :check_opposite_route - def check_opposite_route - return unless opposite_route && opposite_wayback - unless opposite_route_candidates.include?(opposite_route) - errors.add(:opposite_route_id, :invalid) + def checksum_attributes + values = self.slice(*['name', 'published_name', 'wayback']).values + values.tap do |attrs| + attrs << self.stop_points.map{|sp| "#{sp.stop_area.user_objectid}#{sp.for_boarding}#{sp.for_alighting}" }.join + attrs << self.routing_constraint_zones.map(&:checksum) + end end - end - def checksum_attributes - values = self.slice(*['name', 'published_name', 'wayback']).values - values.tap do |attrs| - attrs << self.stop_points.map{|sp| "#{sp.stop_area.user_objectid}#{sp.for_boarding}#{sp.for_alighting}" }.join - attrs << self.routing_constraint_zones.map(&:checksum) + def geometry + points = stop_areas.map(&:to_lat_lng).compact.map do |loc| + [loc.lng, loc.lat] + end + GeoRuby::SimpleFeatures::LineString.from_coordinates( points, 4326) end - end - def geometry - points = stop_areas.map(&:to_lat_lng).compact.map do |loc| - [loc.lng, loc.lat] + def time_tables + vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq end - GeoRuby::SimpleFeatures::LineString.from_coordinates( points, 4326) - end - def time_tables - vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq - end + def sorted_vehicle_journeys(journey_category_model) + send(journey_category_model) + .joins(:journey_pattern, :vehicle_journey_at_stops) + .joins('LEFT JOIN "time_tables_vehicle_journeys" ON "time_tables_vehicle_journeys"."vehicle_journey_id" = "vehicle_journeys"."id" LEFT JOIN "time_tables" ON "time_tables"."id" = "time_tables_vehicle_journeys"."time_table_id"') + .where("vehicle_journey_at_stops.stop_point_id=journey_patterns.departure_stop_point_id") + .order("vehicle_journey_at_stops.departure_time") + end - def sorted_vehicle_journeys(journey_category_model) - send(journey_category_model) - .joins(:journey_pattern, :vehicle_journey_at_stops) - .joins('LEFT JOIN "time_tables_vehicle_journeys" ON "time_tables_vehicle_journeys"."vehicle_journey_id" = "vehicle_journeys"."id" LEFT JOIN "time_tables" ON "time_tables"."id" = "time_tables_vehicle_journeys"."time_table_id"') - .where("vehicle_journey_at_stops.stop_point_id=journey_patterns.departure_stop_point_id") - .order("vehicle_journey_at_stops.departure_time") - end + def stop_point_permutation?( stop_point_ids) + stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort + end - def stop_point_permutation?( stop_point_ids) - stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort - end + def reorder!( stop_point_ids) + return false unless stop_point_permutation?( stop_point_ids) + + stop_area_id_by_stop_point_id = {} + stop_points.each do |sp| + stop_area_id_by_stop_point_id.merge!( sp.id => sp.stop_area_id) + end - def reorder!( stop_point_ids) - return false unless stop_point_permutation?( stop_point_ids) + reordered_stop_area_ids = [] + stop_point_ids.each do |stop_point_id| + reordered_stop_area_ids << stop_area_id_by_stop_point_id[ stop_point_id.to_i] + end - stop_area_id_by_stop_point_id = {} - stop_points.each do |sp| - stop_area_id_by_stop_point_id.merge!( sp.id => sp.stop_area_id) - end + stop_points.each_with_index do |sp, index| + if sp.stop_area_id.to_s != reordered_stop_area_ids[ index].to_s + #result = sp.update_attributes( :stop_area_id => reordered_stop_area_ids[ index]) + sp.stop_area_id = reordered_stop_area_ids[ index] + result = sp.save! + end + end - reordered_stop_area_ids = [] - stop_point_ids.each do |stop_point_id| - reordered_stop_area_ids << stop_area_id_by_stop_point_id[ stop_point_id.to_i] + return true end - stop_points.each_with_index do |sp, index| - if sp.stop_area_id.to_s != reordered_stop_area_ids[ index].to_s - #result = sp.update_attributes( :stop_area_id => reordered_stop_area_ids[ index]) - sp.stop_area_id = reordered_stop_area_ids[ index] - result = sp.save! + def journey_patterns_control_route_sections + self.journey_patterns.each do |jp| + jp.control_route_sections end end - return true - end + protected - def journey_patterns_control_route_sections - self.journey_patterns.each do |jp| - jp.control_route_sections + def self.vehicle_journeys_timeless(stop_point_id) + all( :conditions => ['vehicle_journeys.id NOT IN (?)', Chouette::VehicleJourneyAtStop.where(stop_point_id: stop_point_id).pluck(:vehicle_journey_id)] ) end - end - - protected - def self.vehicle_journeys_timeless(stop_point_id) - all( :conditions => ['vehicle_journeys.id NOT IN (?)', Chouette::VehicleJourneyAtStop.where(stop_point_id: stop_point_id).pluck(:vehicle_journey_id)] ) end - -end +end
\ No newline at end of file diff --git a/app/models/chouette/route_section.rb b/app/models/chouette/route_section.rb index 3ce4232be..e4b4347e7 100644 --- a/app/models/chouette/route_section.rb +++ b/app/models/chouette/route_section.rb @@ -1,81 +1,83 @@ -class Chouette::RouteSection < Chouette::TridentActiveRecord - belongs_to :departure, class_name: 'Chouette::StopArea' - belongs_to :arrival, class_name: 'Chouette::StopArea' - has_many :journey_pattern_sections - has_many :journey_patterns, through: :journey_pattern_sections, dependent: :destroy +module Chouette + class RouteSection < Chouette::TridentActiveRecord + belongs_to :departure, class_name: 'Chouette::StopArea' + belongs_to :arrival, class_name: 'Chouette::StopArea' + has_many :journey_pattern_sections + has_many :journey_patterns, through: :journey_pattern_sections, dependent: :destroy - validates :departure, :arrival, :processed_geometry, presence: true + validates :departure, :arrival, :processed_geometry, presence: true - scope :by_endpoint_name, ->(endpoint, name) do - joins("INNER JOIN stop_areas #{endpoint} ON #{endpoint}.id = route_sections.#{endpoint}_id").where(["#{endpoint}.name ilike ?", "%#{name}%"]) - end - scope :by_line_id, ->(line_id) do - joins(:journey_pattern_sections, :journey_patterns).joins('INNER JOIN routes ON journey_patterns.route_id = routes.id').where("routes.line_id = #{line_id}") - end + scope :by_endpoint_name, ->(endpoint, name) do + joins("INNER JOIN stop_areas #{endpoint} ON #{endpoint}.id = route_sections.#{endpoint}_id").where(["#{endpoint}.name ilike ?", "%#{name}%"]) + end + scope :by_line_id, ->(line_id) do + joins(:journey_pattern_sections, :journey_patterns).joins('INNER JOIN routes ON journey_patterns.route_id = routes.id').where("routes.line_id = #{line_id}") + end - def stop_areas - [departure, arrival].compact - end + def stop_areas + [departure, arrival].compact + end - def default_geometry - points = stop_areas.collect(&:geometry).compact - GeoRuby::SimpleFeatures::LineString.from_points(points) if points.many? - end + def default_geometry + points = stop_areas.collect(&:geometry).compact + GeoRuby::SimpleFeatures::LineString.from_points(points) if points.many? + end - def name - stop_areas.map do |stop_area| - stop_area.try(:name) or '?' - end.join(' - ') + " (#{geometry_description})" - end + def name + stop_areas.map do |stop_area| + stop_area.try(:name) or '?' + end.join(' - ') + " (#{geometry_description})" + end - def via_count - input_geometry ? [ input_geometry.points.count - 2, 0 ].max : 0 - end + def via_count + input_geometry ? [ input_geometry.points.count - 2, 0 ].max : 0 + end - def geometry_description - if input_geometry || processed_geometry - [ "#{distance.to_i}m" ].tap do |parts| - parts << "#{via_count} #{'via'.pluralize(via_count)}" if via_count > 0 - end.join(' - ') - else - "-" + def geometry_description + if input_geometry || processed_geometry + [ "#{distance.to_i}m" ].tap do |parts| + parts << "#{via_count} #{'via'.pluralize(via_count)}" if via_count > 0 + end.join(' - ') + else + "-" + end end - end - DEFAULT_PROCESSOR = Proc.new { |section| section.input_geometry || section.default_geometry.try(:to_rgeo) } + DEFAULT_PROCESSOR = Proc.new { |section| section.input_geometry || section.default_geometry.try(:to_rgeo) } - @@processor = DEFAULT_PROCESSOR - cattr_accessor :processor + @@processor = DEFAULT_PROCESSOR + cattr_accessor :processor - def instance_processor - no_processing || processor.nil? ? DEFAULT_PROCESSOR : processor - end + def instance_processor + no_processing || processor.nil? ? DEFAULT_PROCESSOR : processor + end + + def process_geometry + if input_geometry_changed? || processed_geometry.nil? + self.processed_geometry = instance_processor.call(self) + self.distance = processed_geometry.to_georuby.to_wgs84.spherical_distance if processed_geometry + end - def process_geometry - if input_geometry_changed? || processed_geometry.nil? - self.processed_geometry = instance_processor.call(self) - self.distance = processed_geometry.to_georuby.to_wgs84.spherical_distance if processed_geometry + true end + before_validation :process_geometry - true - end - before_validation :process_geometry + def editable_geometry=(geometry) + self.input_geometry = geometry + end - def editable_geometry=(geometry) - self.input_geometry = geometry - end + def editable_geometry + input_geometry.try(:to_georuby) or default_geometry + end - def editable_geometry - input_geometry.try(:to_georuby) or default_geometry - end + def editable_geometry_before_type_cast + editable_geometry.to_ewkt + end - def editable_geometry_before_type_cast - editable_geometry.to_ewkt - end + def geometry(mode = nil) + mode ||= :processed + mode == :editable ? editable_geometry : processed_geometry.to_georuby + end - def geometry(mode = nil) - mode ||= :processed - mode == :editable ? editable_geometry : processed_geometry.to_georuby end - -end +end
\ No newline at end of file diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 5f6e5affd..0691ef688 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -1,44 +1,46 @@ -class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord - include ChecksumSupport - include ObjectidSupport +module Chouette + class RoutingConstraintZone < Chouette::TridentActiveRecord + include ChecksumSupport + include ObjectidSupport - belongs_to :route - has_array_of :stop_points, class_name: 'Chouette::StopPoint' + belongs_to :route + has_array_of :stop_points, class_name: 'Chouette::StopPoint' - validates_presence_of :name, :stop_points, :route, :objectid_format - # validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') } - validate :stop_points_belong_to_route, :not_all_stop_points_selected + validates_presence_of :name, :stop_points, :route, :objectid_format + # validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') } + validate :stop_points_belong_to_route, :not_all_stop_points_selected - def local_id - "IBOO-#{self.referential.id}-#{self.route.line.objectid.local_id}-#{self.route.objectid.local_id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.objectid.local_id}-#{self.route.objectid.local_id}-#{self.id}" + end - scope :order_by_stop_points_count, ->(direction) do - order("array_length(stop_point_ids, 1) #{direction}") - end + scope :order_by_stop_points_count, ->(direction) do + order("array_length(stop_point_ids, 1) #{direction}") + end - scope :order_by_route_name, ->(direction) do - joins(:route) - .order("routes.name #{direction}") - end + scope :order_by_route_name, ->(direction) do + joins(:route) + .order("routes.name #{direction}") + end - def checksum_attributes - self.stop_points.map(&:stop_area).map(&:user_objectid) - end + def checksum_attributes + self.stop_points.map(&:stop_area).map(&:user_objectid) + end - def stop_points_belong_to_route - errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp } - end + def stop_points_belong_to_route + errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp } + end - def not_all_stop_points_selected - errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.all_stop_points_selected')) if stop_points.length == route.stop_points.length - end + def not_all_stop_points_selected + errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.all_stop_points_selected')) if stop_points.length == route.stop_points.length + end - def stop_points_count - stop_points.count - end + def stop_points_count + stop_points.count + end - def route_name - route.name + def route_name + route.name + end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/source_type.rb b/app/models/chouette/source_type.rb index 124a6c433..1554d846b 100644 --- a/app/models/chouette/source_type.rb +++ b/app/models/chouette/source_type.rb @@ -1,56 +1,58 @@ -class Chouette::SourceType < ActiveSupport::StringInquirer +module Chouette + class SourceType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - def to_i - @numerical_code - end + def to_i + @numerical_code + end - def inspect - "#{to_s}/#{to_i}" - end + def inspect + "#{to_s}/#{to_i}" + end - def name - camelize - end + def name + camelize + end - @@definitions = [ - ["public_and_private_utilities", 0], - ["road_authorities", 1], - ["transit_operator", 2], - ["public_transport", 3], - ["passenger_transport_coordinating_authority", 4], - ["travel_information_service_provider", 5], - ["travel_agency", 6], - ["individual_subject_of_travel_itinerary", 7], - ["other_information", 8] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@definitions = [ + ["public_and_private_utilities", 0], + ["road_authorities", 1], + ["transit_operator", 2], + ["public_transport", 3], + ["passenger_transport_coordinating_authority", 4], + ["travel_information_service_provider", 5], + ["travel_agency", 6], + ["individual_subject_of_travel_itinerary", 7], + ["other_information", 8] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 513eb4d48..f907f6777 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -1,334 +1,336 @@ require 'geokit' require 'geo_ruby' -class Chouette::StopArea < Chouette::ActiveRecord - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - include Geokit::Mappable - # include StifReflexAttributesSupport - include ProjectionFields - include StopAreaRestrictions - include StopAreaReferentialSupport - include ObjectidSupport - - extend Enumerize - enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) - - with_options dependent: :destroy do |assoc| - assoc.has_many :stop_points - assoc.has_many :access_points - assoc.has_many :access_links - end - - has_and_belongs_to_many :routing_lines, :class_name => 'Chouette::Line', :foreign_key => "stop_area_id", :association_foreign_key => "line_id", :join_table => "routing_constraints_lines", :order => "lines.number" - has_and_belongs_to_many :routing_stops, :class_name => 'Chouette::StopArea', :foreign_key => "parent_id", :association_foreign_key => "child_id", :join_table => "stop_areas_stop_areas", :order => "stop_areas.name" - - belongs_to :stop_area_referential - validates_presence_of :stop_area_referential_id +module Chouette + class StopArea < Chouette::ActiveRecord + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + + include Geokit::Mappable + # include StifReflexAttributesSupport + include ProjectionFields + include StopAreaRestrictions + include StopAreaReferentialSupport + include ObjectidSupport + + extend Enumerize + enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) + + with_options dependent: :destroy do |assoc| + assoc.has_many :stop_points + assoc.has_many :access_points + assoc.has_many :access_links + end - acts_as_tree :foreign_key => 'parent_id', :order => "name" + has_and_belongs_to_many :routing_lines, :class_name => 'Chouette::Line', :foreign_key => "stop_area_id", :association_foreign_key => "line_id", :join_table => "routing_constraints_lines", :order => "lines.number" + has_and_belongs_to_many :routing_stops, :class_name => 'Chouette::StopArea', :foreign_key => "parent_id", :association_foreign_key => "child_id", :join_table => "stop_areas_stop_areas", :order => "stop_areas.name" - attr_accessor :stop_area_type - attr_accessor :children_ids - attr_writer :coordinates + belongs_to :stop_area_referential + validates_presence_of :stop_area_referential_id - after_update :journey_patterns_control_route_sections, - if: Proc.new { |stop_area| ['boarding_position', 'quay'].include? stop_area.stop_area_type } + acts_as_tree :foreign_key => 'parent_id', :order => "name" - validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_blank => true - validates_presence_of :name - validates_presence_of :latitude, :if => :longitude - validates_presence_of :longitude, :if => :latitude - validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true - validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true + attr_accessor :stop_area_type + attr_accessor :children_ids + attr_writer :coordinates - validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true + after_update :journey_patterns_control_route_sections, + if: Proc.new { |stop_area| ['boarding_position', 'quay'].include? stop_area.stop_area_type } - def self.nullable_attributes - [:registration_number, :street_name, :country_code, :fare_code, - :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] - end + validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_blank => true + validates_presence_of :name + validates_presence_of :latitude, :if => :longitude + validates_presence_of :longitude, :if => :latitude + validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true + validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true - after_update :clean_invalid_access_links - before_save :coordinates_to_lat_lng + validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true - def combine_lat_lng - if self.latitude.nil? || self.longitude.nil? - "" - else - self.latitude.to_s+","+self.longitude.to_s + def self.nullable_attributes + [:registration_number, :street_name, :country_code, :fare_code, + :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] end - end - def coordinates - @coordinates || combine_lat_lng - end + after_update :clean_invalid_access_links + before_save :coordinates_to_lat_lng - def coordinates_to_lat_lng - if ! @coordinates.nil? - if @coordinates.empty? - self.latitude = nil - self.longitude = nil + def combine_lat_lng + if self.latitude.nil? || self.longitude.nil? + "" else - self.latitude = BigDecimal.new(@coordinates.split(",").first) - self.longitude = BigDecimal.new(@coordinates.split(",").last) + self.latitude.to_s+","+self.longitude.to_s end - @coordinates = nil end - end - def user_objectid - if objectid =~ /^.*:([0-9A-Za-z_-]+):STIF$/ - $1 - else - id.to_s + def coordinates + @coordinates || combine_lat_lng + end + + def coordinates_to_lat_lng + if ! @coordinates.nil? + if @coordinates.empty? + self.latitude = nil + self.longitude = nil + else + self.latitude = BigDecimal.new(@coordinates.split(",").first) + self.longitude = BigDecimal.new(@coordinates.split(",").last) + end + @coordinates = nil + end end - end - def children_in_depth - return [] if self.children.empty? + def user_objectid + if objectid =~ /^.*:([0-9A-Za-z_-]+):STIF$/ + $1 + else + id.to_s + end + end - self.children + self.children.map do |child| - child.children_in_depth - end.flatten.compact - end + def children_in_depth + return [] if self.children.empty? - def possible_children - case area_type - when "BoardingPosition" then [] - when "Quay" then [] - when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) - [self] - when "StopPlace" then Chouette::StopArea.where(:area_type => ['StopPlace', 'CommercialStopPoint']) - [self] + self.children + self.children.map do |child| + child.children_in_depth + end.flatten.compact end - end + def possible_children + case area_type + when "BoardingPosition" then [] + when "Quay" then [] + when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) - [self] + when "StopPlace" then Chouette::StopArea.where(:area_type => ['StopPlace', 'CommercialStopPoint']) - [self] + end - def possible_parents - case area_type - when "BoardingPosition" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] - when "Quay" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] - when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] - when "StopPlace" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] end - end - def geometry_presenter - Chouette::Geometry::StopAreaPresenter.new self - end + def possible_parents + case area_type + when "BoardingPosition" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] + when "Quay" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] + when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] + when "StopPlace" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] + end + end - def lines - [] - end + def geometry_presenter + Chouette::Geometry::StopAreaPresenter.new self + end - def routes - [] - end + def lines + [] + end - def self.commercial - where :area_type => "CommercialStopPoint" - end + def routes + [] + end - def self.stop_place - where :area_type => "StopPlace" - end + def self.commercial + where :area_type => "CommercialStopPoint" + end - def self.physical - where :area_type => [ "BoardingPosition", "Quay" ] - end + def self.stop_place + where :area_type => "StopPlace" + end + def self.physical + where :area_type => [ "BoardingPosition", "Quay" ] + end - def to_lat_lng - Geokit::LatLng.new(latitude, longitude) if latitude and longitude - end - def geometry - GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude - end + def to_lat_lng + Geokit::LatLng.new(latitude, longitude) if latitude and longitude + end - def geometry=(geometry) - geometry = geometry.to_wgs84 - self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" - end + def geometry + GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude + end - def position - geometry - end + def geometry=(geometry) + geometry = geometry.to_wgs84 + self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" + end - def position=(position) - position = nil if String === position && position == "" - position = Geokit::LatLng.normalize(position), 4326 if String === position - if position - self.latitude = position.lat - self.longitude = position.lng + def position + geometry end - end - def default_position - # for first StopArea ... the bounds is nil :( - Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : nil # FIXME #821 stop_area_referential.envelope.center - end + def position=(position) + position = nil if String === position && position == "" + position = Geokit::LatLng.normalize(position), 4326 if String === position + if position + self.latitude = position.lat + self.longitude = position.lng + end + end - def around(scope, distance) - db = "ST_GeomFromEWKB(ST_MakePoint(longitude, latitude, 4326))" - from = "ST_GeomFromText('POINT(#{self.longitude} #{self.latitude})', 4326)" - scope.where("ST_DWithin(#{db}, #{from}, ?, false)", distance) - end + def default_position + # for first StopArea ... the bounds is nil :( + Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : nil # FIXME #821 stop_area_referential.envelope.center + end - def self.near(origin, distance = 0.3) - origin = origin.to_lat_lng + def around(scope, distance) + db = "ST_GeomFromEWKB(ST_MakePoint(longitude, latitude, 4326))" + from = "ST_GeomFromText('POINT(#{self.longitude} #{self.latitude})', 4326)" + scope.where("ST_DWithin(#{db}, #{from}, ?, false)", distance) + end - lat_degree_units = units_per_latitude_degree(:kms) - lng_degree_units = units_per_longitude_degree(origin.lat, :kms) + def self.near(origin, distance = 0.3) + origin = origin.to_lat_lng - where "SQRT(POW(#{lat_degree_units}*(#{origin.lat}-latitude),2)+POW(#{lng_degree_units}*(#{origin.lng}-longitude),2)) <= #{distance}" - end + lat_degree_units = units_per_latitude_degree(:kms) + lng_degree_units = units_per_longitude_degree(origin.lat, :kms) - def self.bounds - # Give something like : - # [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]] - min_and_max = connection.select_rows("select min(longitude) as min_lon, min(latitude) as min_lat, max(longitude) as max_lon, max(latitude) as max_lat from #{table_name} where latitude is not null and longitude is not null").first - return nil unless min_and_max + where "SQRT(POW(#{lat_degree_units}*(#{origin.lat}-latitude),2)+POW(#{lng_degree_units}*(#{origin.lng}-longitude),2)) <= #{distance}" + end - # Ignore [nil, nil, nil, nil] - min_and_max.compact! - return nil unless min_and_max.size == 4 + def self.bounds + # Give something like : + # [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]] + min_and_max = connection.select_rows("select min(longitude) as min_lon, min(latitude) as min_lat, max(longitude) as max_lon, max(latitude) as max_lat from #{table_name} where latitude is not null and longitude is not null").first + return nil unless min_and_max - min_and_max.collect! { |n| n.to_f } + # Ignore [nil, nil, nil, nil] + min_and_max.compact! + return nil unless min_and_max.size == 4 - # We need something like : - # [[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]] - coordinates = min_and_max.each_slice(2).to_a - GeoRuby::SimpleFeatures::Envelope.from_coordinates coordinates - end + min_and_max.collect! { |n| n.to_f } - def stop_area_type - area_type ? area_type : " " - end + # We need something like : + # [[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]] + coordinates = min_and_max.each_slice(2).to_a + GeoRuby::SimpleFeatures::Envelope.from_coordinates coordinates + end - def stop_area_type=(stop_area_type) - self.area_type = (stop_area_type ? stop_area_type.camelcase : nil) - end + def stop_area_type + area_type ? area_type : " " + end - def children_ids=(children_ids) - children = children_ids.split(',').uniq - # remove unset children - self.children.each do |child| - if (! children.include? child.id) - child.update_attribute :parent_id, nil - end + def stop_area_type=(stop_area_type) + self.area_type = (stop_area_type ? stop_area_type.camelcase : nil) end - # add new children - Chouette::StopArea.find(children).each do |child| - child.update_attribute :parent_id, self.id + + def children_ids=(children_ids) + children = children_ids.split(',').uniq + # remove unset children + self.children.each do |child| + if (! children.include? child.id) + child.update_attribute :parent_id, nil + end + end + # add new children + Chouette::StopArea.find(children).each do |child| + child.update_attribute :parent_id, self.id + end end - end - def routing_stop_ids=(routing_stop_ids) - stops = routing_stop_ids.split(',').uniq - self.routing_stops.clear - Chouette::StopArea.find(stops).each do |stop| - self.routing_stops << stop + def routing_stop_ids=(routing_stop_ids) + stops = routing_stop_ids.split(',').uniq + self.routing_stops.clear + Chouette::StopArea.find(stops).each do |stop| + self.routing_stops << stop + end end - end - def routing_line_ids=(routing_line_ids) - lines = routing_line_ids.split(',').uniq - self.routing_lines.clear - Chouette::Line.find(lines).each do |line| - self.routing_lines << line + def routing_line_ids=(routing_line_ids) + lines = routing_line_ids.split(',').uniq + self.routing_lines.clear + Chouette::Line.find(lines).each do |line| + self.routing_lines << line + end end - end - def self.without_geometry - where("latitude is null or longitude is null") - end + def self.without_geometry + where("latitude is null or longitude is null") + end - def self.with_geometry - where("latitude is not null and longitude is not null") - end + def self.with_geometry + where("latitude is not null and longitude is not null") + end - def self.default_geometry! - count = 0 - where(nil).find_each do |stop_area| - Chouette::StopArea.unscoped do - count += 1 if stop_area.default_geometry! + def self.default_geometry! + count = 0 + where(nil).find_each do |stop_area| + Chouette::StopArea.unscoped do + count += 1 if stop_area.default_geometry! + end end + count end - count - end - - def default_geometry! - new_geometry = default_geometry - update_attribute :geometry, new_geometry if new_geometry - end - def default_geometry - children_geometries = children.with_geometry.map(&:geometry).uniq - GeoRuby::SimpleFeatures::Point.centroid children_geometries if children_geometries.present? - end + def default_geometry! + new_geometry = default_geometry + update_attribute :geometry, new_geometry if new_geometry + end - def generic_access_link_matrix - matrix = Array.new - access_points.each do |access_point| - matrix += access_point.generic_access_link_matrix - end - matrix - end + def default_geometry + children_geometries = children.with_geometry.map(&:geometry).uniq + GeoRuby::SimpleFeatures::Point.centroid children_geometries if children_geometries.present? + end - def detail_access_link_matrix - matrix = Array.new - access_points.each do |access_point| - matrix += access_point.detail_access_link_matrix - end - matrix - end + def generic_access_link_matrix + matrix = Array.new + access_points.each do |access_point| + matrix += access_point.generic_access_link_matrix + end + matrix + end - def children_at_base - list = Array.new - children_in_depth.each do |child| - if child.area_type == 'Quay' || child.area_type == 'BoardingPosition' - list << child + def detail_access_link_matrix + matrix = Array.new + access_points.each do |access_point| + matrix += access_point.detail_access_link_matrix end + matrix end - list - end - def parents - list = Array.new - if !parent.nil? - list << parent - list += parent.parents + def children_at_base + list = Array.new + children_in_depth.each do |child| + if child.area_type == 'Quay' || child.area_type == 'BoardingPosition' + list << child + end + end + list end - list - end - def clean_invalid_access_links - stop_parents = parents - access_links.each do |link| - unless stop_parents.include? link.access_point.stop_area - link.delete + def parents + list = Array.new + if !parent.nil? + list << parent + list += parent.parents end + list end - children.each do |child| - child.clean_invalid_access_links + + def clean_invalid_access_links + stop_parents = parents + access_links.each do |link| + unless stop_parents.include? link.access_point.stop_area + link.delete + end + end + children.each do |child| + child.clean_invalid_access_links + end end - end - def duplicate - sa = self.deep_clone :except => [:object_version, :parent_id, :registration_number] - sa.uniq_objectid - sa.name = I18n.t("activerecord.copy", :name => self.name) - sa - end + def duplicate + sa = self.deep_clone :except => [:object_version, :parent_id, :registration_number] + sa.uniq_objectid + sa.name = I18n.t("activerecord.copy", :name => self.name) + sa + end - def journey_patterns_control_route_sections - if self.changed_attributes['latitude'] || self.changed_attributes['longitude'] - self.stop_points.each do |stop_point| - stop_point.route.journey_patterns.completed.map{ |jp| jp.control! } + def journey_patterns_control_route_sections + if self.changed_attributes['latitude'] || self.changed_attributes['longitude'] + self.stop_points.each do |stop_point| + stop_point.route.journey_patterns.completed.map{ |jp| jp.control! } + end end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb index 4f8b215b0..86be39d70 100644 --- a/app/models/chouette/stop_point.rb +++ b/app/models/chouette/stop_point.rb @@ -1,59 +1,60 @@ -class Chouette::StopPoint < Chouette::TridentActiveRecord +module Chouette + class StopPoint < Chouette::TridentActiveRecord - def self.policy_class - RoutePolicy - end + def self.policy_class + Chouette::RoutePolicy + end - include ForBoardingEnumerations - include ForAlightingEnumerations - include ObjectidSupport + include ForBoardingEnumerations + include ForAlightingEnumerations + include ObjectidSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - belongs_to :stop_area - belongs_to :route, inverse_of: :stop_points - has_many :vehicle_journey_at_stops, :dependent => :destroy - has_many :vehicle_journeys, -> {uniq}, :through => :vehicle_journey_at_stops + belongs_to :stop_area + belongs_to :route, inverse_of: :stop_points + has_many :vehicle_journey_at_stops, :dependent => :destroy + has_many :vehicle_journeys, -> {uniq}, :through => :vehicle_journey_at_stops - acts_as_list :scope => :route, top_of_list: 0 + acts_as_list :scope => :route, top_of_list: 0 - validates_presence_of :stop_area - validate :stop_area_id_validation - def stop_area_id_validation - if stop_area_id.nil? - errors.add(:stop_area_id, I18n.t("stop_areas.errors.empty")) + validates_presence_of :stop_area + validate :stop_area_id_validation + def stop_area_id_validation + if stop_area_id.nil? + errors.add(:stop_area_id, I18n.t("stop_areas.errors.empty")) + end end - end - scope :default_order, -> { order("position") } + scope :default_order, -> { order("position") } - delegate :name, to: :stop_area + delegate :name, to: :stop_area - before_destroy :remove_dependent_journey_pattern_stop_points - def remove_dependent_journey_pattern_stop_points - route.journey_patterns.each do |jp| - if jp.stop_point_ids.include?( id) - jp.stop_point_ids = jp.stop_point_ids - [id] + before_destroy :remove_dependent_journey_pattern_stop_points + def remove_dependent_journey_pattern_stop_points + route.journey_patterns.each do |jp| + if jp.stop_point_ids.include?( id) + jp.stop_point_ids = jp.stop_point_ids - [id] + end end end - end - def duplicate(for_route:) - keys_for_create = attributes.keys - %w{id objectid created_at updated_at} - atts_for_create = attributes - .slice(*keys_for_create) - .merge('route_id' => for_route.id) - self.class.create!(atts_for_create) - end + def duplicate(for_route:) + keys_for_create = attributes.keys - %w{id objectid created_at updated_at} + atts_for_create = attributes + .slice(*keys_for_create) + .merge('route_id' => for_route.id) + self.class.create!(atts_for_create) + end - def local_id - "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.route.id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.route.id}-#{self.id}" + end - def self.area_candidates - Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) + def self.area_candidates + Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) + end end - end
\ No newline at end of file diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index a17fb5799..172b73101 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -1,572 +1,574 @@ -class Chouette::TimeTable < Chouette::TridentActiveRecord - include ChecksumSupport - include TimeTableRestrictions - include ObjectidSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class TimeTable < Chouette::TridentActiveRecord + include ChecksumSupport + include TimeTableRestrictions + include ObjectidSupport + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - acts_as_taggable + acts_as_taggable - attr_accessor :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday - attr_accessor :tag_search + attr_accessor :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday + attr_accessor :tag_search - def self.ransackable_attributes auth_object = nil - (column_names + ['tag_search']) + _ransackers.keys - end + def self.ransackable_attributes auth_object = nil + (column_names + ['tag_search']) + _ransackers.keys + end - has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' + has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' - has_many :dates, -> {order(:date)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTableDate", :dependent => :destroy - has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy + has_many :dates, -> {order(:date)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTableDate", :dependent => :destroy + has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy - belongs_to :calendar - belongs_to :created_from, class_name: 'Chouette::TimeTable' + belongs_to :calendar + belongs_to :created_from, class_name: 'Chouette::TimeTable' - scope :overlapping, -> (period_range) do - joins(" - LEFT JOIN time_table_periods ON time_tables.id = time_table_periods.time_table_id - LEFT JOIN time_table_dates ON time_tables.id = time_table_dates.time_table_id - ") - .where("(time_table_periods.period_start <= :end AND time_table_periods.period_end >= :begin) OR (time_table_dates.date BETWEEN :begin AND :end)", {begin: period_range.begin, end: period_range.end}) - end + scope :overlapping, -> (period_range) do + joins(" + LEFT JOIN time_table_periods ON time_tables.id = time_table_periods.time_table_id + LEFT JOIN time_table_dates ON time_tables.id = time_table_dates.time_table_id + ") + .where("(time_table_periods.period_start <= :end AND time_table_periods.period_end >= :begin) OR (time_table_dates.date BETWEEN :begin AND :end)", {begin: period_range.begin, end: period_range.end}) + end - after_save :save_shortcuts + after_save :save_shortcuts - def local_id - "IBOO-#{self.referential.id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.id}" + end - def checksum_attributes - [].tap do |attrs| - attrs << self.int_day_types - attrs << self.dates.map(&:checksum).map(&:to_s).sort - attrs << self.periods.map(&:checksum).map(&:to_s).sort + def checksum_attributes + [].tap do |attrs| + attrs << self.int_day_types + attrs << self.dates.map(&:checksum).map(&:to_s).sort + attrs << self.periods.map(&:checksum).map(&:to_s).sort + end end - end - def self.object_id_key - "Timetable" - end + def self.object_id_key + "Timetable" + end - accepts_nested_attributes_for :dates, :allow_destroy => :true - accepts_nested_attributes_for :periods, :allow_destroy => :true - - validates_presence_of :comment - validates_presence_of :objectid_format - validates_associated :dates - validates_associated :periods - - def continuous_dates - in_days = self.dates.where(in_out: true).sort_by(&:date) - chunk = {} - group = nil - in_days.each_with_index do |date, index| - group ||= index - group = (date.date == in_days[index - 1].date + 1.day) ? group : group + 1 - chunk[group] ||= [] - chunk[group] << date - end - # Remove less than 2 continuous day chunk - chunk.values.delete_if {|dates| dates.count < 2} - end + accepts_nested_attributes_for :dates, :allow_destroy => :true + accepts_nested_attributes_for :periods, :allow_destroy => :true + + validates_presence_of :comment + validates_presence_of :objectid_format + validates_associated :dates + validates_associated :periods + + def continuous_dates + in_days = self.dates.where(in_out: true).sort_by(&:date) + chunk = {} + group = nil + in_days.each_with_index do |date, index| + group ||= index + group = (date.date == in_days[index - 1].date + 1.day) ? group : group + 1 + chunk[group] ||= [] + chunk[group] << date + end + # Remove less than 2 continuous day chunk + chunk.values.delete_if {|dates| dates.count < 2} + end - def convert_continuous_dates_to_periods - chunks = self.continuous_dates + def convert_continuous_dates_to_periods + chunks = self.continuous_dates - transaction do - chunks.each do |chunk| - self.periods.create!(period_start: chunk.first.date, period_end: chunk.last.date) - self.dates.delete(chunk) + transaction do + chunks.each do |chunk| + self.periods.create!(period_start: chunk.first.date, period_end: chunk.last.date) + self.dates.delete(chunk) + end end end - end - def state_update state - update_attributes(self.class.state_permited_attributes(state)) - self.tag_list = state['tags'].collect{|t| t['name']}.join(', ') - self.calendar_id = nil unless state['calendar'] + def state_update state + update_attributes(self.class.state_permited_attributes(state)) + self.tag_list = state['tags'].collect{|t| t['name']}.join(', ') + self.calendar_id = nil unless state['calendar'] - days = state['day_types'].split(',') - Date::DAYNAMES.map(&:underscore).each do |name| - prefix = human_attribute_name(name).first(2) - send("#{name}=", days.include?(prefix)) - end + days = state['day_types'].split(',') + Date::DAYNAMES.map(&:underscore).each do |name| + prefix = human_attribute_name(name).first(2) + send("#{name}=", days.include?(prefix)) + end - saved_dates = Hash[self.dates.collect{ |d| [d.id, d.date]}] - cmonth = Date.parse(state['current_periode_range']) + saved_dates = Hash[self.dates.collect{ |d| [d.id, d.date]}] + cmonth = Date.parse(state['current_periode_range']) - state['current_month'].each do |d| - date = Date.parse(d['date']) - checked = d['include_date'] || d['excluded_date'] - in_out = d['include_date'] ? true : false + state['current_month'].each do |d| + date = Date.parse(d['date']) + checked = d['include_date'] || d['excluded_date'] + in_out = d['include_date'] ? true : false - date_id = saved_dates.key(date) - time_table_date = self.dates.find(date_id) if date_id + date_id = saved_dates.key(date) + time_table_date = self.dates.find(date_id) if date_id - next if !checked && !time_table_date - # Destroy date if no longer checked - next if !checked && time_table_date.destroy + next if !checked && !time_table_date + # Destroy date if no longer checked + next if !checked && time_table_date.destroy - # Create new date - unless time_table_date - time_table_date = self.dates.create({in_out: in_out, date: date}) - end - # Update in_out - if in_out != time_table_date.in_out - time_table_date.update_attributes({in_out: in_out}) + # Create new date + unless time_table_date + time_table_date = self.dates.create({in_out: in_out, date: date}) + end + # Update in_out + if in_out != time_table_date.in_out + time_table_date.update_attributes({in_out: in_out}) + end end - end - self.state_update_periods state['time_table_periods'] - self.save - end + self.state_update_periods state['time_table_periods'] + self.save + end - def state_update_periods state_periods - state_periods.each do |item| - period = self.periods.find(item['id']) if item['id'] - next if period && item['deleted'] && period.destroy - period ||= self.periods.build + def state_update_periods state_periods + state_periods.each do |item| + period = self.periods.find(item['id']) if item['id'] + next if period && item['deleted'] && period.destroy + period ||= self.periods.build - period.period_start = Date.parse(item['period_start']) - period.period_end = Date.parse(item['period_end']) + period.period_start = Date.parse(item['period_start']) + period.period_end = Date.parse(item['period_end']) - if period.changed? - period.save - item['id'] = period.id + if period.changed? + period.save + item['id'] = period.id + end end + + state_periods.delete_if {|item| item['deleted']} end - state_periods.delete_if {|item| item['deleted']} - end + def self.state_permited_attributes item + item.slice('comment', 'color').to_hash + end - def self.state_permited_attributes item - item.slice('comment', 'color').to_hash - end + def presenter + @presenter ||= ::TimeTablePresenter.new( self) + end - def presenter - @presenter ||= ::TimeTablePresenter.new( self) - end + def self.start_validity_period + [Chouette::TimeTable.minimum(:start_date)].compact.min + end + def self.end_validity_period + [Chouette::TimeTable.maximum(:end_date)].compact.max + end - def self.start_validity_period - [Chouette::TimeTable.minimum(:start_date)].compact.min - end - def self.end_validity_period - [Chouette::TimeTable.maximum(:end_date)].compact.max - end + def add_exclude_date(in_out, date) + self.dates.create!({in_out: in_out, date: date}) + end - def add_exclude_date(in_out, date) - self.dates.create!({in_out: in_out, date: date}) - end + def actualize + self.dates.clear + self.periods.clear + from = self.calendar.convert_to_time_table + self.dates = from.dates + self.periods = from.periods + self.save + end - def actualize - self.dates.clear - self.periods.clear - from = self.calendar.convert_to_time_table - self.dates = from.dates - self.periods = from.periods - self.save - end + def month_inspect(date) + (date.beginning_of_month..date.end_of_month).map do |d| + { + day: I18n.l(d, format: '%A'), + date: d.to_s, + wday: d.wday, + wnumber: d.strftime("%W").to_s, + mday: d.mday, + include_date: include_in_dates?(d), + excluded_date: excluded_date?(d) + } + end + end - def month_inspect(date) - (date.beginning_of_month..date.end_of_month).map do |d| - { - day: I18n.l(d, format: '%A'), - date: d.to_s, - wday: d.wday, - wnumber: d.strftime("%W").to_s, - mday: d.mday, - include_date: include_in_dates?(d), - excluded_date: excluded_date?(d) - } + def save_shortcuts + shortcuts_update + self.update_column(:start_date, start_date) + self.update_column(:end_date, end_date) end - end - def save_shortcuts - shortcuts_update - self.update_column(:start_date, start_date) - self.update_column(:end_date, end_date) - end + def shortcuts_update(date=nil) + dates_array = bounding_dates + #if new_record? + if dates_array.empty? + self.start_date=nil + self.end_date=nil + else + self.start_date=dates_array.min + self.end_date=dates_array.max + end + #else + # if dates_array.empty? + # update_attributes :start_date => nil, :end_date => nil + # else + # update_attributes :start_date => dates_array.min, :end_date => dates_array.max + # end + #end + end - def shortcuts_update(date=nil) - dates_array = bounding_dates - #if new_record? - if dates_array.empty? - self.start_date=nil - self.end_date=nil + def validity_out_from_on?(expected_date) + return false unless self.end_date + self.end_date <= expected_date + end + + def validity_out_between?(starting_date, ending_date) + return false unless self.start_date + starting_date < self.end_date && + self.end_date <= ending_date + end + def self.validity_out_from_on?(expected_date,limit=0) + if limit==0 + Chouette::TimeTable.where("end_date <= ?", expected_date) else - self.start_date=dates_array.min - self.end_date=dates_array.max + Chouette::TimeTable.where("end_date <= ?", expected_date).limit( limit) end - #else - # if dates_array.empty? - # update_attributes :start_date => nil, :end_date => nil - # else - # update_attributes :start_date => dates_array.min, :end_date => dates_array.max - # end - #end - end - - def validity_out_from_on?(expected_date) - return false unless self.end_date - self.end_date <= expected_date - end - - def validity_out_between?(starting_date, ending_date) - return false unless self.start_date - starting_date < self.end_date && - self.end_date <= ending_date - end - def self.validity_out_from_on?(expected_date,limit=0) - if limit==0 - Chouette::TimeTable.where("end_date <= ?", expected_date) - else - Chouette::TimeTable.where("end_date <= ?", expected_date).limit( limit) end - end - def self.validity_out_between?(start_date, end_date,limit=0) - if limit==0 - Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date) - else - Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date).limit( limit) + def self.validity_out_between?(start_date, end_date,limit=0) + if limit==0 + Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date) + else + Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date).limit( limit) + end end - end - # Return days which intersects with the time table dates and periods - def intersects(days) - [].tap do |intersect_days| - days.each do |day| - intersect_days << day if include_day?(day) + # Return days which intersects with the time table dates and periods + def intersects(days) + [].tap do |intersect_days| + days.each do |day| + intersect_days << day if include_day?(day) + end end end - end - def include_day?(day) - include_in_dates?(day) || include_in_periods?(day) - end + def include_day?(day) + include_in_dates?(day) || include_in_periods?(day) + end - def include_in_dates?(day) - self.dates.any?{ |d| d.date === day && d.in_out == true } - end + def include_in_dates?(day) + self.dates.any?{ |d| d.date === day && d.in_out == true } + end - def excluded_date?(day) - self.dates.any?{ |d| d.date === day && d.in_out == false } - end + def excluded_date?(day) + self.dates.any?{ |d| d.date === day && d.in_out == false } + end - def include_in_periods?(day) - self.periods.any?{ |period| period.period_start <= day && - day <= period.period_end && - valid_days.include?(day.cwday) && - ! excluded_date?(day) } - end + def include_in_periods?(day) + self.periods.any?{ |period| period.period_start <= day && + day <= period.period_end && + valid_days.include?(day.cwday) && + ! excluded_date?(day) } + end - def include_in_overlap_dates?(day) - return false if self.excluded_date?(day) + def include_in_overlap_dates?(day) + return false if self.excluded_date?(day) - counter = self.dates.select{ |d| d.date === day}.size + self.periods.select{ |period| period.period_start <= day && day <= period.period_end && valid_days.include?(day.cwday) }.size - counter <= 1 ? false : true - end + counter = self.dates.select{ |d| d.date === day}.size + self.periods.select{ |period| period.period_start <= day && day <= period.period_end && valid_days.include?(day.cwday) }.size + counter <= 1 ? false : true + end - def periods_max_date - return nil if self.periods.empty? + def periods_max_date + return nil if self.periods.empty? - min_start = self.periods.map(&:period_start).compact.min - max_end = self.periods.map(&:period_end).compact.max - result = nil + min_start = self.periods.map(&:period_start).compact.min + max_end = self.periods.map(&:period_end).compact.max + result = nil - if max_end && min_start - max_end.downto( min_start) do |date| - if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) - result = date - break + if max_end && min_start + max_end.downto( min_start) do |date| + if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) + result = date + break + end end end + result end - result - end - def periods_min_date - return nil if self.periods.empty? - - min_start = self.periods.map(&:period_start).compact.min - max_end = self.periods.map(&:period_end).compact.max - result = nil - - if max_end && min_start - min_start.upto(max_end) do |date| - if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) - result = date - break + def periods_min_date + return nil if self.periods.empty? + + min_start = self.periods.map(&:period_start).compact.min + max_end = self.periods.map(&:period_end).compact.max + result = nil + + if max_end && min_start + min_start.upto(max_end) do |date| + if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) + result = date + break + end end end + result end - result - end - def bounding_dates - bounding_min = self.dates.select{|d| d.in_out}.map(&:date).compact.min - bounding_max = self.dates.select{|d| d.in_out}.map(&:date).compact.max + def bounding_dates + bounding_min = self.dates.select{|d| d.in_out}.map(&:date).compact.min + bounding_max = self.dates.select{|d| d.in_out}.map(&:date).compact.max - unless self.periods.empty? - bounding_min = periods_min_date if periods_min_date && - (bounding_min.nil? || (periods_min_date < bounding_min)) + unless self.periods.empty? + bounding_min = periods_min_date if periods_min_date && + (bounding_min.nil? || (periods_min_date < bounding_min)) - bounding_max = periods_max_date if periods_max_date && - (bounding_max.nil? || (bounding_max < periods_max_date)) - end + bounding_max = periods_max_date if periods_max_date && + (bounding_max.nil? || (bounding_max < periods_max_date)) + end - [bounding_min, bounding_max].compact - end + [bounding_min, bounding_max].compact + end - def display_day_types - %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| self.send(d) }.map{ |d| self.human_attribute_name(d).first(2)}.join(', ') - end + def display_day_types + %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| self.send(d) }.map{ |d| self.human_attribute_name(d).first(2)}.join(', ') + end - def day_by_mask(flag) - int_day_types & flag == flag - end + def day_by_mask(flag) + int_day_types & flag == flag + end - def self.day_by_mask(int_day_types,flag) - int_day_types & flag == flag - end + def self.day_by_mask(int_day_types,flag) + int_day_types & flag == flag + end - def valid_days - # Build an array with day of calendar week (1-7, Monday is 1). - [].tap do |valid_days| - valid_days << 1 if monday - valid_days << 2 if tuesday - valid_days << 3 if wednesday - valid_days << 4 if thursday - valid_days << 5 if friday - valid_days << 6 if saturday - valid_days << 7 if sunday + def valid_days + # Build an array with day of calendar week (1-7, Monday is 1). + [].tap do |valid_days| + valid_days << 1 if monday + valid_days << 2 if tuesday + valid_days << 3 if wednesday + valid_days << 4 if thursday + valid_days << 5 if friday + valid_days << 6 if saturday + valid_days << 7 if sunday + end end - end - def self.valid_days(int_day_types) - # Build an array with day of calendar week (1-7, Monday is 1). - [].tap do |valid_days| - valid_days << 1 if day_by_mask(int_day_types,4) - valid_days << 2 if day_by_mask(int_day_types,8) - valid_days << 3 if day_by_mask(int_day_types,16) - valid_days << 4 if day_by_mask(int_day_types,32) - valid_days << 5 if day_by_mask(int_day_types,64) - valid_days << 6 if day_by_mask(int_day_types,128) - valid_days << 7 if day_by_mask(int_day_types,256) + def self.valid_days(int_day_types) + # Build an array with day of calendar week (1-7, Monday is 1). + [].tap do |valid_days| + valid_days << 1 if day_by_mask(int_day_types,4) + valid_days << 2 if day_by_mask(int_day_types,8) + valid_days << 3 if day_by_mask(int_day_types,16) + valid_days << 4 if day_by_mask(int_day_types,32) + valid_days << 5 if day_by_mask(int_day_types,64) + valid_days << 6 if day_by_mask(int_day_types,128) + valid_days << 7 if day_by_mask(int_day_types,256) + end end - end - def monday - day_by_mask(4) - end - def tuesday - day_by_mask(8) - end - def wednesday - day_by_mask(16) - end - def thursday - day_by_mask(32) - end - def friday - day_by_mask(64) - end - def saturday - day_by_mask(128) - end - def sunday - day_by_mask(256) - end + def monday + day_by_mask(4) + end + def tuesday + day_by_mask(8) + end + def wednesday + day_by_mask(16) + end + def thursday + day_by_mask(32) + end + def friday + day_by_mask(64) + end + def saturday + day_by_mask(128) + end + def sunday + day_by_mask(256) + end - def set_day(day,flag) - if day == '1' || day == true - self.int_day_types |= flag - else - self.int_day_types &= ~flag + def set_day(day,flag) + if day == '1' || day == true + self.int_day_types |= flag + else + self.int_day_types &= ~flag + end + shortcuts_update end - shortcuts_update - end - def monday=(day) - set_day(day,4) - end - def tuesday=(day) - set_day(day,8) - end - def wednesday=(day) - set_day(day,16) - end - def thursday=(day) - set_day(day,32) - end - def friday=(day) - set_day(day,64) - end - def saturday=(day) - set_day(day,128) - end - def sunday=(day) - set_day(day,256) - end + def monday=(day) + set_day(day,4) + end + def tuesday=(day) + set_day(day,8) + end + def wednesday=(day) + set_day(day,16) + end + def thursday=(day) + set_day(day,32) + end + def friday=(day) + set_day(day,64) + end + def saturday=(day) + set_day(day,128) + end + def sunday=(day) + set_day(day,256) + end - def effective_days_of_period(period,valid_days=self.valid_days) - days = [] - period.period_start.upto(period.period_end) do |date| - if valid_days.include?(date.cwday) && !self.excluded_date?(date) - days << date + def effective_days_of_period(period,valid_days=self.valid_days) + days = [] + period.period_start.upto(period.period_end) do |date| + if valid_days.include?(date.cwday) && !self.excluded_date?(date) + days << date + end end - end - days - end + days + end - def effective_days(valid_days=self.valid_days) - days=self.effective_days_of_periods(valid_days) - self.dates.each do |d| - days |= [d.date] if d.in_out + def effective_days(valid_days=self.valid_days) + days=self.effective_days_of_periods(valid_days) + self.dates.each do |d| + days |= [d.date] if d.in_out + end + days.sort end - days.sort - end - def effective_days_of_periods(valid_days=self.valid_days) - days = [] - self.periods.each { |p| days |= self.effective_days_of_period(p,valid_days)} - days.sort - end + def effective_days_of_periods(valid_days=self.valid_days) + days = [] + self.periods.each { |p| days |= self.effective_days_of_period(p,valid_days)} + days.sort + end - def clone_periods - periods = [] - self.periods.each { |p| periods << p.copy} - periods.sort_by(&:period_start) - end + def clone_periods + periods = [] + self.periods.each { |p| periods << p.copy} + periods.sort_by(&:period_start) + end - def included_days - days = [] - self.dates.each do |d| - days |= [d.date] if d.in_out + def included_days + days = [] + self.dates.each do |d| + days |= [d.date] if d.in_out + end + days.sort end - days.sort - end - def excluded_days - days = [] - self.dates.each do |d| - days |= [d.date] unless d.in_out + def excluded_days + days = [] + self.dates.each do |d| + days |= [d.date] unless d.in_out + end + days.sort end - days.sort - end - # produce a copy of periods without anyone overlapping or including another - def optimize_overlapping_periods - periods = self.clone_periods - optimized = [] - i=0 - while i < periods.length - p1 = periods[i] - optimized << p1 - j= i+1 - while j < periods.length - p2 = periods[j] - if p1.contains? p2 - periods.delete p2 - elsif p1.overlap? p2 - p1.period_start = [p1.period_start,p2.period_start].min - p1.period_end = [p1.period_end,p2.period_end].max - periods.delete p2 - else - j += 1 + # produce a copy of periods without anyone overlapping or including another + def optimize_overlapping_periods + periods = self.clone_periods + optimized = [] + i=0 + while i < periods.length + p1 = periods[i] + optimized << p1 + j= i+1 + while j < periods.length + p2 = periods[j] + if p1.contains? p2 + periods.delete p2 + elsif p1.overlap? p2 + p1.period_start = [p1.period_start,p2.period_start].min + p1.period_end = [p1.period_end,p2.period_end].max + periods.delete p2 + else + j += 1 + end end + i+= 1 end - i+= 1 + optimized.sort { |a,b| a.period_start <=> b.period_start} end - optimized.sort { |a,b| a.period_start <=> b.period_start} - end - # add a peculiar day or switch it from excluded to included - def add_included_day(d) - if self.excluded_date?(d) - self.dates.each do |date| - if date.date === d - date.in_out = true - end - end - elsif !self.include_in_dates?(d) - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + # add a peculiar day or switch it from excluded to included + def add_included_day(d) + if self.excluded_date?(d) + self.dates.each do |date| + if date.date === d + date.in_out = true + end + end + elsif !self.include_in_dates?(d) + self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + end end - end - # merge effective days from another timetable - def merge!(another_tt) - transaction do - days = [].tap do |array| - array.push(*self.effective_days, *another_tt.effective_days) - array.uniq! - end + # merge effective days from another timetable + def merge!(another_tt) + transaction do + days = [].tap do |array| + array.push(*self.effective_days, *another_tt.effective_days) + array.uniq! + end - self.dates.clear - self.periods.clear + self.dates.clear + self.periods.clear - days.each do |day| - self.dates << Chouette::TimeTableDate.new(date: day, in_out: true) + days.each do |day| + self.dates << Chouette::TimeTableDate.new(date: day, in_out: true) + end + self.save! end - self.save! + self.convert_continuous_dates_to_periods end - self.convert_continuous_dates_to_periods - end - def included_days_in_dates_and_periods - in_day = self.dates.select {|d| d.in_out }.map(&:date) - out_day = self.dates.select {|d| !d.in_out }.map(&:date) + def included_days_in_dates_and_periods + in_day = self.dates.select {|d| d.in_out }.map(&:date) + out_day = self.dates.select {|d| !d.in_out }.map(&:date) - in_periods = self.periods.map{|p| (p.period_start..p.period_end).to_a }.flatten - days = in_periods + in_day - days -= out_day - days - end + in_periods = self.periods.map{|p| (p.period_start..p.period_end).to_a }.flatten + days = in_periods + in_day + days -= out_day + days + end - # keep common dates with another_tt - def intersect!(another_tt) - transaction do - days = [].tap do |array| - array.push(*self.effective_days) - array.delete_if {|day| !another_tt.effective_days.include?(day) } - array.uniq! - end + # keep common dates with another_tt + def intersect!(another_tt) + transaction do + days = [].tap do |array| + array.push(*self.effective_days) + array.delete_if {|day| !another_tt.effective_days.include?(day) } + array.uniq! + end - self.dates.clear - self.periods.clear + self.dates.clear + self.periods.clear - days.sort.each do |d| - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + days.sort.each do |d| + self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + end + self.save! end - self.save! + self.convert_continuous_dates_to_periods end - self.convert_continuous_dates_to_periods - end - # remove common dates with another_tt - def disjoin!(another_tt) - transaction do - days = [].tap do |array| - array.push(*self.effective_days) - array.delete_if {|day| another_tt.effective_days.include?(day) } - array.uniq! - end + # remove common dates with another_tt + def disjoin!(another_tt) + transaction do + days = [].tap do |array| + array.push(*self.effective_days) + array.delete_if {|day| another_tt.effective_days.include?(day) } + array.uniq! + end - self.dates.clear - self.periods.clear + self.dates.clear + self.periods.clear - days.sort.each do |d| - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + days.sort.each do |d| + self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + end + self.save! end - self.save! + self.convert_continuous_dates_to_periods end - self.convert_continuous_dates_to_periods - end - def duplicate - tt = self.deep_clone :include => [:periods, :dates], :except => [:object_version, :objectid] - tt.tag_list.add(*self.tag_list) unless self.tag_list.empty? - tt.created_from = self - tt.comment = I18n.t("activerecord.copy", :name => self.comment) - tt + def duplicate + tt = self.deep_clone :include => [:periods, :dates], :except => [:object_version, :objectid] + tt.tag_list.add(*self.tag_list) unless self.tag_list.empty? + tt.created_from = self + tt.comment = I18n.t("activerecord.copy", :name => self.comment) + tt + end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/time_table_date.rb b/app/models/chouette/time_table_date.rb index 1893eae91..b3b2fd561 100644 --- a/app/models/chouette/time_table_date.rb +++ b/app/models/chouette/time_table_date.rb @@ -1,22 +1,23 @@ -class Chouette::TimeTableDate < Chouette::ActiveRecord - include ChecksumSupport +module Chouette + class TimeTableDate < Chouette::ActiveRecord + include ChecksumSupport - self.primary_key = "id" - belongs_to :time_table, inverse_of: :dates - acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 + self.primary_key = "id" + belongs_to :time_table, inverse_of: :dates + acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 - validates_presence_of :date - validates_uniqueness_of :date, :scope => :time_table_id + validates_presence_of :date + validates_uniqueness_of :date, :scope => :time_table_id - scope :in_dates, -> { where(in_out: true) } + scope :in_dates, -> { where(in_out: true) } - def self.model_name - ActiveModel::Name.new Chouette::TimeTableDate, Chouette, "TimeTableDate" - end + def self.model_name + ActiveModel::Name.new Chouette::TimeTableDate, Chouette, "TimeTableDate" + end - def checksum_attributes - attrs = ['date', 'in_out'] - self.slice(*attrs).values + def checksum_attributes + attrs = ['date', 'in_out'] + self.slice(*attrs).values + end end -end - +end
\ No newline at end of file diff --git a/app/models/chouette/time_table_period.rb b/app/models/chouette/time_table_period.rb index ed136f3b9..ab3e79d7e 100644 --- a/app/models/chouette/time_table_period.rb +++ b/app/models/chouette/time_table_period.rb @@ -1,45 +1,46 @@ -class Chouette::TimeTablePeriod < Chouette::ActiveRecord - include ChecksumSupport +module Chouette + class TimeTablePeriod < Chouette::ActiveRecord + include ChecksumSupport - self.primary_key = "id" - belongs_to :time_table, inverse_of: :periods - acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 + self.primary_key = "id" + belongs_to :time_table, inverse_of: :periods + acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 - validates_presence_of :period_start, :period_end + validates_presence_of :period_start, :period_end - validate :start_must_be_before_end + validate :start_must_be_before_end - def checksum_attributes - attrs = ['period_start', 'period_end'] - self.slice(*attrs).values - end - - def self.model_name - ActiveModel::Name.new Chouette::TimeTablePeriod, Chouette, "TimeTablePeriod" - end + def checksum_attributes + attrs = ['period_start', 'period_end'] + self.slice(*attrs).values + end - def start_must_be_before_end - # security against nil values - if period_end.nil? || period_start.nil? - return + def self.model_name + ActiveModel::Name.new Chouette::TimeTablePeriod, Chouette, "TimeTablePeriod" end - if period_end <= period_start - errors.add(:period_end,I18n.t("activerecord.errors.models.time_table_period.start_must_be_before_end")) + + def start_must_be_before_end + # security against nil values + if period_end.nil? || period_start.nil? + return + end + if period_end <= period_start + errors.add(:period_end,I18n.t("activerecord.errors.models.time_table_period.start_must_be_before_end")) + end end - end - def copy - Chouette::TimeTablePeriod.new(:period_start => self.period_start,:period_end => self.period_end) - end + def copy + Chouette::TimeTablePeriod.new(:period_start => self.period_start,:period_end => self.period_end) + end - # Test to see if a period overlap this period - def overlap?(p) - (p.period_start >= self.period_start && p.period_start <= self.period_end) || (p.period_end >= self.period_start && p.period_end <= self.period_end) - end + # Test to see if a period overlap this period + def overlap?(p) + (p.period_start >= self.period_start && p.period_start <= self.period_end) || (p.period_end >= self.period_start && p.period_end <= self.period_end) + end - # Test to see if a period is included in this period - def contains?(p) - (p.period_start >= self.period_start && p.period_end <= self.period_end) + # Test to see if a period is included in this period + def contains?(p) + (p.period_start >= self.period_start && p.period_end <= self.period_end) + end end - -end +end
\ No newline at end of file diff --git a/app/models/chouette/timeband.rb b/app/models/chouette/timeband.rb index 3de394ced..da8bc3dea 100644 --- a/app/models/chouette/timeband.rb +++ b/app/models/chouette/timeband.rb @@ -1,26 +1,27 @@ -class Chouette::TimebandValidator < ActiveModel::Validator - def validate(record) - if record.end_time <= record.start_time - record.errors[:end_time] << I18n.t('activerecord.errors.models.timeband.start_must_be_before_end') +module Chouette + class TimebandValidator < ActiveModel::Validator + def validate(record) + if record.end_time <= record.start_time + record.errors[:end_time] << I18n.t('activerecord.errors.models.timeband.start_must_be_before_end') + end end end -end -class Chouette::Timeband < Chouette::TridentActiveRecord - self.primary_key = "id" + class Timeband < Chouette::TridentActiveRecord + self.primary_key = "id" - validates :start_time, :end_time, presence: true - validates_with Chouette::TimebandValidator + validates :start_time, :end_time, presence: true + validates_with Chouette::TimebandValidator - default_scope { order(:start_time) } + default_scope { order(:start_time) } - def self.object_id_key - "Timeband" - end + def self.object_id_key + "Timeband" + end - def fullname - fullname = "#{I18n.l(self.start_time, format: :hour)}-#{I18n.l(self.end_time, format: :hour)}" - "#{self.name} (#{fullname})" if self.name + def fullname + fullname = "#{I18n.l(self.start_time, format: :hour)}-#{I18n.l(self.end_time, format: :hour)}" + "#{self.name} (#{fullname})" if self.name + end end - end
\ No newline at end of file diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb index f2d654efc..18b7bbf9b 100644 --- a/app/models/chouette/trident_active_record.rb +++ b/app/models/chouette/trident_active_record.rb @@ -1,17 +1,19 @@ -class Chouette::TridentActiveRecord < Chouette::ActiveRecord +module Chouette + class TridentActiveRecord < Chouette::ActiveRecord - self.abstract_class = true + self.abstract_class = true - def referential - @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! - end + def referential + @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! + end - def hub_restricted? - referential.data_format == "hub" - end + def hub_restricted? + referential.data_format == "hub" + end - def prefix - referential.prefix - end + def prefix + referential.prefix + end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index ec4d82de7..b68909795 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -1,306 +1,307 @@ -class Chouette::VehicleJourney < Chouette::TridentActiveRecord - include ChecksumSupport - include VehicleJourneyRestrictions - include ObjectidSupport - extend StifTransportModeEnumerations - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class VehicleJourney < Chouette::TridentActiveRecord + include ChecksumSupport + include VehicleJourneyRestrictions + include ObjectidSupport + extend StifTransportModeEnumerations + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - enum journey_category: { timed: 0, frequency: 1 } + enum journey_category: { timed: 0, frequency: 1 } - default_scope { where(journey_category: journey_categories[:timed]) } + default_scope { where(journey_category: journey_categories[:timed]) } - attr_reader :time_table_tokens + attr_reader :time_table_tokens - def self.nullable_attributes - [:transport_mode, :published_journey_name, :vehicle_type_identifier, :published_journey_identifier, :comment, :status_value] - end + def self.nullable_attributes + [:transport_mode, :published_journey_name, :vehicle_type_identifier, :published_journey_identifier, :comment, :status_value] + end - belongs_to :company - belongs_to :route - belongs_to :journey_pattern + belongs_to :company + belongs_to :route + belongs_to :journey_pattern - has_and_belongs_to_many :footnotes, :class_name => 'Chouette::Footnote' + has_and_belongs_to_many :footnotes, :class_name => 'Chouette::Footnote' - validates_presence_of :route - validates_presence_of :journey_pattern - # validates :vehicle_journey_at_stops, - # Validation temporarily removed for day offsets - # :vjas_departure_time_must_be_before_next_stop_arrival_time, + validates_presence_of :route + validates_presence_of :journey_pattern + # validates :vehicle_journey_at_stops, + # Validation temporarily removed for day offsets + # :vjas_departure_time_must_be_before_next_stop_arrival_time, - # vehicle_journey_at_stops_are_in_increasing_time_order: false - validates_presence_of :number + # vehicle_journey_at_stops_are_in_increasing_time_order: false + validates_presence_of :number - has_many :vehicle_journey_at_stops, -> { includes(:stop_point).order("stop_points.position") }, :dependent => :destroy - has_and_belongs_to_many :time_tables, :class_name => 'Chouette::TimeTable', :foreign_key => "vehicle_journey_id", :association_foreign_key => "time_table_id" - has_many :stop_points, -> { order("stop_points.position") }, :through => :vehicle_journey_at_stops + has_many :vehicle_journey_at_stops, -> { includes(:stop_point).order("stop_points.position") }, :dependent => :destroy + has_and_belongs_to_many :time_tables, :class_name => 'Chouette::TimeTable', :foreign_key => "vehicle_journey_id", :association_foreign_key => "time_table_id" + has_many :stop_points, -> { order("stop_points.position") }, :through => :vehicle_journey_at_stops - before_validation :set_default_values, - :calculate_vehicle_journey_at_stop_day_offset + before_validation :set_default_values, + :calculate_vehicle_journey_at_stop_day_offset - # TODO: Remove this validator - # We've eliminated this validation because it prevented vehicle journeys - # from being saved with at-stops having a day offset greater than 0, - # because these would have times that were "earlier" than the previous - # at-stop. TBD by Luc whether we're deleting this validation altogether or - # instead rejiggering it to work with day offsets. - def vjas_departure_time_must_be_before_next_stop_arrival_time - notice = 'departure time must be before next stop arrival time' - vehicle_journey_at_stops.each_with_index do |current_stop, index| - next_stop = vehicle_journey_at_stops[index + 1] + # TODO: Remove this validator + # We've eliminated this validation because it prevented vehicle journeys + # from being saved with at-stops having a day offset greater than 0, + # because these would have times that were "earlier" than the previous + # at-stop. TBD by Luc whether we're deleting this validation altogether or + # instead rejiggering it to work with day offsets. + def vjas_departure_time_must_be_before_next_stop_arrival_time + notice = 'departure time must be before next stop arrival time' + vehicle_journey_at_stops.each_with_index do |current_stop, index| + next_stop = vehicle_journey_at_stops[index + 1] - next unless next_stop && (next_stop[:arrival_time] < current_stop[:departure_time]) + next unless next_stop && (next_stop[:arrival_time] < current_stop[:departure_time]) - current_stop.errors.add(:departure_time, notice) - self.errors.add(:vehicle_journey_at_stops, notice) + current_stop.errors.add(:departure_time, notice) + self.errors.add(:vehicle_journey_at_stops, notice) + end end - end - def local_id - "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.id}" + end - def checksum_attributes - [].tap do |attrs| - attrs << self.published_journey_name - attrs << self.published_journey_identifier - attrs << self.try(:company).try(:objectid).try(:local_id) - attrs << self.footnotes.map(&:checksum).sort - attrs << self.vehicle_journey_at_stops.map(&:checksum).sort + def checksum_attributes + [].tap do |attrs| + attrs << self.published_journey_name + attrs << self.published_journey_identifier + attrs << self.try(:company).try(:objectid).try(:local_id) + attrs << self.footnotes.map(&:checksum).sort + attrs << self.vehicle_journey_at_stops.map(&:checksum).sort + end end - end - def set_default_values - if number.nil? - self.number = 0 + def set_default_values + if number.nil? + self.number = 0 + end end - end - def calculate_vehicle_journey_at_stop_day_offset - Chouette::VehicleJourneyAtStopsDayOffset.new( - vehicle_journey_at_stops - ).update - end + def calculate_vehicle_journey_at_stop_day_offset + Chouette::VehicleJourneyAtStopsDayOffset.new( + vehicle_journey_at_stops + ).update + end - scope :without_any_time_table, -> { joins('LEFT JOIN "time_tables_vehicle_journeys" ON "time_tables_vehicle_journeys"."vehicle_journey_id" = "vehicle_journeys"."id" LEFT JOIN "time_tables" ON "time_tables"."id" = "time_tables_vehicle_journeys"."time_table_id"').where(:time_tables => { :id => nil}) } - scope :without_any_passing_time, -> { joins('LEFT JOIN "vehicle_journey_at_stops" ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id"').where(vehicle_journey_at_stops: { id: nil }) } + scope :without_any_time_table, -> { joins('LEFT JOIN "time_tables_vehicle_journeys" ON "time_tables_vehicle_journeys"."vehicle_journey_id" = "vehicle_journeys"."id" LEFT JOIN "time_tables" ON "time_tables"."id" = "time_tables_vehicle_journeys"."time_table_id"').where(:time_tables => { :id => nil}) } + scope :without_any_passing_time, -> { joins('LEFT JOIN "vehicle_journey_at_stops" ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id"').where(vehicle_journey_at_stops: { id: nil }) } - accepts_nested_attributes_for :vehicle_journey_at_stops, :allow_destroy => true + accepts_nested_attributes_for :vehicle_journey_at_stops, :allow_destroy => true - def presenter - @presenter ||= ::VehicleJourneyPresenter.new( self) - end + def presenter + @presenter ||= ::VehicleJourneyPresenter.new( self) + end - def vehicle_journey_at_stops_matrix - at_stops = self.vehicle_journey_at_stops.to_a.dup - active_stop_point_ids = journey_pattern.stop_points.map(&:id) + def vehicle_journey_at_stops_matrix + at_stops = self.vehicle_journey_at_stops.to_a.dup + active_stop_point_ids = journey_pattern.stop_points.map(&:id) - (route.stop_points.map(&:id) - at_stops.map(&:stop_point_id)).each do |id| - vjas = Chouette::VehicleJourneyAtStop.new(stop_point_id: id) - vjas.dummy = !active_stop_point_ids.include?(id) - at_stops.insert(route.stop_points.map(&:id).index(id), vjas) + (route.stop_points.map(&:id) - at_stops.map(&:stop_point_id)).each do |id| + vjas = Chouette::VehicleJourneyAtStop.new(stop_point_id: id) + vjas.dummy = !active_stop_point_ids.include?(id) + at_stops.insert(route.stop_points.map(&:id).index(id), vjas) + end + at_stops end - at_stops - end - def create_or_find_vjas_from_state vjas - return vehicle_journey_at_stops.find(vjas['id']) if vjas['id'] - stop_point = Chouette::StopPoint.find_by(objectid: vjas['stop_point_objectid']) - stop = vehicle_journey_at_stops.create(stop_point: stop_point) - vjas['id'] = stop.id - vjas['new_record'] = true - stop - end + def create_or_find_vjas_from_state vjas + return vehicle_journey_at_stops.find(vjas['id']) if vjas['id'] + stop_point = Chouette::StopPoint.find_by(objectid: vjas['stop_point_objectid']) + stop = vehicle_journey_at_stops.create(stop_point: stop_point) + vjas['id'] = stop.id + vjas['new_record'] = true + stop + end - def update_vjas_from_state state - state.each do |vjas| - next if vjas["dummy"] - params = {}.tap do |el| - ['arrival_time', 'departure_time'].each do |field| - time = "#{vjas[field]['hour']}:#{vjas[field]['minute']}" - el[field.to_sym] = Time.parse("2000-01-01 #{time}:00 UTC") + def update_vjas_from_state state + state.each do |vjas| + next if vjas["dummy"] + params = {}.tap do |el| + ['arrival_time', 'departure_time'].each do |field| + time = "#{vjas[field]['hour']}:#{vjas[field]['minute']}" + el[field.to_sym] = Time.parse("2000-01-01 #{time}:00 UTC") + end end + stop = create_or_find_vjas_from_state(vjas) + stop.update_attributes(params) + vjas.delete('errors') + vjas['errors'] = stop.errors if stop.errors.any? end - stop = create_or_find_vjas_from_state(vjas) - stop.update_attributes(params) - vjas.delete('errors') - vjas['errors'] = stop.errors if stop.errors.any? end - end - def state_update_vjas? vehicle_journey_at_stops - departure_times = vehicle_journey_at_stops.map do |vjas| - "#{vjas['departure_time']['hour']}:#{vjas['departure_time']['minute']}" + def state_update_vjas? vehicle_journey_at_stops + departure_times = vehicle_journey_at_stops.map do |vjas| + "#{vjas['departure_time']['hour']}:#{vjas['departure_time']['minute']}" + end + times = departure_times.uniq + (times.count == 1 && times[0] == '00:00') ? false : true end - times = departure_times.uniq - (times.count == 1 && times[0] == '00:00') ? false : true - end - def update_has_and_belongs_to_many_from_state item - ['time_tables', 'footnotes'].each do |assos| - saved = self.send(assos).map(&:id) + def update_has_and_belongs_to_many_from_state item + ['time_tables', 'footnotes'].each do |assos| + saved = self.send(assos).map(&:id) - (saved - item[assos].map{|t| t['id']}).each do |id| - self.send(assos).delete(self.send(assos).find(id)) - end + (saved - item[assos].map{|t| t['id']}).each do |id| + self.send(assos).delete(self.send(assos).find(id)) + end - item[assos].each do |t| - klass = "Chouette::#{assos.classify}".constantize - unless saved.include?(t['id']) - self.send(assos) << klass.find(t['id']) + item[assos].each do |t| + klass = "Chouette::#{assos.classify}".constantize + unless saved.include?(t['id']) + self.send(assos) << klass.find(t['id']) + end end end end - end - def self.state_update route, state - transaction do - state.each do |item| - item.delete('errors') - vj = find_by(objectid: item['objectid']) || state_create_instance(route, item) - next if item['deletable'] && vj.persisted? && vj.destroy + def self.state_update route, state + transaction do + state.each do |item| + item.delete('errors') + vj = find_by(objectid: item['objectid']) || state_create_instance(route, item) + next if item['deletable'] && vj.persisted? && vj.destroy - if vj.state_update_vjas?(item['vehicle_journey_at_stops']) - vj.update_vjas_from_state(item['vehicle_journey_at_stops']) + if vj.state_update_vjas?(item['vehicle_journey_at_stops']) + vj.update_vjas_from_state(item['vehicle_journey_at_stops']) + end + + vj.update_attributes(state_permited_attributes(item)) + vj.update_has_and_belongs_to_many_from_state(item) + item['errors'] = vj.errors.full_messages.uniq if vj.errors.any? end - vj.update_attributes(state_permited_attributes(item)) - vj.update_has_and_belongs_to_many_from_state(item) - item['errors'] = vj.errors.full_messages.uniq if vj.errors.any? + # Delete ids of new object from state if we had to rollback + if state.any? {|item| item['errors']} + state.map do |item| + item.delete('objectid') if item['new_record'] + item['vehicle_journey_at_stops'].map {|vjas| vjas.delete('id') if vjas['new_record'] } + end + raise ::ActiveRecord::Rollback + end end - # Delete ids of new object from state if we had to rollback - if state.any? {|item| item['errors']} - state.map do |item| - item.delete('objectid') if item['new_record'] - item['vehicle_journey_at_stops'].map {|vjas| vjas.delete('id') if vjas['new_record'] } - end - raise ::ActiveRecord::Rollback + # Remove new_record flag && deleted item from state if transaction has been saved + state.map do |item| + item.delete('new_record') + item['vehicle_journey_at_stops'].map {|vjas| vjas.delete('new_record') } end + state.delete_if {|item| item['deletable']} end - # Remove new_record flag && deleted item from state if transaction has been saved - state.map do |item| - item.delete('new_record') - item['vehicle_journey_at_stops'].map {|vjas| vjas.delete('new_record') } + def self.state_create_instance route, item + # Flag new record, so we can unset object_id if transaction rollback + vj = route.vehicle_journeys.create(state_permited_attributes(item)) + item['objectid'] = vj.objectid + item['new_record'] = true + vj end - state.delete_if {|item| item['deletable']} - end - def self.state_create_instance route, item - # Flag new record, so we can unset object_id if transaction rollback - vj = route.vehicle_journeys.create(state_permited_attributes(item)) - item['objectid'] = vj.objectid - item['new_record'] = true - vj - end + def self.state_permited_attributes item + attrs = item.slice('published_journey_identifier', 'published_journey_name', 'journey_pattern_id', 'company_id').to_hash + ['company', 'journey_pattern'].map do |association| + attrs["#{association}_id"] = item[association]['id'] if item[association] + end + attrs + end - def self.state_permited_attributes item - attrs = item.slice('published_journey_identifier', 'published_journey_name', 'journey_pattern_id', 'company_id').to_hash - ['company', 'journey_pattern'].map do |association| - attrs["#{association}_id"] = item[association]['id'] if item[association] + def missing_stops_in_relation_to_a_journey_pattern(selected_journey_pattern) + selected_journey_pattern.stop_points - self.stop_points end - attrs - end + def extra_stops_in_relation_to_a_journey_pattern(selected_journey_pattern) + self.stop_points - selected_journey_pattern.stop_points + end + def extra_vjas_in_relation_to_a_journey_pattern(selected_journey_pattern) + extra_stops = self.extra_stops_in_relation_to_a_journey_pattern(selected_journey_pattern) + self.vehicle_journey_at_stops.select { |vjas| extra_stops.include?( vjas.stop_point)} + end + def time_table_tokens=(ids) + self.time_table_ids = ids.split(",") + end + def bounding_dates + dates = [] - def missing_stops_in_relation_to_a_journey_pattern(selected_journey_pattern) - selected_journey_pattern.stop_points - self.stop_points - end - def extra_stops_in_relation_to_a_journey_pattern(selected_journey_pattern) - self.stop_points - selected_journey_pattern.stop_points - end - def extra_vjas_in_relation_to_a_journey_pattern(selected_journey_pattern) - extra_stops = self.extra_stops_in_relation_to_a_journey_pattern(selected_journey_pattern) - self.vehicle_journey_at_stops.select { |vjas| extra_stops.include?( vjas.stop_point)} - end - def time_table_tokens=(ids) - self.time_table_ids = ids.split(",") - end - def bounding_dates - dates = [] + time_tables.each do |tm| + dates << tm.start_date if tm.start_date + dates << tm.end_date if tm.end_date + end - time_tables.each do |tm| - dates << tm.start_date if tm.start_date - dates << tm.end_date if tm.end_date + dates.empty? ? [] : [dates.min, dates.max] end - dates.empty? ? [] : [dates.min, dates.max] - end + def update_journey_pattern( selected_journey_pattern) + return unless selected_journey_pattern.route_id==self.route_id - def update_journey_pattern( selected_journey_pattern) - return unless selected_journey_pattern.route_id==self.route_id - - missing_stops_in_relation_to_a_journey_pattern(selected_journey_pattern).each do |sp| - self.vehicle_journey_at_stops.build( :stop_point => sp) - end - extra_vjas_in_relation_to_a_journey_pattern(selected_journey_pattern).each do |vjas| - vjas._destroy = true + missing_stops_in_relation_to_a_journey_pattern(selected_journey_pattern).each do |sp| + self.vehicle_journey_at_stops.build( :stop_point => sp) + end + extra_vjas_in_relation_to_a_journey_pattern(selected_journey_pattern).each do |vjas| + vjas._destroy = true + end end - end - def self.matrix(vehicle_journeys) - {}.tap do |hash| - vehicle_journeys.map{ |vj| - vj.vehicle_journey_at_stops.map{ |vjas |hash[ "#{vj.id}-#{vjas.stop_point_id}"] = vjas } - } + def self.matrix(vehicle_journeys) + {}.tap do |hash| + vehicle_journeys.map{ |vj| + vj.vehicle_journey_at_stops.map{ |vjas |hash[ "#{vj.id}-#{vjas.stop_point_id}"] = vjas } + } + end end - end - def self.with_stops - self - .joins(:journey_pattern) - .joins(' - LEFT JOIN "vehicle_journey_at_stops" - ON "vehicle_journey_at_stops"."vehicle_journey_id" = - "vehicle_journeys"."id" - AND "vehicle_journey_at_stops"."stop_point_id" = - "journey_patterns"."departure_stop_point_id" - ') - .order('"vehicle_journey_at_stops"."departure_time"') - end + def self.with_stops + self + .joins(:journey_pattern) + .joins(' + LEFT JOIN "vehicle_journey_at_stops" + ON "vehicle_journey_at_stops"."vehicle_journey_id" = + "vehicle_journeys"."id" + AND "vehicle_journey_at_stops"."stop_point_id" = + "journey_patterns"."departure_stop_point_id" + ') + .order('"vehicle_journey_at_stops"."departure_time"') + end - # Requires a SELECT DISTINCT and a join with - # "vehicle_journey_at_stops". - # - # Example: - # .select('DISTINCT "vehicle_journeys".*') - # .joins(' - # LEFT JOIN "vehicle_journey_at_stops" - # ON "vehicle_journey_at_stops"."vehicle_journey_id" = - # "vehicle_journeys"."id" - # ') - # .where_departure_time_between('08:00', '09:45') - def self.where_departure_time_between( - start_time, - end_time, - allow_empty: false - ) - self - .where( - %Q( - "vehicle_journey_at_stops"."departure_time" >= ? - AND "vehicle_journey_at_stops"."departure_time" <= ? - #{ - if allow_empty - 'OR "vehicle_journey_at_stops"."id" IS NULL' - end - } - ), - "2000-01-01 #{start_time}:00 UTC", - "2000-01-01 #{end_time}:00 UTC" - ) - end + # Requires a SELECT DISTINCT and a join with + # "vehicle_journey_at_stops". + # + # Example: + # .select('DISTINCT "vehicle_journeys".*') + # .joins(' + # LEFT JOIN "vehicle_journey_at_stops" + # ON "vehicle_journey_at_stops"."vehicle_journey_id" = + # "vehicle_journeys"."id" + # ') + # .where_departure_time_between('08:00', '09:45') + def self.where_departure_time_between( + start_time, + end_time, + allow_empty: false + ) + self + .where( + %Q( + "vehicle_journey_at_stops"."departure_time" >= ? + AND "vehicle_journey_at_stops"."departure_time" <= ? + #{ + if allow_empty + 'OR "vehicle_journey_at_stops"."id" IS NULL' + end + } + ), + "2000-01-01 #{start_time}:00 UTC", + "2000-01-01 #{end_time}:00 UTC" + ) + end - def self.without_time_tables - # Joins the VehicleJourney–TimeTable through table to select only those - # VehicleJourneys that don't have an associated TimeTable. - self - .joins(' - LEFT JOIN "time_tables_vehicle_journeys" - ON "time_tables_vehicle_journeys"."vehicle_journey_id" = - "vehicle_journeys"."id" - ') - .where('"time_tables_vehicle_journeys"."vehicle_journey_id" IS NULL') + def self.without_time_tables + # Joins the VehicleJourney–TimeTable through table to select only those + # VehicleJourneys that don't have an associated TimeTable. + self + .joins(' + LEFT JOIN "time_tables_vehicle_journeys" + ON "time_tables_vehicle_journeys"."vehicle_journey_id" = + "vehicle_journeys"."id" + ') + .where('"time_tables_vehicle_journeys"."vehicle_journey_id" IS NULL') + end end - end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb index 470725041..6f0119e74 100644 --- a/app/models/chouette/vehicle_journey_at_stop.rb +++ b/app/models/chouette/vehicle_journey_at_stop.rb @@ -1,77 +1,79 @@ -class Chouette::VehicleJourneyAtStop < ActiveRecord::Base - include Chouette::ForBoardingEnumerations - include Chouette::ForAlightingEnumerations - include ChecksumSupport +module Chouette + class VehicleJourneyAtStop < ActiveRecord + include Chouette::ForBoardingEnumerations + include Chouette::ForAlightingEnumerations + include ChecksumSupport - DAY_OFFSET_MAX = 1 + DAY_OFFSET_MAX = 1 - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - belongs_to :stop_point - belongs_to :vehicle_journey + belongs_to :stop_point + belongs_to :vehicle_journey - attr_accessor :_destroy, :dummy + attr_accessor :_destroy, :dummy - validate :arrival_must_be_before_departure - def arrival_must_be_before_departure - # security against nil values - return unless arrival_time && departure_time + validate :arrival_must_be_before_departure + def arrival_must_be_before_departure + # security against nil values + return unless arrival_time && departure_time - if TimeDuration.exceeds_gap?(4.hours, arrival_time, departure_time) - errors.add( - :arrival_time, - I18n.t("activerecord.errors.models.vehicle_journey_at_stop.arrival_must_be_before_departure") - ) + if TimeDuration.exceeds_gap?(4.hours, arrival_time, departure_time) + errors.add( + :arrival_time, + I18n.t("activerecord.errors.models.vehicle_journey_at_stop.arrival_must_be_before_departure") + ) + end end - end - validate :day_offset_must_be_within_range + validate :day_offset_must_be_within_range - after_initialize :set_virtual_attributes - def set_virtual_attributes - @_destroy = false - @dummy = false - end + after_initialize :set_virtual_attributes + def set_virtual_attributes + @_destroy = false + @dummy = false + end - def day_offset_must_be_within_range - if day_offset_outside_range?(arrival_day_offset) - errors.add( - :arrival_day_offset, - I18n.t( - 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', - short_id: vehicle_journey.get_objectid.short_id, - max: DAY_OFFSET_MAX + 1 + def day_offset_must_be_within_range + if day_offset_outside_range?(arrival_day_offset) + errors.add( + :arrival_day_offset, + I18n.t( + 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', + short_id: vehicle_journey.get_objectid.short_id, + max: DAY_OFFSET_MAX + 1 + ) ) - ) - end + end - if day_offset_outside_range?(departure_day_offset) - errors.add( - :departure_day_offset, - I18n.t( - 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', - short_id: vehicle_journey.get_objectid.short_id, - max: DAY_OFFSET_MAX + 1 + if day_offset_outside_range?(departure_day_offset) + errors.add( + :departure_day_offset, + I18n.t( + 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', + short_id: vehicle_journey.get_objectid.short_id, + max: DAY_OFFSET_MAX + 1 + ) ) - ) + end end - end - def day_offset_outside_range?(offset) - # At-stops that were created before the database-default of 0 will have - # nil offsets. Handle these gracefully by forcing them to a 0 offset. - offset ||= 0 + def day_offset_outside_range?(offset) + # At-stops that were created before the database-default of 0 will have + # nil offsets. Handle these gracefully by forcing them to a 0 offset. + offset ||= 0 - offset < 0 || offset > DAY_OFFSET_MAX - end + offset < 0 || offset > DAY_OFFSET_MAX + end - def checksum_attributes - [].tap do |attrs| - attrs << self.departure_time.try(:to_s, :time) - attrs << self.arrival_time.try(:to_s, :time) - attrs << self.departure_day_offset.to_s - attrs << self.arrival_day_offset.to_s + def checksum_attributes + [].tap do |attrs| + attrs << self.departure_time.try(:to_s, :time) + attrs << self.arrival_time.try(:to_s, :time) + attrs << self.departure_day_offset.to_s + attrs << self.arrival_day_offset.to_s + end end end end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb index ba6992ed3..b4e6a047d 100644 --- a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb +++ b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb @@ -1,47 +1,49 @@ -class Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator < ActiveModel::EachValidator - def validate_each(vehicle_journey, attribute, value) - previous_at_stop = nil +module Chouette + class VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator < ActiveModel::EachValidator + def validate_each(vehicle_journey, attribute, value) + previous_at_stop = nil - vehicle_journey - .vehicle_journey_at_stops - .select { |vjas| vjas.departure_time && vjas.arrival_time } - .each do |vjas| - unless self.class.validate_at_stop_times_must_increase( - vjas, - previous_at_stop - ) - vehicle_journey.errors.add( - :vehicle_journey_at_stops, - 'time gap overflow' + vehicle_journey + .vehicle_journey_at_stops + .select { |vjas| vjas.departure_time && vjas.arrival_time } + .each do |vjas| + unless self.class.validate_at_stop_times_must_increase( + vjas, + previous_at_stop ) + vehicle_journey.errors.add( + :vehicle_journey_at_stops, + 'time gap overflow' + ) + end + + previous_at_stop = vjas end + end - previous_at_stop = vjas - end - end + def self.validate_at_stop_times_must_increase(at_stop, previous_at_stop) + valid = true + return valid unless previous_at_stop - def self.validate_at_stop_times_must_increase(at_stop, previous_at_stop) - valid = true - return valid unless previous_at_stop + if TimeDuration.exceeds_gap?( + 4.hours, + previous_at_stop.departure_time, + at_stop.departure_time + ) + valid = false + at_stop.errors.add(:departure_time, 'departure time gap overflow') + end - if TimeDuration.exceeds_gap?( - 4.hours, - previous_at_stop.departure_time, - at_stop.departure_time - ) - valid = false - at_stop.errors.add(:departure_time, 'departure time gap overflow') - end + if TimeDuration.exceeds_gap?( + 4.hours, + previous_at_stop.arrival_time, + at_stop.arrival_time + ) + valid = false + at_stop.errors.add(:arrival_time, 'arrival time gap overflow') + end - if TimeDuration.exceeds_gap?( - 4.hours, - previous_at_stop.arrival_time, - at_stop.arrival_time - ) - valid = false - at_stop.errors.add(:arrival_time, 'arrival time gap overflow') + valid end - - valid end end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb index 60b8c2edf..b2cb90d11 100644 --- a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb +++ b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb @@ -1,40 +1,42 @@ -class Chouette::VehicleJourneyAtStopsDayOffset - def initialize(at_stops) - @at_stops = at_stops - end +module Chouette + class VehicleJourneyAtStopsDayOffset + def initialize(at_stops) + @at_stops = at_stops + end - def calculate! - arrival_offset = 0 - departure_offset = 0 + def calculate! + arrival_offset = 0 + departure_offset = 0 - @at_stops.inject(nil) do |prior_stop, stop| - next stop if prior_stop.nil? + @at_stops.inject(nil) do |prior_stop, stop| + next stop if prior_stop.nil? - if stop.arrival_time < prior_stop.departure_time || - stop.arrival_time < prior_stop.arrival_time - arrival_offset += 1 - end + if stop.arrival_time < prior_stop.departure_time || + stop.arrival_time < prior_stop.arrival_time + arrival_offset += 1 + end - if stop.departure_time < stop.arrival_time || - stop.departure_time < prior_stop.departure_time - departure_offset += 1 - end + if stop.departure_time < stop.arrival_time || + stop.departure_time < prior_stop.departure_time + departure_offset += 1 + end - stop.arrival_day_offset = arrival_offset - stop.departure_day_offset = departure_offset + stop.arrival_day_offset = arrival_offset + stop.departure_day_offset = departure_offset - stop + stop + end end - end - def save - @at_stops.each do |at_stop| - at_stop.save + def save + @at_stops.each do |at_stop| + at_stop.save + end end - end - def update - calculate! - save + def update + calculate! + save + end end end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_frequency.rb b/app/models/chouette/vehicle_journey_frequency.rb index 61bc1206d..53e85121f 100644 --- a/app/models/chouette/vehicle_journey_frequency.rb +++ b/app/models/chouette/vehicle_journey_frequency.rb @@ -1,67 +1,69 @@ -class Chouette::VehicleJourneyFrequency < Chouette::VehicleJourney +module Chouette + class VehicleJourneyFrequency < Chouette::VehicleJourney - after_initialize :fill_journey_category + after_initialize :fill_journey_category - default_scope { where(journey_category: journey_categories[:frequency]) } + default_scope { where(journey_category: journey_categories[:frequency]) } - has_many :journey_frequencies, dependent: :destroy, foreign_key: 'vehicle_journey_id' - accepts_nested_attributes_for :journey_frequencies, allow_destroy: true + has_many :journey_frequencies, dependent: :destroy, foreign_key: 'vehicle_journey_id' + accepts_nested_attributes_for :journey_frequencies, allow_destroy: true - validate :require_at_least_one_frequency + validate :require_at_least_one_frequency - def self.matrix(vehicle_journeys) - hash = {} - vehicle_journeys.each do |vj| - vj.journey_frequencies.each do |jf| - next if jf.scheduled_headway_interval.hour == 0 && jf.scheduled_headway_interval.min == 0 - interval = jf.scheduled_headway_interval.hour.hours + jf.scheduled_headway_interval.min.minutes - first_departure_time = jf.first_departure_time - while first_departure_time <= jf.last_departure_time - hash[first_departure_time] = vj - first_departure_time += interval + def self.matrix(vehicle_journeys) + hash = {} + vehicle_journeys.each do |vj| + vj.journey_frequencies.each do |jf| + next if jf.scheduled_headway_interval.hour == 0 && jf.scheduled_headway_interval.min == 0 + interval = jf.scheduled_headway_interval.hour.hours + jf.scheduled_headway_interval.min.minutes + first_departure_time = jf.first_departure_time + while first_departure_time <= jf.last_departure_time + hash[first_departure_time] = vj + first_departure_time += interval + end end end + hash.sort.to_h end - hash.sort.to_h - end - def self.matrix_interval(matrix) - hash = prepare_matrix(matrix) - matrix.each do |departure_time, vj| - @base_departure_time = departure_time - vj.vehicle_journey_at_stops.each_cons(2) { |vjas, vjas_next| - vjas_dup = vjas.dup - vjas_dup.departure_time = @base_departure_time - hash[vjas.stop_point.stop_area.name][departure_time.to_i] = vjas_dup - @base_departure_time = vjas_dup.departure_time + (vjas_next.departure_time - vjas.departure_time) - @last_vjas_next = vjas_next.dup - } - # Add last stop_point - @last_vjas_next.departure_time = @base_departure_time - hash[@last_vjas_next.stop_point.stop_area.name][departure_time.to_i] = @last_vjas_next + def self.matrix_interval(matrix) + hash = prepare_matrix(matrix) + matrix.each do |departure_time, vj| + @base_departure_time = departure_time + vj.vehicle_journey_at_stops.each_cons(2) { |vjas, vjas_next| + vjas_dup = vjas.dup + vjas_dup.departure_time = @base_departure_time + hash[vjas.stop_point.stop_area.name][departure_time.to_i] = vjas_dup + @base_departure_time = vjas_dup.departure_time + (vjas_next.departure_time - vjas.departure_time) + @last_vjas_next = vjas_next.dup + } + # Add last stop_point + @last_vjas_next.departure_time = @base_departure_time + hash[@last_vjas_next.stop_point.stop_area.name][departure_time.to_i] = @last_vjas_next + end + hash end - hash - end - private + private - def self.prepare_matrix(matrix) - matrix.map{ |departure_time, vj| - Hash[ - vj.vehicle_journey_at_stops.map{ |sp| - [ - sp.stop_point.stop_area.name, Hash[matrix.map{ |departure_time2, vj2| [departure_time2.to_i, nil] }] - ] - } - ] - }.inject(&:merge) - end + def self.prepare_matrix(matrix) + matrix.map{ |departure_time, vj| + Hash[ + vj.vehicle_journey_at_stops.map{ |sp| + [ + sp.stop_point.stop_area.name, Hash[matrix.map{ |departure_time2, vj2| [departure_time2.to_i, nil] }] + ] + } + ] + }.inject(&:merge) + end - def fill_journey_category - self.journey_category = :frequency - end + def fill_journey_category + self.journey_category = :frequency + end - def require_at_least_one_frequency - errors.add(:base, I18n.t('vehicle_journey_frequency.require_at_least_one_frequency')) unless journey_frequencies.size > 0 + def require_at_least_one_frequency + errors.add(:base, I18n.t('vehicle_journey_frequency.require_at_least_one_frequency')) unless journey_frequencies.size > 0 + end end end
\ No newline at end of file diff --git a/app/policies/chouette/access_link_policy.rb b/app/policies/chouette/access_link_policy.rb index bee7984c0..539262458 100644 --- a/app/policies/chouette/access_link_policy.rb +++ b/app/policies/chouette/access_link_policy.rb @@ -1,19 +1,21 @@ -class Chouette::AccessLinkPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class AccessLinkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('access_links.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('access_links.create') + end - def update? - !archived? && organisation_match? && user.has_permission?('access_links.update') - end + def update? + !archived? && organisation_match? && user.has_permission?('access_links.update') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('access_links.destroy') + def destroy? + !archived? && organisation_match? && user.has_permission?('access_links.destroy') + end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/access_point_policy.rb b/app/policies/chouette/access_point_policy.rb index 6a570c812..2ecd971cd 100644 --- a/app/policies/chouette/access_point_policy.rb +++ b/app/policies/chouette/access_point_policy.rb @@ -1,19 +1,21 @@ -class Chouette::AccessPointPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class AccessPointPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('access_points.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('access_points.create') + end - def update? - !archived? && organisation_match? && user.has_permission?('access_points.update') - end + def update? + !archived? && organisation_match? && user.has_permission?('access_points.update') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('access_points.destroy') + def destroy? + !archived? && organisation_match? && user.has_permission?('access_points.destroy') + end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/company_policy.rb b/app/policies/chouette/company_policy.rb index 8fa22b5df..f2167b91e 100644 --- a/app/policies/chouette/company_policy.rb +++ b/app/policies/chouette/company_policy.rb @@ -1,7 +1,9 @@ -class Chouette::CompanyPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class CompanyPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end end - end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/connection_link_policy.rb b/app/policies/chouette/connection_link_policy.rb index 65c4101f0..ac7b1746a 100644 --- a/app/policies/chouette/connection_link_policy.rb +++ b/app/policies/chouette/connection_link_policy.rb @@ -1,19 +1,21 @@ -class Chouette::ConnectionLinkPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class ConnectionLinkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('connection_links.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('connection_links.create') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('connection_links.destroy') - end + def destroy? + !archived? && organisation_match? && user.has_permission?('connection_links.destroy') + end - def update? - !archived? && organisation_match? && user.has_permission?('connection_links.update') + def update? + !archived? && organisation_match? && user.has_permission?('connection_links.update') + end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/group_of_line_policy.rb b/app/policies/chouette/group_of_line_policy.rb index 9b4fbb4d8..f31107452 100644 --- a/app/policies/chouette/group_of_line_policy.rb +++ b/app/policies/chouette/group_of_line_policy.rb @@ -1,7 +1,9 @@ -class Chouette::GroupOfLinePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class GroupOfLinePolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/journey_pattern_policy.rb b/app/policies/chouette/journey_pattern_policy.rb index 2fb1c9fd4..add28e0ca 100644 --- a/app/policies/chouette/journey_pattern_policy.rb +++ b/app/policies/chouette/journey_pattern_policy.rb @@ -1,21 +1,22 @@ -class Chouette::JourneyPatternPolicy < ApplicationPolicy +module Chouette + class JourneyPatternPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('journey_patterns.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('journey_patterns.create') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') - end + def destroy? + !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') + end - def update? - !archived? && organisation_match? && user.has_permission?('journey_patterns.update') + def update? + !archived? && organisation_match? && user.has_permission?('journey_patterns.update') + end end -end - +end
\ No newline at end of file diff --git a/app/policies/chouette/line_policy.rb b/app/policies/chouette/line_policy.rb index d07ad775c..678191ef7 100644 --- a/app/policies/chouette/line_policy.rb +++ b/app/policies/chouette/line_policy.rb @@ -1,23 +1,25 @@ -class Chouette::LinePolicy < ApplicationPolicy +module Chouette + class LinePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope + class Scope < Scope + def resolve + scope + end end - end - def create_footnote? - !archived? && organisation_match? && user.has_permission?('footnotes.create') - end + def create_footnote? + !archived? && organisation_match? && user.has_permission?('footnotes.create') + end - def edit_footnote? - !archived? && organisation_match? && user.has_permission?('footnotes.update') - end + def edit_footnote? + !archived? && organisation_match? && user.has_permission?('footnotes.update') + end - def destroy_footnote? - !archived? && organisation_match? && user.has_permission?('footnotes.destroy') - end + def destroy_footnote? + !archived? && organisation_match? && user.has_permission?('footnotes.destroy') + end - def update_footnote? ; edit_footnote? end - def new_footnote? ; create_footnote? end -end + def update_footnote? ; edit_footnote? end + def new_footnote? ; create_footnote? end + end +end
\ No newline at end of file diff --git a/app/policies/chouette/network_policy.rb b/app/policies/chouette/network_policy.rb index faea4bb79..d792645b7 100644 --- a/app/policies/chouette/network_policy.rb +++ b/app/policies/chouette/network_policy.rb @@ -1,7 +1,9 @@ -class Chouette::NetworkPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class NetworkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/route_policy.rb b/app/policies/chouette/route_policy.rb index 5f467d98f..224d3c09e 100644 --- a/app/policies/chouette/route_policy.rb +++ b/app/policies/chouette/route_policy.rb @@ -1,23 +1,25 @@ -class Chouette::RoutePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class RoutePolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('routes.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('routes.create') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('routes.destroy') - end + def destroy? + !archived? && organisation_match? && user.has_permission?('routes.destroy') + end - def update? - !archived? && organisation_match? && user.has_permission?('routes.update') - end + def update? + !archived? && organisation_match? && user.has_permission?('routes.update') + end - def duplicate? - create? + def duplicate? + create? + end end end
\ No newline at end of file diff --git a/app/policies/chouette/routing_constraint_zone_policy.rb b/app/policies/chouette/routing_constraint_zone_policy.rb index 955ae21e6..ce08cfde5 100644 --- a/app/policies/chouette/routing_constraint_zone_policy.rb +++ b/app/policies/chouette/routing_constraint_zone_policy.rb @@ -1,19 +1,21 @@ -class Chouette::RoutingConstraintZonePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class RoutingConstraintZonePolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy') - end + def destroy? + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy') + end - def update? - !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update') + def update? + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update') + end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/stop_area_policy.rb b/app/policies/chouette/stop_area_policy.rb index 75cbf15a3..1a34b3753 100644 --- a/app/policies/chouette/stop_area_policy.rb +++ b/app/policies/chouette/stop_area_policy.rb @@ -1,7 +1,9 @@ -class Chouette::StopAreaPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class StopAreaPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/time_table_policy.rb b/app/policies/chouette/time_table_policy.rb index 2eb21ddf1..33a5f541a 100644 --- a/app/policies/chouette/time_table_policy.rb +++ b/app/policies/chouette/time_table_policy.rb @@ -1,32 +1,34 @@ -class Chouette::TimeTablePolicy < ApplicationPolicy +module Chouette + class TimeTablePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('time_tables.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('time_tables.create') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('time_tables.destroy') - end + def destroy? + !archived? && organisation_match? && user.has_permission?('time_tables.destroy') + end - def update? - !archived? && organisation_match? && user.has_permission?('time_tables.update') - end + def update? + !archived? && organisation_match? && user.has_permission?('time_tables.update') + end - def actualize? - !archived? && organisation_match? && edit? - end + def actualize? + !archived? && organisation_match? && edit? + end - def duplicate? - !archived? && organisation_match? && create? - end + def duplicate? + !archived? && organisation_match? && create? + end - def month? - update? + def month? + update? + end end -end +end
\ No newline at end of file diff --git a/app/policies/chouette/vehicle_journey_policy.rb b/app/policies/chouette/vehicle_journey_policy.rb index 646b0c07d..744c6f8d4 100644 --- a/app/policies/chouette/vehicle_journey_policy.rb +++ b/app/policies/chouette/vehicle_journey_policy.rb @@ -1,19 +1,21 @@ -class Chouette::VehicleJourneyPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope +module Chouette + class VehicleJourneyPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end end - end - def create? - !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') - end + def create? + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') + end - def destroy? - !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') - end + def destroy? + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') + end - def update? - !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update') + def update? + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update') + end end -end +end
\ No newline at end of file diff --git a/app/views/connection_links/_connection_link.slim b/app/views/connection_links/_connection_link.slim index 2ece8ed44..44ed5093f 100644 --- a/app/views/connection_links/_connection_link.slim +++ b/app/views/connection_links/_connection_link.slim @@ -11,7 +11,7 @@ span.fa.fa-trash-o h5 - = link_to([@referential, connection_link], class: 'preview', title: "#{Chouette::ConnectionLink.model_name.human.capitalize} #{connection_link.name}") do + = link_to referential_connection_link_path(@referential, connection_link), class: 'preview', title: "#{Chouette::ConnectionLink.model_name.human.capitalize} #{connection_link.name}" do span.name = truncate(connection_link.name, :length => 20) diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim index 7e3e1cc85..0cb7ab493 100644 --- a/app/views/lines/index.html.slim +++ b/app/views/lines/index.html.slim @@ -21,7 +21,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'ID Codifligne', \ - attribute: Proc.new { |n| n.objectid.local_id }, \ + attribute: Proc.new { |n| n.get_objectid.local_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/lines/show.html.slim b/app/views/lines/show.html.slim index d8f236ecc..4c6c6fc95 100644 --- a/app/views/lines/show.html.slim +++ b/app/views/lines/show.html.slim @@ -21,7 +21,7 @@ .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { 'ID Codif' => @line.objectid.local_id, + { 'ID Codif' => @line.get_objectid.local_id, 'Activé' => (@line.deactivated? ? t('false') : t('true')), @line.human_attribute_name(:network) => (@line.network.nil? ? t('lines.index.unset') : @line.network.name), @line.human_attribute_name(:company) => (@line.company.nil? ? t('lines.index.unset') : @line.company.name), diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index 0ef548e89..74542d2b6 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -21,7 +21,7 @@ .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { t('id_codif') => @line.objectid.local_id, + { t('id_codif') => @line.get_objectid.local_id, 'Activé' => (@line.deactivated? ? t('false') : t('true')), @line.human_attribute_name(:network) => (@line.network.nil? ? t('lines.index.unset') : link_to(@line.network.name, [@referential, @line.network]) ), @line.human_attribute_name(:company) => (@line.company.nil? ? t('lines.index.unset') : link_to(@line.company.name, [@referential, @line.company]) ), @@ -48,7 +48,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'ID', \ - attribute: Proc.new { |n| n.objectid.short_id }, \ + attribute: Proc.new { |n| n.get_objectid.short_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index b03fb9f53..33dc07567 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -43,7 +43,7 @@ [ \ TableBuilderHelper::Column.new( \ name: t('id_codif'), \ - attribute: Proc.new { |n| n.objectid.local_id }, \ + attribute: Proc.new { |n| n.get_objectid.local_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index 1411a5502..329be4b5f 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -22,7 +22,7 @@ .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { t('objectid') => @route.objectid.short_id, + { t('objectid') => @route.get_objectid.short_id, t('activerecord.attributes.route.published_name') => (@route.published_name ? @route.published_name : '-'), @route.human_attribute_name(:wayback) => (@route.wayback ? @route.wayback_text : '-' ), @route.human_attribute_name(:opposite_route) => (@route.opposite_route ? @route.opposite_route.name : '-') } diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim index ddad7723e..fcf904070 100644 --- a/app/views/routing_constraint_zones/index.html.slim +++ b/app/views/routing_constraint_zones/index.html.slim @@ -21,7 +21,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'ID', \ - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ + attribute: Proc.new { |n| n.get_objectid.local_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index b0f4e84c5..edbf89c43 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -19,7 +19,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'ID', \ - attribute: Proc.new { |n| n.objectid.short_id}, \ + attribute: Proc.new { |n| n.get_objectid.short_id}, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/bin/bundle b/bin/bundle deleted file mode 100755 index 66e9889e8..000000000 --- a/bin/bundle +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') diff --git a/bin/bundle-audit b/bin/bundle-audit deleted file mode 100755 index 70ba44868..000000000 --- a/bin/bundle-audit +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'bundle-audit' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("bundler-audit", "bundle-audit") diff --git a/bin/bundler b/bin/bundler deleted file mode 100755 index d6107f047..000000000 --- a/bin/bundler +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'bundler' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("bundler", "bundler") diff --git a/bin/byebug b/bin/byebug deleted file mode 100755 index d9bf0f4eb..000000000 --- a/bin/byebug +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'byebug' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("byebug", "byebug") diff --git a/bin/cap b/bin/cap deleted file mode 100755 index d2c0b9e5a..000000000 --- a/bin/cap +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'cap' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("capistrano", "cap") diff --git a/bin/capify b/bin/capify deleted file mode 100755 index bdd2c8712..000000000 --- a/bin/capify +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'capify' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("capistrano", "capify") diff --git a/bin/coderay b/bin/coderay deleted file mode 100755 index e248d2436..000000000 --- a/bin/coderay +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'coderay' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("coderay", "coderay") diff --git a/bin/cucumber b/bin/cucumber deleted file mode 100755 index 63ddc2afb..000000000 --- a/bin/cucumber +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'cucumber' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("cucumber", "cucumber") diff --git a/bin/dbf b/bin/dbf deleted file mode 100755 index 081977293..000000000 --- a/bin/dbf +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'dbf' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("dbf", "dbf") diff --git a/bin/dot2ruby b/bin/dot2ruby deleted file mode 100755 index 585531cf7..000000000 --- a/bin/dot2ruby +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'dot2ruby' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("ruby-graphviz", "dot2ruby") diff --git a/bin/erd b/bin/erd deleted file mode 100755 index c112d6420..000000000 --- a/bin/erd +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'erd' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rails-erd", "erd") diff --git a/bin/erubis b/bin/erubis deleted file mode 100755 index 9d0f9cb06..000000000 --- a/bin/erubis +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'erubis' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("erubis", "erubis") diff --git a/bin/gem2gv b/bin/gem2gv deleted file mode 100755 index 31f38af7c..000000000 --- a/bin/gem2gv +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'gem2gv' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("ruby-graphviz", "gem2gv") diff --git a/bin/gherkin-ruby b/bin/gherkin-ruby deleted file mode 100755 index 490d35a71..000000000 --- a/bin/gherkin-ruby +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'gherkin-ruby' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("gherkin", "gherkin-ruby") diff --git a/bin/git2gv b/bin/git2gv deleted file mode 100755 index 6e5d0dac4..000000000 --- a/bin/git2gv +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'git2gv' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("ruby-graphviz", "git2gv") diff --git a/bin/htmlbeautifier b/bin/htmlbeautifier deleted file mode 100755 index 077ceda68..000000000 --- a/bin/htmlbeautifier +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'htmlbeautifier' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("htmlbeautifier", "htmlbeautifier") diff --git a/bin/htmldiff b/bin/htmldiff deleted file mode 100755 index 09c825951..000000000 --- a/bin/htmldiff +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'htmldiff' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("diff-lcs", "htmldiff") diff --git a/bin/httparty b/bin/httparty deleted file mode 100755 index 110df0244..000000000 --- a/bin/httparty +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'httparty' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("httparty", "httparty") diff --git a/bin/i18n-tasks b/bin/i18n-tasks deleted file mode 100755 index bd0dddcaa..000000000 --- a/bin/i18n-tasks +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'i18n-tasks' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("i18n-tasks", "i18n-tasks") diff --git a/bin/launchy b/bin/launchy deleted file mode 100755 index a86ca1756..000000000 --- a/bin/launchy +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'launchy' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("launchy", "launchy") diff --git a/bin/ldiff b/bin/ldiff deleted file mode 100755 index a5e9564aa..000000000 --- a/bin/ldiff +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'ldiff' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("diff-lcs", "ldiff") diff --git a/bin/license_finder b/bin/license_finder deleted file mode 100755 index d5ef03fc6..000000000 --- a/bin/license_finder +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'license_finder' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("license_finder", "license_finder") diff --git a/bin/license_finder_pip.py b/bin/license_finder_pip.py deleted file mode 100755 index 6a1c91be3..000000000 --- a/bin/license_finder_pip.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'license_finder_pip.py' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("license_finder", "license_finder_pip.py") diff --git a/bin/mongrel_rpm b/bin/mongrel_rpm deleted file mode 100755 index 20cb86dc8..000000000 --- a/bin/mongrel_rpm +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'mongrel_rpm' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("newrelic_rpm", "mongrel_rpm") diff --git a/bin/newrelic b/bin/newrelic deleted file mode 100755 index 7a2008dda..000000000 --- a/bin/newrelic +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'newrelic' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("newrelic_rpm", "newrelic") diff --git a/bin/newrelic_cmd b/bin/newrelic_cmd deleted file mode 100755 index 02d32467c..000000000 --- a/bin/newrelic_cmd +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'newrelic_cmd' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("newrelic_rpm", "newrelic_cmd") diff --git a/bin/nokogiri b/bin/nokogiri deleted file mode 100755 index c1f0ca44f..000000000 --- a/bin/nokogiri +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'nokogiri' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("nokogiri", "nokogiri") diff --git a/bin/nrdebug b/bin/nrdebug deleted file mode 100755 index 3878e8590..000000000 --- a/bin/nrdebug +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'nrdebug' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("newrelic_rpm", "nrdebug") diff --git a/bin/pry b/bin/pry deleted file mode 100755 index 743a1337b..000000000 --- a/bin/pry +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'pry' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("pry", "pry") diff --git a/bin/rackup b/bin/rackup deleted file mode 100755 index 0f074e64e..000000000 --- a/bin/rackup +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'rackup' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rack", "rackup") diff --git a/bin/rdoc b/bin/rdoc deleted file mode 100755 index c051912da..000000000 --- a/bin/rdoc +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'rdoc' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rdoc", "rdoc") diff --git a/bin/redcloth b/bin/redcloth deleted file mode 100755 index 02d94175d..000000000 --- a/bin/redcloth +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'redcloth' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("RedCloth", "redcloth") diff --git a/bin/ri b/bin/ri deleted file mode 100755 index 56db0fc44..000000000 --- a/bin/ri +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'ri' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rdoc", "ri") diff --git a/bin/ruby-parse b/bin/ruby-parse deleted file mode 100755 index 20557e7b3..000000000 --- a/bin/ruby-parse +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'ruby-parse' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("parser", "ruby-parse") diff --git a/bin/ruby-rewrite b/bin/ruby-rewrite deleted file mode 100755 index 60032ed17..000000000 --- a/bin/ruby-rewrite +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'ruby-rewrite' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("parser", "ruby-rewrite") diff --git a/bin/ruby2gv b/bin/ruby2gv deleted file mode 100755 index 3b82be141..000000000 --- a/bin/ruby2gv +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'ruby2gv' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("ruby-graphviz", "ruby2gv") diff --git a/bin/safe_yaml b/bin/safe_yaml deleted file mode 100755 index 5979200f1..000000000 --- a/bin/safe_yaml +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'safe_yaml' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("safe_yaml", "safe_yaml") diff --git a/bin/sass b/bin/sass deleted file mode 100755 index ef9f699d8..000000000 --- a/bin/sass +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sass' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sass", "sass") diff --git a/bin/sass-convert b/bin/sass-convert deleted file mode 100755 index 13936f1df..000000000 --- a/bin/sass-convert +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sass-convert' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sass", "sass-convert") diff --git a/bin/scss b/bin/scss deleted file mode 100755 index 76c0dce5f..000000000 --- a/bin/scss +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'scss' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sass", "scss") diff --git a/bin/sdoc b/bin/sdoc deleted file mode 100755 index 6d3dbba68..000000000 --- a/bin/sdoc +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sdoc' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sdoc", "sdoc") diff --git a/bin/sdoc-merge b/bin/sdoc-merge deleted file mode 100755 index 7e997760e..000000000 --- a/bin/sdoc-merge +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sdoc-merge' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sdoc", "sdoc-merge") diff --git a/bin/sequel b/bin/sequel deleted file mode 100755 index bff4fa333..000000000 --- a/bin/sequel +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sequel' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sequel", "sequel") diff --git a/bin/setup b/bin/setup deleted file mode 100755 index acdb2c138..000000000 --- a/bin/setup +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -require 'pathname' - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -Dir.chdir APP_ROOT do - # This script is a starting point to setup your application. - # Add necessary setup steps to this file: - - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install" - - # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" - # end - - puts "\n== Preparing database ==" - system "bin/rake db:setup" - - puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" - - puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" -end diff --git a/bin/sidekiq b/bin/sidekiq deleted file mode 100755 index 83aab28f8..000000000 --- a/bin/sidekiq +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sidekiq' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sidekiq", "sidekiq") diff --git a/bin/sidekiqctl b/bin/sidekiqctl deleted file mode 100755 index 7ea23ddee..000000000 --- a/bin/sidekiqctl +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sidekiqctl' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sidekiq", "sidekiqctl") diff --git a/bin/slimrb b/bin/slimrb deleted file mode 100755 index 8e106805e..000000000 --- a/bin/slimrb +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'slimrb' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("slim", "slimrb") diff --git a/bin/sprockets b/bin/sprockets deleted file mode 100755 index e8ffa4dd9..000000000 --- a/bin/sprockets +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'sprockets' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("sprockets", "sprockets") diff --git a/bin/teaspoon b/bin/teaspoon deleted file mode 100755 index db1919810..000000000 --- a/bin/teaspoon +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'teaspoon' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("teaspoon", "teaspoon") diff --git a/bin/thor b/bin/thor deleted file mode 100755 index 63f10e55d..000000000 --- a/bin/thor +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'thor' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("thor", "thor") diff --git a/bin/tilt b/bin/tilt deleted file mode 100755 index a606a2ee5..000000000 --- a/bin/tilt +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'tilt' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("tilt", "tilt") diff --git a/bin/transpec b/bin/transpec deleted file mode 100755 index be3f396ff..000000000 --- a/bin/transpec +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'transpec' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("transpec", "transpec") diff --git a/bin/webpack b/bin/webpack deleted file mode 100755 index 9d3800c74..000000000 --- a/bin/webpack +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'webpack' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("webpacker", "webpack") diff --git a/bin/webpack-dev-server b/bin/webpack-dev-server deleted file mode 100755 index cf701102a..000000000 --- a/bin/webpack-dev-server +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'webpack-dev-server' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("webpacker", "webpack-dev-server") diff --git a/bin/whenever b/bin/whenever deleted file mode 100755 index 80d7387d7..000000000 --- a/bin/whenever +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'whenever' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("whenever", "whenever") diff --git a/bin/wheneverize b/bin/wheneverize deleted file mode 100755 index 783105e92..000000000 --- a/bin/wheneverize +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'wheneverize' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("whenever", "wheneverize") diff --git a/bin/xml2gv b/bin/xml2gv deleted file mode 100755 index 33b47ef4a..000000000 --- a/bin/xml2gv +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true -# -# This file was generated by Bundler. -# -# The application 'xml2gv' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("ruby-graphviz", "xml2gv") diff --git a/spec/decorators/company_decorator_spec.rb b/spec/decorators/company_decorator_spec.rb index a1df03449..557d98da1 100644 --- a/spec/decorators/company_decorator_spec.rb +++ b/spec/decorators/company_decorator_spec.rb @@ -1,2 +1,2 @@ -describe CompanyDecorator do +describe Chouette::CompanyDecorator do end diff --git a/spec/features/line_footnotes_permissions_spec.rb b/spec/features/line_footnotes_permissions_spec.rb index 62adbfcd5..deac8e8fc 100644 --- a/spec/features/line_footnotes_permissions_spec.rb +++ b/spec/features/line_footnotes_permissions_spec.rb @@ -10,7 +10,7 @@ describe 'Line Footnotes', type: :feature do describe 'permissions' do before do - allow_any_instance_of(LinePolicy).to receive(:update_footnote?).and_return permission + allow_any_instance_of(Chouette::LinePolicy).to receive(:update_footnote?).and_return permission visit path end diff --git a/spec/features/lines_permissions_spec.rb b/spec/features/lines_permissions_spec.rb index 5d53d6568..903868fae 100644 --- a/spec/features/lines_permissions_spec.rb +++ b/spec/features/lines_permissions_spec.rb @@ -13,8 +13,8 @@ describe "Lines", :type => :feature do create :group_of_line line_referential.lines << line line_referential.organisations << Organisation.first - allow_any_instance_of(LinePolicy).to receive(:create?).and_return permission - allow_any_instance_of(LinePolicy).to receive(:destroy?).and_return permission + allow_any_instance_of(Chouette::LinePolicy).to receive(:create?).and_return permission + allow_any_instance_of(Chouette::LinePolicy).to receive(:destroy?).and_return permission visit path end diff --git a/spec/features/referential_lines_permissions_spec.rb b/spec/features/referential_lines_permissions_spec.rb index 0d156f0d6..bedec3d07 100644 --- a/spec/features/referential_lines_permissions_spec.rb +++ b/spec/features/referential_lines_permissions_spec.rb @@ -7,7 +7,7 @@ describe 'ReferentialLines', type: :feature do context 'permissions' do before do - allow_any_instance_of(RoutePolicy).to receive(:create?).and_return permission + allow_any_instance_of(Chouette::RoutePolicy).to receive(:create?).and_return permission visit path end diff --git a/spec/features/routes_permissions_spec.rb b/spec/features/routes_permissions_spec.rb index 36c13b24a..467d8479d 100644 --- a/spec/features/routes_permissions_spec.rb +++ b/spec/features/routes_permissions_spec.rb @@ -11,8 +11,8 @@ describe "Routes", :type => :feature do describe 'permissions' do before do @user.update(organisation: referential.organisation) - allow_any_instance_of(RoutePolicy).to receive(:edit?).and_return permission - allow_any_instance_of(RoutePolicy).to receive(:destroy?).and_return permission + allow_any_instance_of(Chouette::RoutePolicy).to receive(:edit?).and_return permission + allow_any_instance_of(Chouette::RoutePolicy).to receive(:destroy?).and_return permission visit path end diff --git a/spec/features/time_tables_permissions_spec.rb b/spec/features/time_tables_permissions_spec.rb index bd94a3aa1..01c7c2ed2 100644 --- a/spec/features/time_tables_permissions_spec.rb +++ b/spec/features/time_tables_permissions_spec.rb @@ -8,7 +8,7 @@ describe "TimeTables", :type => :feature do describe 'permissions' do before do - allow_any_instance_of(TimeTablePolicy).to receive(:duplicate?).and_return permission + allow_any_instance_of(Chouette::TimeTablePolicy).to receive(:duplicate?).and_return permission visit path end diff --git a/spec/policies/access_link_policy_spec.rb b/spec/policies/access_link_policy_spec.rb index 6194ae55c..392ad7f92 100644 --- a/spec/policies/access_link_policy_spec.rb +++ b/spec/policies/access_link_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe AccessLinkPolicy, type: :policy do +RSpec.describe Chouette::AccessLinkPolicy, type: :policy do let( :record ){ build_stubbed :access_link } diff --git a/spec/policies/access_point_policy_spec.rb b/spec/policies/access_point_policy_spec.rb index b6bc46eb4..8154b3d24 100644 --- a/spec/policies/access_point_policy_spec.rb +++ b/spec/policies/access_point_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe AccessPointPolicy, type: :policy do +RSpec.describe Chouette::AccessPointPolicy, type: :policy do let( :record ){ build_stubbed :access_point } diff --git a/spec/policies/company_policy_spec.rb b/spec/policies/company_policy_spec.rb index 2d249a2be..f374e31d2 100644 --- a/spec/policies/company_policy_spec.rb +++ b/spec/policies/company_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe CompanyPolicy, type: :policy do +RSpec.describe Chouette::CompanyPolicy, type: :policy do let( :record ){ build_stubbed :company } before { stub_policy_scope(record) } diff --git a/spec/policies/connection_link_policy_spec.rb b/spec/policies/connection_link_policy_spec.rb index 23e40abe3..17cfdeb04 100644 --- a/spec/policies/connection_link_policy_spec.rb +++ b/spec/policies/connection_link_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ConnectionLinkPolicy, type: :policy do +RSpec.describe Chouette::ConnectionLinkPolicy, type: :policy do let( :record ){ build_stubbed :connection_link } diff --git a/spec/policies/group_of_line_policy_spec.rb b/spec/policies/group_of_line_policy_spec.rb index 29fbb1bfb..7a58a7f0e 100644 --- a/spec/policies/group_of_line_policy_spec.rb +++ b/spec/policies/group_of_line_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe GroupOfLinePolicy, type: :policy do +RSpec.describe Chouette::GroupOfLinePolicy, type: :policy do let( :record ){ build_stubbed :group_of_line } before { stub_policy_scope(record) } diff --git a/spec/policies/journey_pattern_policy_spec.rb b/spec/policies/journey_pattern_policy_spec.rb index 39f849277..a7de379a2 100644 --- a/spec/policies/journey_pattern_policy_spec.rb +++ b/spec/policies/journey_pattern_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe JourneyPatternPolicy, type: :policy do +RSpec.describe Chouette::JourneyPatternPolicy, type: :policy do let( :record ){ build_stubbed :journey_pattern } diff --git a/spec/policies/line_policy_spec.rb b/spec/policies/line_policy_spec.rb index 334073506..d2248e750 100644 --- a/spec/policies/line_policy_spec.rb +++ b/spec/policies/line_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe LinePolicy, type: :policy do +RSpec.describe Chouette::LinePolicy, type: :policy do let( :record ){ build_stubbed :line } before { stub_policy_scope(record) } diff --git a/spec/policies/network_policy_spec.rb b/spec/policies/network_policy_spec.rb index ae4ffa03a..c09546c22 100644 --- a/spec/policies/network_policy_spec.rb +++ b/spec/policies/network_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe NetworkPolicy, type: :policy do +RSpec.describe Chouette::NetworkPolicy, type: :policy do let( :record ){ build_stubbed :network } before { stub_policy_scope(record) } diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb index d7edceaef..df2e41a89 100644 --- a/spec/policies/route_policy_spec.rb +++ b/spec/policies/route_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe RoutePolicy, type: :policy do +RSpec.describe Chouette::RoutePolicy, type: :policy do let( :record ){ build_stubbed :route } diff --git a/spec/policies/routing_constraint_zone_policy_spec.rb b/spec/policies/routing_constraint_zone_policy_spec.rb index 2ef15fa95..903e3671a 100644 --- a/spec/policies/routing_constraint_zone_policy_spec.rb +++ b/spec/policies/routing_constraint_zone_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe RoutingConstraintZonePolicy, type: :policy do +RSpec.describe Chouette::RoutingConstraintZonePolicy, type: :policy do let( :record ){ build_stubbed :routing_constraint_zone } diff --git a/spec/policies/stop_area_policy_spec.rb b/spec/policies/stop_area_policy_spec.rb index 8fe59c8e3..1295ecd68 100644 --- a/spec/policies/stop_area_policy_spec.rb +++ b/spec/policies/stop_area_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe StopAreaPolicy, type: :policy do +RSpec.describe Chouette::StopAreaPolicy, type: :policy do let( :record ){ build_stubbed :stop_area } before { stub_policy_scope(record) } diff --git a/spec/policies/time_table_policy_spec.rb b/spec/policies/time_table_policy_spec.rb index dad3c13bc..6f1e13844 100644 --- a/spec/policies/time_table_policy_spec.rb +++ b/spec/policies/time_table_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe TimeTablePolicy, type: :policy do +RSpec.describe Chouette::TimeTablePolicy, type: :policy do let( :record ){ build_stubbed :time_table } diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 6f60bd86b..b615491da 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -46,9 +46,11 @@ RSpec.configure do |config| organisation = Organisation.create!(code: "first", name: "first") line_referential = LineReferential.find_or_create_by(name: "first") do |referential| + referential.objectid_format = "stif_codifligne" referential.add_member organisation, owner: true end stop_area_referential = StopAreaReferential.find_or_create_by(name: "first") do |referential| + referential.objectid_format = "stif_reflex" referential.add_member organisation, owner: true end @@ -65,7 +67,8 @@ RSpec.configure do |config| name: "first", slug: "first", organisation: organisation, - workbench: workbench + workbench: workbench, + objectid_format: "stif_netex" ) end diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index dae8c9ed3..ee917127f 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -6,7 +6,7 @@ RSpec.describe "/routes/show", type: :view do let!(:route_sp) do assign :route_sp, ModelDecorator.decorate( route.stop_points, - with: StopPointDecorator + with: Chouette::StopPointDecorator ) end |
