Module: Repositorish::ClassMethods

Defined in:
lib/repositorish.rb

Overview

:nodoc:

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



93
94
95
96
97
98
# File 'lib/repositorish.rb', line 93

def method_missing(method, *args, &block)
  return query.public_send(method, *args, &block) if method_defined?(method)

  fail DomainMethodError, method if @domain.respond_to?(method)
  super
end

Instance Method Details

#create(model, *args, &block) ⇒ Object



71
72
73
74
75
# File 'lib/repositorish.rb', line 71

def create(model, *args, &block)
  return false if model.persisted?

  model.save(*args, &block)
end

#destroy(model) ⇒ Object



83
84
85
86
87
# File 'lib/repositorish.rb', line 83

def destroy(model)
  return if model.new_record?

  model.destroy
end

#query(domain = @domain) ⇒ Object



89
90
91
# File 'lib/repositorish.rb', line 89

def query(domain = @domain)
  new(domain)
end

#repositorish(model, options = {}) ⇒ Object



65
66
67
68
69
# File 'lib/repositorish.rb', line 65

def repositorish(model, options = {})
  @domain = model.to_s.classify.constantize
  @domain = @domain.public_send(options[:scope]) if options[:scope]
  self
end

#update(model, *args, &block) ⇒ Object



77
78
79
80
81
# File 'lib/repositorish.rb', line 77

def update(model, *args, &block)
  return false if model.new_record?

  model.save(*args, &block)
end