Module: Schema

Included in:
Controls::Schema::Boolean::Example, Controls::Schema::DefaultValue::Example, Controls::Schema::DefaultValue::ObjectReference, Controls::Schema::DefaultValue::Primitive, Controls::Schema::DefaultValue::Proc, Controls::Schema::Duplicate::Example, Controls::Schema::Equivalent::Example, Controls::Schema::TransientAttributes::Example, Controls::Schema::Typed::Example, Controls::Schema::Typed::Strict::Example, Controls::Schema::Validation::Example
Defined in:
lib/schema/schema.rb,
lib/schema/data_structure.rb,
lib/schema/schema/compare.rb,
lib/schema/controls/random.rb,
lib/schema/controls/schema.rb,
lib/schema/schema/attribute.rb,
lib/schema/validation/error.rb,
lib/schema/controls/attribute.rb,
lib/schema/controls/comparison.rb,
lib/schema/controls/data_structure.rb,
lib/schema/controls/comparison/entry.rb,
lib/schema/controls/schema/different.rb,
lib/schema/schema/compare/comparison.rb,
lib/schema/validation/nil_attributes.rb,
lib/schema/schema/compare/comparison/entry.rb

Defined Under Namespace

Modules: AttributeMacro, Attributes, Boolean, Compare, Controls, DataStructure, Info, Validation Classes: Attribute, AttributeRegistry, Error

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(cls) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/schema/schema.rb', line 4

def self.included(cls)
  cls.class_exec do
    extend Info
    extend AttributeMacro
    extend Attributes

    include Virtual

    virtual :transform_write do |data|
      transform_out(data)
    end
    virtual :transform_out

    const_set(:Boolean, Boolean)
  end
end

Instance Method Details

#==(other, attributes_names = nil, ignore_class: nil) ⇒ Object Also known as: eql?



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/schema/schema.rb', line 186

def ==(other, attributes_names=nil, ignore_class: nil)
  ignore_class ||= false

  if not ignore_class
    return false if self.class != other.class
  end

  comparison = Compare.(self, other, attributes_names)

  different = comparison.different?(ignore_class: ignore_class)

  !different
end

#all_attributesObject



182
183
184
# File 'lib/schema/schema.rb', line 182

def all_attributes
  attributes(include_transient: true)
end

#attributes(include_transient: nil) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/schema/schema.rb', line 164

def attributes(include_transient: nil)
  include_transient ||= false

  attribute_names = self.class.attribute_names(include_transient: include_transient)

  data = attribute_names.each_with_object({}) do |attribute_name, attributes|
    attributes[attribute_name] = public_send(attribute_name)
  end

  transform_write(data)

  data
end

#to_hObject



178
179
180
# File 'lib/schema/schema.rb', line 178

def to_h
  attributes
end