Boring Ruby Code

9800e8331d2341549301c957a878f1c8?s=47 Adam Niedzielski
October 06, 2017
50

Boring Ruby Code

Southeast Ruby

9800e8331d2341549301c957a878f1c8?s=128

Adam Niedzielski

October 06, 2017
Tweet

Transcript

  1. 20.

    @niedzielskiadam blog.sundaycoding.com def initialize(options) %w(id name path size data mode

    commit_id binary).each do |key| self.send("#{key}=", options[key.to_sym]) end end
  2. 21.

    @niedzielskiadam blog.sundaycoding.com def initialize(options) %w(id name path size data mode

    commit_id binary).each do |key| self.send("#{key}=", options[key.to_sym]) end end
  3. 22.

    @niedzielskiadam blog.sundaycoding.com %i(call to_document to_html).each do |meth| define_method(meth) do |text,

    context| context = transform_context(context) html_pipeline.send(meth, text, context) end end
  4. 23.

    @niedzielskiadam blog.sundaycoding.com %i(call to_document to_html).each do |meth| define_method(meth) do |text,

    context| context = transform_context(context) html_pipeline.send(meth, text, context) end end
  5. 24.

    @niedzielskiadam blog.sundaycoding.com def call(text, context) context = transform_context(context) html_pipeline.call(text, context)

    end def to_document(text, context) context = transform_context(context) html_pipeline.to_document(text, context) end def to_html(text, context) context = transform_context(context) html_pipeline.to_html(text, context) end
  6. 25.

    @niedzielskiadam blog.sundaycoding.com %i(call to_document to_html).each do |meth| define_method(meth) do |text,

    context| context = transform_context(context) html_pipeline.send(meth, text, context) end end
  7. 27.

    @niedzielskiadam blog.sundaycoding.com %i(original_position position).each do |meth| define_method "#{meth}=" do |new_position|

    if new_position.is_a?(String) new_position = JSON.parse(new_position) rescue nil end if new_position.is_a?(Hash) new_position = new_position.with_indifferent_access new_position = Gitlab::Diff::Position.new(new_position) end super(new_position) end end
  8. 28.

    @niedzielskiadam blog.sundaycoding.com %i(original_position position).each do |meth| define_method "#{meth}=" do |new_position|

    if new_position.is_a?(String) new_position = JSON.parse(new_position) rescue nil end if new_position.is_a?(Hash) new_position = new_position.with_indifferent_access new_position = Gitlab::Diff::Position.new(new_position) end super(new_position) end end
  9. 29.

    @niedzielskiadam blog.sundaycoding.com %i(original_position position).each do |meth| define_method "#{meth}=" do |new_position|

    if new_position.is_a?(String) new_position = JSON.parse(new_position) rescue nil end if new_position.is_a?(Hash) new_position = new_position.with_indifferent_access new_position = Gitlab::Diff::Position.new(new_position) end super(new_position) end end
  10. 43.

    @niedzielskiadam blog.sundaycoding.com def method_missing(m, *args, &block) if m == :lookup

    && !block_given? lookup_cache[m] ||= {} lookup_cache[m][args.join(":")] ||= raw_repository.send(m, *args, &block) else raw_repository.send(m, *args, &block) end end
  11. 44.

    @niedzielskiadam blog.sundaycoding.com def method_missing(m, *args, &block) if m == :lookup

    && !block_given? lookup_cache[m] ||= {} lookup_cache[m][args.join(":")] ||= raw_repository.send(m, *args, &block) else raw_repository.send(m, *args, &block) end end
  12. 45.

    @niedzielskiadam blog.sundaycoding.com def method_missing(m, *args, &block) if m == :lookup

    && !block_given? lookup_cache[m] ||= {} lookup_cache[m][args.join(":")] ||= raw_repository.send(m, *args, &block) else raw_repository.send(m, *args, &block) end end
  13. 53.

    @niedzielskiadam blog.sundaycoding.com def project_icon(project_id, options = {}) project = if

    project_id.is_a?(Project) project_id else Project.find_by_full_path(project_id) end end
  14. 54.

    @niedzielskiadam blog.sundaycoding.com def project_icon(project_id, options = {}) project = if

    project_id.is_a?(Project) project_id else Project.find_by_full_path(project_id) end end
  15. 55.

    @niedzielskiadam blog.sundaycoding.com def initialize(repository, name, target) encode! name @name =

    name.gsub(/\Arefs\/(tags|heads)\//, '') @dereferenced_target = Gitlab::Git::Commit.find(repository, target) @target = if target.respond_to?(:oid) target.oid elsif target.respond_to?(:name) target.name elsif target.is_a? String target else nil end end
  16. 56.

    @niedzielskiadam blog.sundaycoding.com def initialize(repository, name, target) encode! name @name =

    name.gsub(/\Arefs\/(tags|heads)\//, '') @dereferenced_target = Gitlab::Git::Commit.find(repository, target) @target = if target.respond_to?(:oid) target.oid elsif target.respond_to?(:name) target.name elsif target.is_a? String target else nil end end
  17. 57.

    @niedzielskiadam blog.sundaycoding.com def initialize(repository, name, target) encode! name @name =

    name.gsub(/\Arefs\/(tags|heads)\//, '') @dereferenced_target = Gitlab::Git::Commit.find(repository, target) @target = if target.respond_to?(:oid) target.oid elsif target.respond_to?(:name) target.name elsif target.is_a? String target else nil end end
  18. 58.

    @niedzielskiadam blog.sundaycoding.com def find(repo, commit_id = "HEAD") return commit_id if

    commit_id.is_a?(Gitlab::Git::Commit) return decorate(commit_id) if commit_id.is_a?(Rugged::Commit) obj = if commit_id.is_a?(String) repo.rev_parse_target(commit_id) else Gitlab::Git::Ref.dereference_object(commit_id) end return nil unless obj.is_a?(Rugged::Commit) decorate(obj) end
  19. 59.

    @niedzielskiadam blog.sundaycoding.com def find(repo, commit_id = "HEAD") return commit_id if

    commit_id.is_a?(Gitlab::Git::Commit) return decorate(commit_id) if commit_id.is_a?(Rugged::Commit) obj = if commit_id.is_a?(String) repo.rev_parse_target(commit_id) else Gitlab::Git::Ref.dereference_object(commit_id) end return nil unless obj.is_a?(Rugged::Commit) decorate(obj) end