Module: Hook::Model::ClassMethods

Defined in:
lib/hook-client/model.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



108
109
110
111
# File 'lib/hook-client/model.rb', line 108

def method_missing(m, *args, &block)
  instance = self.new
  instance.send(m, *args, &block)
end

Instance Method Details

#collection_name(name = nil) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/hook-client/model.rb', line 84

def collection_name(name = nil)
  if name
    @collection_name = name
  else
    @collection_name = ActiveModel::Naming.route_key(self)
  end
end

#field(name, options = {}) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/hook-client/model.rb', line 92

def field name, options = {}
  define_attribute_method name

  # Define getter
  define_method name do
    # self.instance_variable_get("@#{name}")
    attributes[name]
  end

  # Define setter
  define_method "#{name}=" do |value|
    self.send(:"#{name}_will_change!")
    attributes[name] = value
  end
end