Class: Lesli::ApplicationLesliGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/application_lesli_generator.rb

Direct Known Subclasses

SpecGenerator

Instance Method Summary collapse

Instance Method Details

#parse_infoObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/generators/application_lesli_generator.rb', line 77

def parse_info 

    engine, resource = name.split("/")

    # engine information 
    engine_code = engine.underscore

    # resource information 
    resource_code = resource.underscore

    @info = {
        :engine => engine,
        :engine_code => engine_code,
        
        :resource => resource,
        :resource_code => resource_code,

        :engine_resource => "#{engine}::#{resource}",
        :engine_resource_code => "#{engine_code}_#{resource_code}"
    }
end

#parse_modelObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/generators/application_lesli_generator.rb', line 99

def parse_model 

    tabla = "#{@info[:engine_resource]}".constantize
    .columns.map do |column| 

        if column.type == :string
            value = '""' 
            faker = "Faker::String.random"
        end

        if column.type == :integer
            value = 1 
            faker = "Faker::Number.digit"
        end

        if column.type == :datetime
            value = "'#{Time.now}'" 
            faker = 'Faker::Date.between(from: 2.days.ago, to: Date.today)'
        end

        { 
            :name => column.name, 
            :type => column.type,
            :null => column.null,
            :value => value,
            :faker => faker
        }
    end

    @model = {
        :name => @info[:engine_resource],
        :columns => tabla
    }
end