Class: AnimateIt::PropsSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/animate_it/props_schema.rb

Defined Under Namespace

Classes: Field

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePropsSchema

Returns a new instance of PropsSchema.



7
8
9
# File 'lib/animate_it/props_schema.rb', line 7

def initialize
  @fields = []
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



5
6
7
# File 'lib/animate_it/props_schema.rb', line 5

def fields
  @fields
end

Instance Method Details

#asset(name, default: nil) ⇒ Object



19
20
21
# File 'lib/animate_it/props_schema.rb', line 19

def asset(name, default: nil, **)
  field(name, :asset, default:, **)
end

#boolean(name, default: nil) ⇒ Object



31
32
33
# File 'lib/animate_it/props_schema.rb', line 31

def boolean(name, default: nil, **)
  field(name, :boolean, default:, **)
end

#color(name, default: nil) ⇒ Object



15
16
17
# File 'lib/animate_it/props_schema.rb', line 15

def color(name, default: nil, **)
  field(name, :color, default:, **)
end

#defaultsObject



35
36
37
# File 'lib/animate_it/props_schema.rb', line 35

def defaults
  fields.to_h { |field| [field.name, field.default] }
end

#integer(name, default: nil) ⇒ Object



23
24
25
# File 'lib/animate_it/props_schema.rb', line 23

def integer(name, default: nil, **)
  field(name, :integer, default:, **)
end

#number(name, default: nil) ⇒ Object



27
28
29
# File 'lib/animate_it/props_schema.rb', line 27

def number(name, default: nil, **)
  field(name, :number, default:, **)
end

#resolve(input) ⇒ Object



39
40
41
# File 'lib/animate_it/props_schema.rb', line 39

def resolve(input)
  defaults.merge(input.transform_keys(&:to_sym))
end

#string(name, default: nil) ⇒ Object



11
12
13
# File 'lib/animate_it/props_schema.rb', line 11

def string(name, default: nil, **)
  field(name, :string, default:, **)
end