Class: Sutty::Cli::Commands::Field
- Inherits:
-
Sutty::Cli::Command
- Object
- Sutty::Cli::Command
- Sutty::Cli::Commands::Field
- Defined in:
- lib/sutty/cli/commands/field.rb
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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(name, options) ⇒ Field
constructor
A new instance of Field.
Methods inherited from Sutty::Cli::Command
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(name, options) ⇒ Field
Returns a new instance of Field.
16 17 18 19 |
# File 'lib/sutty/cli/commands/field.rb', line 16 def initialize(name, ) @name = name @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/sutty/cli/commands/field.rb', line 11 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/sutty/cli/commands/field.rb', line 11 def @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 |