Class: Gloo::Objs::Git

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/dev/git.rb

Constant Summary collapse

KEYWORD =
'git_repo'.freeze
KEYWORD_SHORT =
'git'.freeze

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #msg_unload, #multiline_value?, #pn, #remove_child, #root?, #send_message, #set_parent, #set_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



42
43
44
# File 'lib/gloo/objs/dev/git.rb', line 42

def self.messages
  return super + %w[validate check_changes get_changes commit get_branch]
end

.short_typenameObject

The short name of the object type.



24
25
26
# File 'lib/gloo/objs/dev/git.rb', line 24

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



17
18
19
# File 'lib/gloo/objs/dev/git.rb', line 17

def self.typename
  return KEYWORD
end

Instance Method Details

#msg_check_changesObject

Check to see if the repo has changes.



101
102
103
104
105
106
107
108
109
110
# File 'lib/gloo/objs/dev/git.rb', line 101

def msg_check_changes
  result = false
  path = path_value
  if path_is_dir?( path )
    data = `cd #{path}; git status -s`
    result = true unless data.strip.empty?
  end

  $engine.heap.it.set_to result
end

#msg_commitObject

Commit pending changes.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gloo/objs/dev/git.rb', line 63

def msg_commit
  msg = 'Commit'
  path = path_value
  if path_is_dir?( path )
    if @params&.token_count&.positive?
      expr = Gloo::Expr::Expression.new( @params.tokens )
      msg = expr.evaluate
    end
    branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
    branch = branch.strip
    add = 'git add .'
    cmt = 'git commit -m '
    psh = 'git push origin '
    `cd #{path};#{add};#{cmt}"#{msg}";#{psh}#{branch}`
  end
  $engine.heap.it.set_to msg
end

#msg_get_branchObject

Get the current working branch.



49
50
51
52
53
54
55
56
57
58
# File 'lib/gloo/objs/dev/git.rb', line 49

def msg_get_branch
  branch = ''
  path = path_value
  if path_is_dir?( path )
    branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
    branch = branch.strip
  end

  $engine.heap.it.set_to branch
end

#msg_get_changesObject

Get the pending changes.



84
85
86
87
88
89
# File 'lib/gloo/objs/dev/git.rb', line 84

def msg_get_changes
  path = path_value
  result = `cd #{path}; git status -s` if path_is_dir?( path )
  result ||= ''
  $engine.heap.it.set_to result
end

#msg_validateObject

Check to make sure this is a valide git repo.



115
116
117
118
119
120
121
122
123
124
# File 'lib/gloo/objs/dev/git.rb', line 115

def msg_validate
  result = false
  path = path_value
  if path_is_dir?( path )
    pn = File.join( path, '.git' )
    result = File.exist? pn
  end

  $engine.heap.it.set_to result
end

#path_is_dir?(path) ⇒ Boolean

Is the given path non nil and is it a directory?

Returns:



94
95
96
# File 'lib/gloo/objs/dev/git.rb', line 94

def path_is_dir?( path )
  return path && File.directory?( path )
end

#path_valueObject

Get the path to the git repo (locally).



31
32
33
# File 'lib/gloo/objs/dev/git.rb', line 31

def path_value
  return value
end