Class: GitPunch::Song
- Inherits:
-
Object
- Object
- GitPunch::Song
- Defined in:
- lib/git_punch/song.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#is_fork ⇒ Object
(also: #is_fork?)
Returns the value of attribute is_fork.
-
#original_song_id ⇒ Object
Returns the value of attribute original_song_id.
-
#original_user ⇒ Object
Returns the value of attribute original_user.
Class Method Summary collapse
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(with_options = {}) ⇒ Song
constructor
A new instance of Song.
- #valid? ⇒ Boolean
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 ={} @attributes = .reduce({}) do |attrs,opt,val| send "#{opt}=", val if respond_to? opt attrs.merge opt => val end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/git_punch/song.rb', line 3 def attributes @attributes end |
#is_fork ⇒ Object 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_id ⇒ Object
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_user ⇒ Object
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 ={} new .merge \ is_fork: true, original_user: User.from_origin.name end |
Instance Method Details
#errors ⇒ Object
30 31 32 |
# File 'lib/git_punch/song.rb', line 30 def errors @errors ||= ClientErrors.new end |
#valid? ⇒ 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 |