Class: Jeny::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jeny/configuration.rb

Constant Summary collapse

DEFAULT_EDIT_PROC =
->(_,content) {
  content =~ /TODO/
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jeny/configuration.rb', line 8

def initialize
  @jeny_block_delimiter = "(#|\/\/)jeny"
  @ignore_pattern = /^(vendor|\.bundle|.min.js|.min.css)/
  @editor_command = default_editor_command
  @edit_changed_files = DEFAULT_EDIT_PROC
  @state_manager = default_state_manager
  @state_manager_options = {
    stash: true,
    commit: true
  }
  yield(self) if block_given?
end

Instance Attribute Details

#edit_changed_filesObject Also known as: edit_changed_files?

Whether files generated/modified must be edited right after.

Accepted values are:

  • ‘false`, then source code edition is disabled

  • ‘true`, then all files are open after being snipetted

  • ‘/…/`, then only files whose name match the regexp are open

  • ‘->(f,c){}`, the file `f` whose generated content is `c` is open is the proc returns a truthy value.

Defaults to a Proc that opens files having at least one TODO.



99
100
101
# File 'lib/jeny/configuration.rb', line 99

def edit_changed_files
  @edit_changed_files
end

#editor_commandObject

Shell command to open the source code editor.

Default value checks the JENY_EDITOR, GIT_EDITOR, EDITOR environment variables, and fallbacks to “code”.



36
37
38
# File 'lib/jeny/configuration.rb', line 36

def editor_command
  @editor_command
end

#ignore_patternObject

Regular expression matching files that can always be ignored by Snippets.

Defaults to /^(vendor|.bundle)/



30
31
32
# File 'lib/jeny/configuration.rb', line 30

def ignore_pattern
  @ignore_pattern
end

#jeny_block_delimiterObject

The delimiter used for jeny block in source code files.

Defaults to ‘#jeny`



25
26
27
# File 'lib/jeny/configuration.rb', line 25

def jeny_block_delimiter
  @jeny_block_delimiter
end

#jeny_fileObject

Returns the value of attribute jeny_file.



20
21
22
# File 'lib/jeny/configuration.rb', line 20

def jeny_file
  @jeny_file
end

#state_managerObject

State manager to use.

Default value check the JENY_STATE_MANAGER environment variable:

  • ‘none`, no state management is done

  • ‘git`, git is used to stash/unstash/commit/reset

Defaults to ‘none`, that is, to an empty state manager.



49
50
51
# File 'lib/jeny/configuration.rb', line 49

def state_manager
  @state_manager
end

#state_manager_optionsObject

Options for the state manager.

This is a Hash, with ‘:stash` and `:commit` keys mapping to either true of false.

Both are true by default.



57
58
59
# File 'lib/jeny/configuration.rb', line 57

def state_manager_options
  @state_manager_options
end

Instance Method Details

#default_editor_commandObject



38
39
40
# File 'lib/jeny/configuration.rb', line 38

def default_editor_command
  ENV['JENY_EDITOR'] || ENV['GIT_EDITOR'] || ENV['EDITOR']
end

#default_state_managerObject



80
81
82
83
84
85
86
87
# File 'lib/jeny/configuration.rb', line 80

def default_state_manager
  case ENV['JENY_STATE_MANAGER']
  when "git"
    StateManager::Git.new(self)
  else
    StateManager.new(self)
  end
end

#ignore_file?(file) ⇒ Boolean

Should ‘file` be ignored?

Returns:

  • (Boolean)


104
105
106
107
# File 'lib/jeny/configuration.rb', line 104

def ignore_file?(file)
  file = Command::Support.simplify_path(file)
  file.to_s =~ ignore_pattern
end

#open_editor(files) ⇒ Object



124
125
126
127
128
129
# File 'lib/jeny/configuration.rb', line 124

def open_editor(files)
  unless editor_command
    raise Error, "source code editor is not enabled"
  end
  fork{ exec(editor_command + " " + files.join(" ")) }
end

#should_be_edited?(file, content) ⇒ Boolean

Whether file should be edited after being snippetted

Returns:

  • (Boolean)


110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/jeny/configuration.rb', line 110

def should_be_edited?(file, content)
  return false if editor_command.nil?
  case edit_changed_files
  when false, true, nil
    !!edit_changed_files
  when Regexp
    !!(file.to_s =~ edit_changed_files)
  when Proc
    !!edit_changed_files.call(file, content)
  else
    raise Error, "Wrong edit_changed_files `#{edit_changed_files}`"
  end
end

#sm_commit?Boolean

:nodoc:

Returns:

  • (Boolean)


65
66
67
# File 'lib/jeny/configuration.rb', line 65

def sm_commit?
  state_manager_options[:commit]
end

#sm_stash?Boolean

:nodoc:

Returns:

  • (Boolean)


60
61
62
# File 'lib/jeny/configuration.rb', line 60

def sm_stash?
  state_manager_options[:stash]
end