Module: Steem::Serializable::ClassMethods

Defined in:
lib/steem/mixins/serializable.rb

Instance Method Summary collapse

Instance Method Details

#add_type(name, type) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/steem/mixins/serializable.rb', line 23

def add_type name, type
  name = name.to_sym
  type = type.to_sym
  raise "Unknown type: #{type}" unless KNOWN_TYPES.include? type
  
  @serializable_types ||= {}
  @serializable_types[name] = type
end

#def_attr(key_pair) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/steem/mixins/serializable.rb', line 12

def def_attr key_pair
  name = key_pair.keys.first.to_sym
  type = key_pair.values.first.to_sym
  
  self.attributes ||= []
  self.attributes << name
  
  attr_accessor *attributes
  add_type name, type
end

#numeric?(name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/steem/mixins/serializable.rb', line 32

def numeric?(name)
  NUMERIC_TYPES.include? @serializable_types[name.to_sym]
end

#serializable_typesObject



36
37
38
# File 'lib/steem/mixins/serializable.rb', line 36

def serializable_types
  @serializable_types
end