Module: Schema
- Included in:
- Controls::Schema::Boolean::Example, Controls::Schema::DefaultValue::Example, Controls::Schema::DefaultValue::Proc::Example, Controls::Schema::Duplicate::Example, Controls::Schema::Equivalent::Example, Controls::Schema::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/controls/schema.rb,
lib/schema/schema/attribute.rb,
lib/schema/validation/error.rb,
lib/schema/schema/assertions.rb,
lib/schema/controls/data_structure.rb,
lib/schema/validation/nil_attributes.rb
Defined Under Namespace
Modules: Assertions, AttributeMacro, Attributes, Boolean, Controls, DataStructure, 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
|
# File 'lib/schema/schema.rb', line 4
def self.included(cls)
cls.class_exec do
extend AttributeMacro
extend Attributes
const_set(:Boolean, Boolean)
end
end
|
Instance Method Details
#==(other, attributes = nil, ignore_class: nil) ⇒ Object
Also known as:
eql?
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/schema/schema.rb', line 153
def ==(other, attributes=nil, ignore_class: nil)
attributes ||= self.class.attribute_names
attributes = Array(attributes)
ignore_class = false if ignore_class.nil?
if !ignore_class
return false if self.class != other.class
end
attributes.each do |attribute|
if attribute.is_a? Hash
this_attribute, other_attribute = attribute.keys.first, attribute.values.first
else
this_attribute, other_attribute = attribute, attribute
end
return false if public_send(this_attribute) != other.public_send(other_attribute)
end
true
end
|
#===(other) ⇒ Object
177
178
179
|
# File 'lib/schema/schema.rb', line 177
def ===(other)
self.eql?(other, ignore_class: true)
end
|
#attributes ⇒ Object
Also known as:
to_h
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/schema/schema.rb', line 140
def attributes
transient_attributes = []
if self.class.respond_to?(:transient_attributes)
transient_attributes = self.class.transient_attributes
end
self.class.attributes.each_with_object({}) do |attribute, attributes|
next if transient_attributes.include?(attribute.name)
attributes[attribute.name] = public_send(attribute.name)
end
end
|