-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename hidden attributes to private attributes
- Loading branch information
Showing
8 changed files
with
49 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
lib/extensions/ar_visible_attribute.rb → lib/extensions/ar_private_attribute.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
module ArVisibleAttribute | ||
module ArPrivateAttribute | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
class_attribute :hidden_attribute_names, :default => [] | ||
class_attribute :private_attribute_names, :default => [] | ||
end | ||
|
||
class_methods do | ||
# @param [String|Symbol] attribute name of attribute to be hidden from the api and reporting | ||
# @param [String|Symbol] attribute name of attribute to be private from the api and reporting | ||
# this attribute is accessible to all ruby methods. But it is not advertised. | ||
# we do this when deprecating an attribute or when introducing an internal attribute | ||
def hide_attribute(attribute) | ||
self.hidden_attribute_names += [attribute.to_s] | ||
def private_attribute(attribute) | ||
self.private_attribute_names += [attribute.to_s] | ||
end | ||
|
||
# @return Array[String] attribute names that can be advertised in the api and reporting | ||
# Other attributes are accessible, they are just no longer in our public api (or never were) | ||
def visible_attribute_names | ||
self.attribute_names - self.hidden_attribute_names | ||
def public_attribute_names | ||
self.attribute_names - self.private_attribute_names | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
RSpec.describe ArPrivateAttribute do | ||
# NOTE: ApplicationRecord already included ArPrivateAttribute | ||
let(:klass) { Class.new(ApplicationRecord) { self.table_name = "vms" } } | ||
let(:other_klass) { Class.new(ApplicationRecord) { self.table_name = "vms" } } | ||
|
||
context ".public_attribute_names" do | ||
it "shows regular attributes" do | ||
expect(klass.public_attribute_names).to include("type") | ||
end | ||
|
||
it "hides private attributes" do | ||
klass.private_attribute :type | ||
expect(klass.public_attribute_names).not_to include("type") | ||
end | ||
|
||
it "only hides attributes for the specified class" do | ||
klass.private_attribute :type | ||
expect(other_klass.public_attribute_names).to include("type") | ||
end | ||
end | ||
|
||
context ".private_attribute_names" do | ||
it "starts with no private attributes" do | ||
expect(klass.private_attribute_names).to be_empty | ||
end | ||
|
||
it "hides private attributes" do | ||
klass.private_attribute :type | ||
expect(klass.private_attribute_names).to include("type") | ||
end | ||
|
||
it "only hides for specified class" do | ||
klass.private_attribute :type | ||
expect(other_klass.private_attribute_names).not_to include("type") | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.