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?



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/schema/schema.rb', line 199

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



195
196
197
# File 'lib/schema/schema.rb', line 195

def all_attributes
  attributes(include_transient: true)
end

#attributes(include_transient: nil) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/schema/schema.rb', line 179

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

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

  data = get_attributes(attribute_names)

  transform_write(data)

  data
end

#get_attributes(attribute_names) ⇒ Object



173
174
175
176
177
# File 'lib/schema/schema.rb', line 173

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

#hashObject



214
215
216
# File 'lib/schema/schema.rb', line 214

def hash
  [self.class, raw_attributes].hash
end

#raw_attributesObject



168
169
170
171
# File 'lib/schema/schema.rb', line 168

def raw_attributes
  all_attribute_names = self.class.all_attribute_names
  get_attributes(all_attribute_names)
end

#to_hObject



191
192
193
# File 'lib/schema/schema.rb', line 191

def to_h
  attributes
end