Sha256: be92d8c182567fe263f881cea0ecc1af5fcee5df158ac320bf12d12c6dfbc846

Contents?: true

Size: 1.58 KB

Versions: 22

Compression:

Stored size: 1.58 KB

Contents

module PatronusFati::DataModels
  class AccessPoint
    include DataMapper::Resource

    include PatronusFati::DataModels::ExpirationAttributes
    include PatronusFati::DataModels::ReportedAttributes

    property  :id,                Serial

    property  :bssid,             String, :length       => 17,
                                          :required     => true,
                                          :unique_index => true

    property  :channel,           Integer
    property  :max_seen_rate,     Integer
    property  :type,              String, :required => true

    has n, :clients,        :through    => :connections
    has n, :connections,    :constraint => :destroy,
                            :child_key  => :access_point_id
    has n, :ssids,          :constraint => :destroy

    belongs_to :mac, :required => false
    before :save do
      self.mac = Mac.first_or_create(mac: bssid)
    end

    def self.current_expiration_threshold
      Time.now.to_i - PatronusFati::AP_EXPIRATION
    end

    def connected_clients
      connections.active.clients
    end

    def current_ssids
      ssids.active
    end

    def disconnect_clients!
      connections.connected.map(&:disconnect!)
    end

    def full_state
      blacklisted_keys = %w(id last_seen_at reported_online).map(&:to_sym)
      attributes
        .reject { |k, v| blacklisted_keys.include?(k) || v.nil? }
        .merge(
          active: active?,
          connected_clients: connected_clients.map(&:bssid),
          vendor: mac.vendor,
          ssids: current_ssids.map(&:full_state)
        )
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
patronus_fati-0.9.11 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.10 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.9 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.8 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.7 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.6 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.5 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.4 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.3 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.2 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.1 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.0 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.18 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.17 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.16 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.15 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.14 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.13 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.12 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.8.11 lib/patronus_fati/data_models/access_point.rb