Class: GitPunch::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/git_punch/song.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(with_options = {}) ⇒ Song

Returns a new instance of Song.



7
8
9
10
11
12
13
# File 'lib/git_punch/song.rb', line 7

def initialize with_options={}
  @attributes = with_options.reduce({}) do |attrs,opt,val|
    send "#{opt}=", val if respond_to? opt
    attrs.merge opt => val
  end

end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/git_punch/song.rb', line 3

def attributes
  @attributes
end

#is_forkObject Also known as: is_fork?

Returns the value of attribute is_fork.



3
4
5
# File 'lib/git_punch/song.rb', line 3

def is_fork
  @is_fork
end

#original_song_idObject

Returns the value of attribute original_song_id.



3
4
5
# File 'lib/git_punch/song.rb', line 3

def original_song_id
  @original_song_id
end

#original_userObject

Returns the value of attribute original_user.



3
4
5
# File 'lib/git_punch/song.rb', line 3

def original_user
  @original_user
end

Class Method Details

.fork(with_options = {}) ⇒ Object



15
16
17
18
19
# File 'lib/git_punch/song.rb', line 15

def self.fork with_options={}
  new with_options.merge \
    is_fork: true,
    original_user: User.from_origin.name
end

Instance Method Details

#errorsObject



30
31
32
# File 'lib/git_punch/song.rb', line 30

def errors
  @errors ||= ClientErrors.new
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/git_punch/song.rb', line 21

def valid?
  if is_fork? && original_user.present?
    fork_url = "/songs/#{original_song_id}/fork"
    create_repository_at fork_url
  else
    create_repository_at "/songs"
  end
end