Class: Promiscuous::DSL::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(mode, model, options) ⇒ Definition

Returns a new instance of Definition.



15
16
17
18
19
20
21
22
23
# File 'lib/promiscuous/dsl.rb', line 15

def initialize(mode, model, options)
  @mode = mode
  @model = model
  @options = options
  @model_class = @model.to_s.singularize.classify.constantize

  promiscuous_include = mode == :publish ? Promiscuous::Publisher : Promiscuous::Subscriber
  @model_class.class_eval { include promiscuous_include }
end

Instance Method Details

#attributes(*fields) ⇒ Object Also known as: attribute



25
26
27
28
# File 'lib/promiscuous/dsl.rb', line 25

def attributes(*fields)
  options = fields.extract_options!
  @model_class.__send__(@mode, *fields, @options.merge(options))
end

#track_dependencies_of(field) ⇒ Object



30
31
32
# File 'lib/promiscuous/dsl.rb', line 30

def track_dependencies_of(field)
  @model_class.track_dependencies_of(field)
end