Module: SmoothOperator::ModelSchema::ClassMethods

Defined in:
lib/smooth_operator/model_schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resource_name(default_bypass = nil) ⇒ Object



27
28
29
30
31
# File 'lib/smooth_operator/model_schema.rb', line 27

def resource_name(default_bypass = nil)
  return @resource_name if defined?(@resource_name)

  (Helpers.super_method(self, :resource_name, true) || (default_bypass ? nil : self.model_name.to_s.underscore))
end

#resources_name(default_bypass = nil) ⇒ Object



20
21
22
23
24
# File 'lib/smooth_operator/model_schema.rb', line 20

def resources_name(default_bypass = nil)
  return @resources_name if defined?(@resources_name)

  (Helpers.super_method(self, :resources_name, true) || (default_bypass ? nil : self.resource_name.pluralize))
end

Instance Method Details

#internal_structureObject



40
41
42
# File 'lib/smooth_operator/model_schema.rb', line 40

def internal_structure
  Helpers.get_instance_variable(self, :internal_structure, { "errors" => nil })
end

#known_attributesObject



44
45
46
# File 'lib/smooth_operator/model_schema.rb', line 44

def known_attributes
  Helpers.get_instance_variable(self, :known_attributes, Set.new)
end

#model_nameObject



48
49
50
51
52
53
54
55
56
# File 'lib/smooth_operator/model_schema.rb', line 48

def model_name
  return '' if @_model_name == :none

  if defined? ActiveModel
    rails_model_name_method
  else
    @_model_name ||= name.split('::').last.underscore.capitalize
  end
end

#model_name=(name) ⇒ Object



58
59
60
# File 'lib/smooth_operator/model_schema.rb', line 58

def model_name=(name)
  @_model_name = name
end

#schema(structure) ⇒ Object



34
35
36
37
38
# File 'lib/smooth_operator/model_schema.rb', line 34

def schema(structure)
  internal_structure.merge! Helpers.stringify_keys(structure)

  known_attributes.merge internal_structure.keys
end