Class: Sutty::Cli::Commands::Post
- Inherits:
-
Sutty::Cli::Command
- Object
- Sutty::Cli::Command
- Sutty::Cli::Commands::Post
- Defined in:
- lib/sutty/cli/commands/post.rb
Constant Summary collapse
- CONTENT_FIELDS =
%w[content markdown_content].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(options) ⇒ Post
constructor
A new instance of Post.
Methods inherited from Sutty::Cli::Command
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(options) ⇒ Post
Returns a new instance of Post.
19 20 21 22 |
# File 'lib/sutty/cli/commands/post.rb', line 19 def initialize() @options = .to_h @options['title'] ||= random_string(10) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/sutty/cli/commands/post.rb', line 15 def @options end |
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sutty/cli/commands/post.rb', line 24 def execute(input: $stdin, output: $stdout) if File.exist? path logger.info "The file #{path} already exists" return true end TTY::File.create_file path, YAML.dump(data) + "---\n\n" + (content? ? random_markdown : '') end |