Class: HookBridge::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/hookbridge/types.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, time_fields: [], date_fields: []) ⇒ BaseModel

Returns a new instance of BaseModel.



41
42
43
44
45
46
# File 'lib/hookbridge/types.rb', line 41

def initialize(data = {}, time_fields: [], date_fields: [])
  @attributes = {}
  (data || {}).each do |key, value|
    @attributes[key.to_s] = convert_value(key.to_s, value, time_fields, date_fields)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/hookbridge/types.rb', line 52

def method_missing(name, *args, &block)
  return super unless args.empty? && block.nil?

  key = name.to_s
  return @attributes[key] if @attributes.key?(key)

  super
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/hookbridge/types.rb', line 61

def respond_to_missing?(name, include_private = false)
  @attributes.key?(name.to_s) || super
end

#to_hObject



48
49
50
# File 'lib/hookbridge/types.rb', line 48

def to_h
  @attributes.transform_keys(&:to_sym)
end