diff options
| author | cedricnjanga | 2017-11-21 15:32:22 +0100 | 
|---|---|---|
| committer | cedricnjanga | 2017-11-21 15:32:22 +0100 | 
| commit | 763010ced3202c99f705562a373861f926aad9a1 (patch) | |
| tree | a316366c92fcf9c88aa8d08ff34e0b737196d618 /app/models/chouette/network.rb | |
| parent | 80bfa87237b78e426e4362a503fe4d72e130beb5 (diff) | |
| download | chouette-core-763010ced3202c99f705562a373861f926aad9a1.tar.bz2 | |
Change the way we name classes
We now always use modules for namespaces
=> same structure for models, decorators, policies...
Diffstat (limited to 'app/models/chouette/network.rb')
| -rw-r--r-- | app/models/chouette/network.rb | 75 | 
1 files changed, 38 insertions, 37 deletions
| 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 | 
