Class: Ymodel::Schema

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/ymodel/schema.rb

Overview

Represents a schema of all keys found in the source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, *keys) ⇒ Schema

Returns a new instance of Schema.



14
15
16
17
18
# File 'lib/ymodel/schema.rb', line 14

def initialize(source, *keys)
  @attributes = source.flat_map(&:keys)
      .map(&:to_sym)
      .to_set + keys
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



10
11
12
# File 'lib/ymodel/schema.rb', line 10

def attributes
  @attributes
end

Instance Method Details

#<<(attribute) ⇒ Object



24
25
26
# File 'lib/ymodel/schema.rb', line 24

def <<(attribute)
  @attributes << attribute.to_sym
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ymodel/schema.rb', line 20

def include?(key)
  attributes.include?(key.to_sym)
end