Class: Bluepine::Attributes::Attribute Abstract
- Inherits:
-
Object
- Object
- Bluepine::Attributes::Attribute
- Includes:
- Bluepine::Assertions, Serializers::Serializable, Validators::Normalizable, Validators::Validatable
- Defined in:
- lib/bluepine/attributes/attribute.rb
Overview
This class is abstract.
An abstract Attribute based class.
Direct Known Subclasses
ArrayAttribute, BooleanAttribute, NumberAttribute, ObjectAttribute, StringAttribute
Constant Summary
Constants included from Bluepine::Assertions
Bluepine::Assertions::Error, Bluepine::Assertions::KeyError, Bluepine::Assertions::SubsetError
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #attributes ⇒ Object
- #default ⇒ Object
-
#deprecated ⇒ Object
deprecated attribute should be listed in schema.
- #description ⇒ Object
- #format ⇒ Object
- #if ⇒ Object
- #in ⇒ Object
-
#initialize(name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #match ⇒ Object
- #method ⇒ Object
- #native_type ⇒ Object
- #null ⇒ Object
- #of ⇒ Object
- #options ⇒ Object
- #private ⇒ Object
- #required ⇒ Object
-
#serializable? ⇒ Boolean
Should not be listed in schema or serialize this attribute.
- #spec ⇒ Object
- #spec_uri ⇒ Object
- #type ⇒ Object
- #unless ⇒ Object
- #value(value) ⇒ Object
Methods included from Validators::Validatable
Methods included from Validators::Normalizable
Methods included from Serializers::Serializable
Methods included from Bluepine::Assertions
#assert, #assert_in, #assert_kind_of, #assert_not, #assert_subset_of, included
Constructor Details
#initialize(name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
18 19 20 21 |
# File 'lib/bluepine/attributes/attribute.rb', line 18 def initialize(name, = {}) @name = name @options = self.class..merge() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/bluepine/attributes/attribute.rb', line 13 def name @name end |
Instance Method Details
#attributes ⇒ Object
95 96 97 |
# File 'lib/bluepine/attributes/attribute.rb', line 95 def attributes {} end |
#default ⇒ Object
112 113 114 |
# File 'lib/bluepine/attributes/attribute.rb', line 112 def default @options[:default] end |
#deprecated ⇒ Object
deprecated attribute should be listed in schema
100 101 102 |
# File 'lib/bluepine/attributes/attribute.rb', line 100 def deprecated @options.fetch(:deprecated, false) end |
#description ⇒ Object
116 117 118 |
# File 'lib/bluepine/attributes/attribute.rb', line 116 def description @options[:description] end |
#format ⇒ Object
83 84 85 |
# File 'lib/bluepine/attributes/attribute.rb', line 83 def format @options[:format] end |
#if ⇒ Object
67 68 69 |
# File 'lib/bluepine/attributes/attribute.rb', line 67 def if @options[:if] end |
#in ⇒ Object
63 64 65 |
# File 'lib/bluepine/attributes/attribute.rb', line 63 def in @options[:in] end |
#match ⇒ Object
51 52 53 |
# File 'lib/bluepine/attributes/attribute.rb', line 51 def match @options[:match] end |
#method ⇒ Object
55 56 57 |
# File 'lib/bluepine/attributes/attribute.rb', line 55 def method @options[:method] || @name end |
#native_type ⇒ Object
79 80 81 |
# File 'lib/bluepine/attributes/attribute.rb', line 79 def native_type type end |
#null ⇒ Object
75 76 77 |
# File 'lib/bluepine/attributes/attribute.rb', line 75 def null @options.fetch(:null, false) end |
#of ⇒ Object
59 60 61 |
# File 'lib/bluepine/attributes/attribute.rb', line 59 def of @options[:of] end |
#options ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bluepine/attributes/attribute.rb', line 23 def @options.merge({ name: @name, match: match, method: method, type: type, native_type: native_type, of: of, in: send(:in), if: @options[:if], unless: @options[:unless], null: null, spec: spec, spec_uri: spec_uri, format: format, private: private, deprecated: deprecated, required: required, default: default, description: description, attributes: attributes.values&.map(&:options), }) end |
#private ⇒ Object
104 105 106 |
# File 'lib/bluepine/attributes/attribute.rb', line 104 def private @options.fetch(:private, false) end |
#required ⇒ Object
108 109 110 |
# File 'lib/bluepine/attributes/attribute.rb', line 108 def required @options.fetch(:required, false) end |
#serializable? ⇒ Boolean
Should not be listed in schema or serialize this attribute
121 122 123 |
# File 'lib/bluepine/attributes/attribute.rb', line 121 def serializable? !private end |
#spec ⇒ Object
87 88 89 |
# File 'lib/bluepine/attributes/attribute.rb', line 87 def spec nil end |
#spec_uri ⇒ Object
91 92 93 |
# File 'lib/bluepine/attributes/attribute.rb', line 91 def spec_uri nil end |
#type ⇒ Object
47 48 49 |
# File 'lib/bluepine/attributes/attribute.rb', line 47 def type self.class.name.demodulize.chomp("Attribute").underscore end |
#unless ⇒ Object
71 72 73 |
# File 'lib/bluepine/attributes/attribute.rb', line 71 def unless @options[:unless] end |
#value(value) ⇒ Object
125 126 127 |
# File 'lib/bluepine/attributes/attribute.rb', line 125 def value(value) value.nil? ? default : value end |