Class: SocialSnippet::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/social_snippet/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_path, new_repo = nil, new_ref = nil) ⇒ Context

Constructor

Parameters:

  • new_path (String)

    The path of context


11
12
13
14
15
16
# File 'lib/social_snippet/context.rb', line 11

def initialize(new_path, new_repo = nil, new_ref = nil)
  @flag_absolute = is_absolute_path(new_path)
  @path = new_path
  @repo = new_repo
  @ref  = new_ref
end

Instance Attribute Details

#flag_absoluteObject (readonly)

Returns the value of attribute flag_absolute


3
4
5
# File 'lib/social_snippet/context.rb', line 3

def flag_absolute
  @flag_absolute
end

#pathObject (readonly)

Returns the value of attribute path


4
5
6
# File 'lib/social_snippet/context.rb', line 4

def path
  @path
end

#refObject (readonly)

Returns the value of attribute ref


6
7
8
# File 'lib/social_snippet/context.rb', line 6

def ref
  @ref
end

#repoObject (readonly)

Returns the value of attribute repo


5
6
7
# File 'lib/social_snippet/context.rb', line 5

def repo
  @repo
end

Instance Method Details

#is_in_repository?Boolean

Check context in repo

Returns:

  • (Boolean)

21
22
23
# File 'lib/social_snippet/context.rb', line 21

def is_in_repository?
  repo.nil? === false
end

#move(new_path, new_repo = nil, new_ref = nil) ⇒ Object

Move to new path from current path

Parameters:

  • new_path (String)

    The next path

  • new_repo (String) (defaults to: nil)

    The next repository

  • new_ref (String) (defaults to: nil)

    The next reference


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/social_snippet/context.rb', line 30

def move(new_path, new_repo = nil, new_ref = nil)
  if new_repo.nil?
    if is_absolute_path(new_path)
      @flag_absolute = true
      @path = new_path
    else
      @path = move_func(new_path)
    end
  else
    @flag_absolute = false
    @path = new_path
    @repo = new_repo
    @ref  = new_ref
  end
end