Class: Airview::ResourceSynchronizer
- Inherits:
-
Object
- Object
- Airview::ResourceSynchronizer
- Defined in:
- lib/airview/resource_synchronizer.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
-
#initialize(definition) ⇒ ResourceSynchronizer
constructor
A new instance of ResourceSynchronizer.
- #sync_missing_fields ⇒ Object
Constructor Details
#initialize(definition) ⇒ ResourceSynchronizer
Returns a new instance of ResourceSynchronizer.
7 8 9 |
# File 'lib/airview/resource_synchronizer.rb', line 7 def initialize(definition) @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
5 6 7 |
# File 'lib/airview/resource_synchronizer.rb', line 5 def definition @definition end |
Instance Method Details
#sync_missing_fields ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/airview/resource_synchronizer.rb', line 11 def sync_missing_fields existing_names = definition.field_definitions.map { |field| field.name.to_s } position = definition.field_definitions.map(&:position).compact.max.to_i added_count = 0 SchemaInference.new(definition.model_class).field_attributes.each do |attributes| next if existing_names.include?(attributes[:name].to_s) position += 1 definition.field_definitions.create!( attributes.merge(position:, read_only: attributes[:read_only] ? true : false) ) added_count += 1 end added_count end |