From 81835c55a027e4b5dda06a2d5e1107315f1bf24d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 8 Mar 2009 16:13:00 +0000 Subject: [PATCH] Commit ACL related files from earlier merges as svn merge seems to neglected to add them... --- app/models/acl.rb | 13 +++++++++++++ db/migrate/018_create_acls.rb | 22 ++++++++++++++++++++++ test/fixtures/acls.yml | 13 +++++++++++++ test/unit/acl_test.rb | 8 ++++++++ 4 files changed, 56 insertions(+) create mode 100644 app/models/acl.rb create mode 100644 db/migrate/018_create_acls.rb create mode 100644 test/fixtures/acls.yml create mode 100644 test/unit/acl_test.rb diff --git a/app/models/acl.rb b/app/models/acl.rb new file mode 100644 index 000000000..5fb99b9e5 --- /dev/null +++ b/app/models/acl.rb @@ -0,0 +1,13 @@ +class Acl < ActiveRecord::Base + def self.find_by_address(address, options) + self.with_scope(:find => {:conditions => ["inet_aton(?) & netmask = address", address]}) do + return self.find(:first, options) + end + end + + def self.find_all_by_address(address, options) + self.with_scope(:find => {:conditions => ["inet_aton(?) & netmask = address", address]}) do + return self.find(:all, options) + end + end +end diff --git a/db/migrate/018_create_acls.rb b/db/migrate/018_create_acls.rb new file mode 100644 index 000000000..3606bd670 --- /dev/null +++ b/db/migrate/018_create_acls.rb @@ -0,0 +1,22 @@ +class CreateAcls < ActiveRecord::Migration + def self.up + create_table "acls", myisam_table do |t| + t.column "id", :integer, :null => false + t.column "address", :integer, :null => false + t.column "netmask", :integer, :null => false + t.column "k", :string, :null => false + t.column "v", :string + end + + add_primary_key "acls", ["id"] + add_index "acls", ["k"], :name => "acls_k_idx" + + change_column "acls", "id", :integer, :null => false, :options => "AUTO_INCREMENT" + change_column "acls", "address", :integer, :null => false, :unsigned => true + change_column "acls", "netmask", :integer, :null => false, :unsigned => true + end + + def self.down + drop_table "acls" + end +end diff --git a/test/fixtures/acls.yml b/test/fixtures/acls.yml new file mode 100644 index 000000000..399e08808 --- /dev/null +++ b/test/fixtures/acls.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + address: 1 + netmask: 1 + k: MyText + v: MyText + +two: + address: 1 + netmask: 1 + k: MyText + v: MyText diff --git a/test/unit/acl_test.rb b/test/unit/acl_test.rb new file mode 100644 index 000000000..991e6eb84 --- /dev/null +++ b/test/unit/acl_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class AclTest < ActiveSupport::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end -- 2.43.2