Class: Sutty::Cli::Commands::Field
Constant Summary
collapse
- INVERSE_REQUIRED =
%w[has_many belongs_to has_and_belongs_to_many].freeze
- VALUE_REQUIRED =
%w[-F --filter].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(name, options) ⇒ Field
16
17
18
19
|
# File 'lib/sutty/cli/commands/field.rb', line 16
def initialize(name, options)
@name = name
@options = options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
11
12
13
|
# File 'lib/sutty/cli/commands/field.rb', line 11
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/sutty/cli/commands/field.rb', line 11
def options
@options
end
|
Class Method Details
.fields ⇒ Object
32
33
34
35
36
|
# File 'lib/sutty/cli/commands/field.rb', line 32
def self.fields
@@fields ||= Dir.glob(source_dir.to_s + '/*.yml.erb').map do |f|
File.basename f, '.yml.erb'
end
end
|
.inverse_required? ⇒ Boolean
38
39
40
|
# File 'lib/sutty/cli/commands/field.rb', line 38
def self.inverse_required?
ARGV.any? { |f| INVERSE_REQUIRED.include? f }
end
|
.value_required? ⇒ Boolean
42
43
44
|
# File 'lib/sutty/cli/commands/field.rb', line 42
def self.value_required?
ARGV.any? { |f| VALUE_REQUIRED.include? f }
end
|
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/sutty/cli/commands/field.rb', line 21
def execute(input: $stdin, output: $stdout)
unless data_layout_contents.scan(/\n#{name}:\n/).empty?
logger.info "The #{name} field is already present, please edit #{data_layout}"
return true
end
TTY::File.safe_append_to_file(data_layout) do
ERB.new(template_contents, trim_mode: '<>', eoutvar: '@output_buffer').result(context)
end
end
|