Class: Lanes::Command::GenerateModel
Constant Summary
collapse
- RESERVED_YAML_KEYWORDS =
%w(y yes n no true false on off null)
Instance Attribute Summary collapse
Attributes inherited from NamedCommand
#class_name, #client_dir, #namespace
Instance Method Summary
collapse
#load_namespace, source_root
Instance Attribute Details
#file_name ⇒ Object
Returns the value of attribute file_name.
18
19
20
|
# File 'lib/lanes/command/generate_model.rb', line 18
def file_name
@file_name
end
|
#table_name ⇒ Object
Returns the value of attribute table_name.
18
19
20
|
# File 'lib/lanes/command/generate_model.rb', line 18
def table_name
@table_name
end
|
Instance Method Details
#add_route ⇒ Object
50
51
52
53
54
|
# File 'lib/lanes/command/generate_model.rb', line 50
def add_route
insert_into_file "config/routes.rb", before: "end" do
" resources #{namespace.camelize}::#{class_name}\n"
end
end
|
#create_client ⇒ Object
43
44
45
46
47
48
|
# File 'lib/lanes/command/generate_model.rb', line 43
def create_client
template "client/data/Model.coffee", \
"#{client_dir}/data/#{class_name}.coffee"
template "spec/client/data/ModelSpec.coffee", \
"spec/client/data/#{class_name}Spec.coffee"
end
|
#create_migration ⇒ Object
31
32
33
34
35
|
# File 'lib/lanes/command/generate_model.rb', line 31
def create_migration
migration = exising_migration || Time.now.utc.strftime("%Y%m%d%H%M%S") + "_create_#{table_name}.rb"
self.fields = fields.map{ |field| ModelAttribute.parse(field) }
template "db/create_table_migration.rb", "db/migrate/#{migration}"
end
|
#create_model ⇒ Object
37
38
39
40
41
|
# File 'lib/lanes/command/generate_model.rb', line 37
def create_model
template "lib/namespace/model.rb", "lib/#{namespace}/#{file_name}.rb"
template "spec/namespace/model_spec.rb", "spec/#{namespace}/#{file_name}.rb"
template "spec/fixtures/namespace/model.yml", "spec/fixtures/#{namespace}/#{file_name}.yml"
end
|
#set_variables ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/lanes/command/generate_model.rb', line 20
def set_variables
super
if name=~/::/
(@namespace,@name) = name.split("::")
else
@namespace = computed_namespace
end
@file_name = name.underscore
@table_name = namespace + "_" + name.tableize
end
|