Methods
A
C
D
F
I
P
R
U
W
Instance Public methods
automatic_properties()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
56 def automatic_properties
57   [identifier_property]
58 end
creatable_properties()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
22 def creatable_properties
23   writeable_properties
24 end
describe_property(property)
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
30 def describe_property(property) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
31   name = property_name(property).to_s
32   {
33     "x-rhino-attribute": {
34       name: name,
35       readableName: name.titleize,
36       readable: read_properties.include?(property),
37       creatable: create_properties.include?(property),
38       updatable: update_properties.include?(property)
39     },
40     readOnly: property_read_only?(name),
41     writeOnly: property_write_only?(name),
42     nullable: property_nullable?(name),
43     default: property_default(name)
44   }
45     .merge(property_type(property))
46     .merge(property_validations(property))
47     .compact
48 end
foreign_key_properties()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
60 def foreign_key_properties
61   # reflect_on_all_associations(:belongs_to).map(&:foreign_key).map(&:to_s)
62   []
63 end
identifier_property()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
10 def identifier_property
11   "id"
12 end
property_default(name)
    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
201 def property_default(name)
202   # FIXME: This will not handle datetime fields
203   # https://github.com/rails/rails/issues/27077 sets the default in the db
204   # but Blog.new does not set the default value like other attributes
205   # https://nubinary.atlassian.net/browse/NUB-298
206   _default_attributes[name].type_cast(_default_attributes[name].value_before_type_cast)
207 end
property_name(property)
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
89 def property_name(property)
90   property.is_a?(Hash) ? property.keys.first : property
91 end
property_nullable?(name)

If there is a presence validator in the model it is not nullable. if there is no optional: true on an association, rails will add a presence validator automatically Otherwise check the db for the actual column or foreign key setting Return nil instead of false for compaction

    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
173 def property_nullable?(name)
174   # Check for presence validator
175   if validators.select { |v| v.is_a? ::ActiveRecord::Validations::PresenceValidator }.flat_map(&:attributes).include?(name.to_sym)
176     return false
177   end
178 
179   # name = reflections[name].foreign_key if reflections.key?(name)
180 
181   # Check the column null setting
182   # return columns_hash[name].null if columns_hash.key?(name)
183 
184   true
185 end
property_read_only?(name)

Return nil instead of false for compaction

    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
188 def property_read_only?(name)
189   return unless read_properties.include?(name) && (create_properties.exclude?(name) && update_properties.exclude?(name))
190 
191   true
192 end
property_type(property)
    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
136 def property_type(property)
137   pt = property_type_raw(property)
138 
139   return pt if pt.is_a? Hash
140 
141   { type: property_type_raw(property) }
142 end
property_type_raw(property)
    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
102 def property_type_raw(property)
103   name = property_name(property)
104   return :identifier if name == identifier_property
105 
106   # return :string if defined_enums.key?(name)
107 
108   # FIXME: Hack for tags for now
109   # if attribute_types.key?(name.to_s) && attribute_types[name.to_s].class.to_s == 'ActsAsTaggableOn::Taggable::TagListType'
110   #   return {
111   #     type: :array,
112   #     items: {
113   #       type: 'string'
114   #     }
115   #   }
116   # end
117 
118   # Use the attribute type if possible
119   return attribute_types[name.to_s].type if attribute_types.key?(name.to_s)
120 
121   # if reflections.key?(name)
122   #   # FIXME: The tr hack is to match how model_name in rails handles modularized classes
123   #   class_name = reflections[name].options[:class_name]&.underscore&.tr('/', '_') || name
124   #   return ref_descriptor(class_name) unless reflections[name].macro == :has_many
125   #
126   #   return {
127   #     type: :array,
128   #     items: ref_descriptor(class_name)
129   #   }
130   # end
131 
132   # raise UnknownpropertyType
133   "unknown"
134 end
property_validations(property)
    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
144 def property_validations(property) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
145   constraint_hash = {}
146 
147   # https://swagger.io/specification/
148 
149   validators_on(property).each do |v|
150     if v.is_a? ActiveModel::Validations::NumericalityValidator
151       constraint_hash[:minimum] = v.options[:greater_than] + 1
152       constraint_hash[:maximum] = v.options[:less_than] - 1
153     end
154 
155     if v.is_a? ::ActiveRecord::Validations::LengthValidator
156       constraint_hash[:minLength] = v.options[:minimum] || v.options[:is]
157       constraint_hash[:maxLength] = v.options[:maximum] || v.options[:is]
158     end
159 
160     constraint_hash[:pattern] = JsRegex.new(v.options[:with]).source if v.is_a? ::ActiveModel::Validations::FormatValidator
161 
162     constraint_hash[:enum] = v.options[:in] if v.is_a? ActiveModel::Validations::InclusionValidator
163   end
164 
165   constraint_hash.compact
166 end
property_write_only?(name)

Return nil instead of false for compaction

    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
195 def property_write_only?(name)
196   return unless (create_properties.include?(name) || update_properties.include?(name)) && read_properties.exclude?(name)
197 
198   true
199 end
readable_properties()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
14 def readable_properties
15   props = attribute_names - foreign_key_properties
16 
17   props.concat(reference_properties)
18 
19   props.map(&:to_s)
20 end
ref_descriptor(name)
    # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
 93 def ref_descriptor(name)
 94   {
 95     type: :reference,
 96     anyOf: [
 97       { "$ref".to_sym => "#/components/schemas/#{name.singularize}" }
 98     ]
 99   }
100 end
reference_properties(read = true)
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
65 def reference_properties(read = true) # rubocop:todo Style/OptionalBooleanParameter
66   references.map do |r|
67     sym = reference_to_sym(r)
68 
69     # All references are readable
70     next sym if read
71 
72     # Writeable if a one type or accepting nested
73     association = reflect_on_association(sym)
74     # rubocop:todo Performance/CollectionLiteralInLoop
75     sym if %i[has_one belongs_to].include?(association.macro) || nested_attributes_options.key?(sym)
76     # rubocop:enable Performance/CollectionLiteralInLoop
77   end.compact
78 end
reference_to_sym(reference)

FIXME: Duplicated in params.rb

   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
52 def reference_to_sym(reference)
53   reference.is_a?(Hash) ? reference.keys.first : reference
54 end
updatable_properties()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
26 def updatable_properties
27   writeable_properties
28 end
writeable_properties()
   # File rhino/rhino/lib/rhino/resource/active_model_extension/properties.rb
80 def writeable_properties
81   # Direct properties for this model
82   props = attribute_names - automatic_properties - foreign_key_properties
83 
84   props.concat(reference_properties(false))
85 
86   props.map(&:to_s)
87 end