lib/jsonapionify/api/attribute.rb in jsonapionify-0.10.2 vs lib/jsonapionify/api/attribute.rb in jsonapionify-0.11.0

- old
+ new

@@ -5,20 +5,21 @@ extend JSONAPIonify::Autoload autoload_all include Documentation using UnstrictProc - attr_reader :name, :type, :description, :read, :write, :required, :block + attr_reader :name, :type, :description, :read, :write, :required, :hidden, :block def initialize( name, type, description, read: true, write: true, required: false, example: nil, + hidden: false, &block ) unless type.is_a? JSONAPIonify::Types::BaseType raise TypeError, "#{type} is not a valid JSON type" end @@ -31,16 +32,22 @@ @write = write&.freeze @required = required&.freeze @block = block&.freeze @writeable_actions = write @readable_actions = read + @hidden = !!hidden && (hidden == true || Array.wrap(hidden)) freeze end def ==(other) self.class == other.class && self.name == other.name + end + + def hidden_for_action?(action_name) + return false if hidden == false + Array.wrap(hidden).any? { |h| h == true || h.to_s == action_name.to_s } end def supports_read_for_action?(action_name, context) case (setting = @readable_actions) when TrueClass, FalseClass