Module: Cloudflair::Entity::ClassMethods
- Defined in:
- lib/cloudflair/entity.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#array_object_fields(*fields_to_class_map) ⇒ Object
allowed values:
array_object_fields :field_a, :field_b, :field_c, 'fieldname_as_string' # next is ame as previous array_object_fields field_a: nil, field_b: nil, field_c: nil, 'fieldname_as_string': nil # next defines the types of the objects array_object_fields field_a: Klass, field_b: proc { |data| Klass.new data }, field_c: nil, 'fieldname_as_string'
. - #deletable(deletable = false) ⇒ Object
- #object_fields(*fields) ⇒ Object
- #patchable_fields(*fields) ⇒ Object
- #path(path = nil) ⇒ Object
- #turn_all_items_into_a_single_hash(fields_to_class_map) ⇒ Object
Class Method Details
.extended(other_klass) ⇒ Object
14 15 16 |
# File 'lib/cloudflair/entity.rb', line 14 def self.extended(other_klass) @other_klass = other_klass end |
Instance Method Details
#array_object_fields(*fields_to_class_map) ⇒ Object
allowed values: array_object_fields :field_a, :field_b, :field_c, 'fieldname_as_string' # next is ame as previous array_object_fields field_a: nil, field_b: nil, field_c: nil, 'fieldname_as_string': nil # next defines the types of the objects array_object_fields field_a: Klass, field_b: proc { |data| Klass.new data }, field_c: nil, 'fieldname_as_string'
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cloudflair/entity.rb', line 64 def array_object_fields(*fields_to_class_map) return @array_object_fields if @array_object_fields if fields_to_class_map.nil? || fields_to_class_map.empty? @array_object_fields = {} else fields_map = turn_all_items_into_a_single_hash(fields_to_class_map) @array_object_fields = fields_map end end |
#deletable(deletable = false) ⇒ Object
31 32 33 34 35 |
# File 'lib/cloudflair/entity.rb', line 31 def deletable(deletable = false) return @deletable unless @deletable.nil? @deletable = deletable end |
#object_fields(*fields) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cloudflair/entity.rb', line 45 def object_fields(*fields) return @object_fields if @object_fields @object_fields = if fields.nil? || fields.empty? [] else fields.map(&:to_s) end end |
#patchable_fields(*fields) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cloudflair/entity.rb', line 18 def patchable_fields(*fields) return @patchable_fields if @patchable_fields @patchable_fields = if fields.nil? [] elsif fields.is_a?(Array) fields.map(&:to_s) else [fields.to_s] end end |
#path(path = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/cloudflair/entity.rb', line 37 def path(path = nil) return @path if @path raise ArgumentError, 'path is not defined' if path.nil? @path = path end |
#turn_all_items_into_a_single_hash(fields_to_class_map) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cloudflair/entity.rb', line 75 def turn_all_items_into_a_single_hash(fields_to_class_map) {}.tap do |fields_map| fields_to_class_map.each do |field_definition| if field_definition.is_a?(Hash) fields_to_class_map[0].each do |field, klass_or_proc| fields_map[field.to_s] = klass_or_proc end else fields_map[field_definition.to_s] = nil end end end end |