Module: Fixjour::Definitions

Included in:
Fixjour
Defined in:
lib/fixjour/definitions.rb

Instance Method Summary collapse

Instance Method Details

#define_create(name) ⇒ Object

Defines the create_* method



11
12
13
14
15
16
17
# File 'lib/fixjour/definitions.rb', line 11

def define_create(name)
  define_method("create_#{name}") do |*args|
    model = send("new_#{name}", *args)
    model.save!
    model
  end
end

#define_new(klass, &block) ⇒ Object

Defines the new_* method



4
5
6
7
8
# File 'lib/fixjour/definitions.rb', line 4

def define_new(klass, &block)
  define_method("new_#{name_for(klass)}") do |*args|
    Generator.new(klass, block).call(self, args.extract_options!.symbolize_keys!)
  end
end

#define_valid_attributes(name, options) ⇒ Object

Defines the valid_*_attributes method



20
21
22
23
24
# File 'lib/fixjour/definitions.rb', line 20

def define_valid_attributes(name, options)
  define_method("valid_#{name}_attributes") do |*args|
    Attributes.new(options.empty?? send("new_#{name}", *args).attributes : options)
  end
end