Sha256: 4e2d8e7bb293979386502dcc6900c97caa4acf9b72e926710d3ca317dac8d6be

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

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

    include PatronusFati::DataModels::AutoVendorLookup
    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

    vendor_attribute :bssid

    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: vendor,
          ssids: current_ssids.map(&:full_state)
        )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
patronus_fati-0.9.16 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.15 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.14 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.13 lib/patronus_fati/data_models/access_point.rb
patronus_fati-0.9.12 lib/patronus_fati/data_models/access_point.rb