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



29
30
31
32
33
# File 'lib/smooth_operator/model_schema.rb', line 29

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



22
23
24
25
26
# File 'lib/smooth_operator/model_schema.rb', line 22

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



42
43
44
# File 'lib/smooth_operator/model_schema.rb', line 42

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

#known_attributesObject



46
47
48
# File 'lib/smooth_operator/model_schema.rb', line 46

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

#model_nameObject



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

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



60
61
62
# File 'lib/smooth_operator/model_schema.rb', line 60

def model_name=(name)
  @_model_name = name
end

#schema(structure) ⇒ Object



36
37
38
39
40
# File 'lib/smooth_operator/model_schema.rb', line 36

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

  known_attributes.merge internal_structure.keys
end