Module: Subly

Defined in:
lib/subly.rb,
lib/subly/model.rb,
lib/subly/version.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: Model

Constant Summary collapse

VERSION =
"0.3.0"

Instance Method Summary collapse

Instance Method Details

#subly(args = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/subly.rb', line 5

def subly(args = {})
  self.has_many :sublies, :as => :subscriber, :class_name => 'Subly::Model'
  self.accepts_nested_attributes_for :sublies, :allow_destroy => true, :reject_if => :all_blank

  #we don't want to use method missing for all "is" methods
  if is_methods = args.delete(:is_methods)
    is_methods.collect(&:to_s).each do |is_name|
      if self.instance_methods.include?(is_name)
        warn("Subly: Method is_#{is_name}? is already available to #{self.class.to_s}")
      else
        self.class_eval <<-EOV
          def is_#{is_name}?
            self.has_active_subscription?('#{is_name}')
          end
        EOV
      end
    end
  end

  extend ClassMethods
  include InstanceMethods
end