Class: SixSaferpay::Generators::Model

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/generators/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/generators/models.rb', line 9

def attributes
  @attributes
end

#file_nameObject

Returns the value of attribute file_name.



9
10
11
# File 'lib/generators/models.rb', line 9

def file_name
  @file_name
end

Class Method Details

.source_rootObject



15
16
17
# File 'lib/generators/models.rb', line 15

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#create_attributes_arrayObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/models.rb', line 23

def create_attributes_array
  @attributes = []
  if method_attributes
    method_attributes.each do |key, value|
      split = value.split(':')

      name = key.underscore
      type = split.first
      if split.length == 2
        mandatory = split.last
      else
        mandatory = false
      end

      attribute = Attribute.new(name, type, mandatory)

      @attributes << attribute
    end
  end
end

#create_fabric_fileObject



52
53
54
# File 'lib/generators/models.rb', line 52

def create_fabric_file
  template('templates/fabric.erb', "spec/fabrics/six_saferpay/models/#{@file_name.pluralize}.rb")
end

#create_model_fileObject



44
45
46
# File 'lib/generators/models.rb', line 44

def create_model_file
  template('templates/model.erb', "lib/six_saferpay/models/#{@file_name}.rb")
end

#create_test_fileObject



48
49
50
# File 'lib/generators/models.rb', line 48

def create_test_file
  template('templates/spec.erb', "spec/six_saferpay/models/#{@file_name}_spec.rb")
end