Module: Boundary::Model

Defined in:
lib/boundary/model.rb

Instance Method Summary collapse

Instance Method Details

#bound_by(scope, *args) ⇒ Object

Adds a scope helper for the specified scope (ie: company)

Options:

  • :foreign_id - Foreign ID column name (default: :company_id)

bound_by :account, :foreign_id => :employee_id

Subscription.bound_by_account(account_id) { query }



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/boundary/model.rb', line 11

def bound_by(scope, *args)
  options = args.extract_options!

  options[:foreign_id]  ||= :company_id

  self.class_eval "      def self.bound_by_\#{scope}(foreign_id, *args)\n        self.where(:\#{options[:foreign_id]} => foreign_id).scoping do\n          yield if block_given?\n        end\n      end\n  end_eval\nend\n", __FILE__, __LINE__