Class: Makers::Maker

Inherits:
Object
  • Object
show all
Defined in:
lib/makers/maker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, model, assignments, associations, sequences, options) ⇒ Maker

Returns a new instance of Maker.



7
8
9
10
11
12
13
14
# File 'lib/makers/maker.rb', line 7

def initialize(name, model, assignments, associations, sequences, options)
  @name = name
  @model = model
  @assignments = assignments
  @associations = associations
  @sequences = sequences
  @options = options
end

Instance Attribute Details

#assignmentsObject (readonly)

Returns the value of attribute assignments.



4
5
6
# File 'lib/makers/maker.rb', line 4

def assignments
  @assignments
end

#associationsObject (readonly)

Returns the value of attribute associations.



4
5
6
# File 'lib/makers/maker.rb', line 4

def associations
  @associations
end

#disabled_associationObject

Returns the value of attribute disabled_association.



5
6
7
# File 'lib/makers/maker.rb', line 5

def disabled_association
  @disabled_association
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/makers/maker.rb', line 4

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/makers/maker.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/makers/maker.rb', line 4

def options
  @options
end

#sequencesObject (readonly)

Returns the value of attribute sequences.



4
5
6
# File 'lib/makers/maker.rb', line 4

def sequences
  @sequences
end

Instance Method Details

#attributesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/makers/maker.rb', line 32

def attributes
  all = assignments.dup
  if options.has_key?(:parent)
    all.reverse_merge! Makers.definitions.find(options[:parent]).assignments
  end
  if disabled_association
    associations.each do |name, class_name|
      if disabled_association == class_name
        all[name] = -> { nil }
      end
    end
  end
  object = Object.new
  all.each do |name, block|
    object.define_singleton_method name, &block
  end
  hash = {}
  all.keys.each do |name|
    hash[name] = object.send(name)
  end
  hash
end