-
-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'benchmark' | ||
require 'ostruct' | ||
require_relative '../lib/yard' | ||
|
||
n = 100000 | ||
class MyStruct < Struct.new(:a, :b, :c); end | ||
ostruct = OpenStruct.new | ||
yostruct = YARD::OpenStruct.new | ||
mystruct = MyStruct.new | ||
|
||
Benchmark.bmbm do |x| | ||
x.report("Struct.new(args)") { n.times { MyStruct.new 1, 2, 3 } } | ||
x.report("Struct (assign)") { n.times { mystruct.a = 1 } } | ||
x.report("Struct (read)") { n.times { mystruct.a } } | ||
x.report("OpenStruct.new(args)") { n.times { OpenStruct.new a: 1, b: 2, c: 3 } } | ||
x.report("OpenStruct.new (blank)") { n.times { OpenStruct.new } } | ||
x.report("OpenStruct (assign)") { n.times { ostruct.a = 1 } } | ||
x.report("OpenStruct (read)") { n.times { ostruct.a } } | ||
x.report("YARD::OpenStruct.new(args)") { n.times { YARD::OpenStruct.new a: 1, b: 2, c: 3 } } | ||
x.report("YARD::OpenStruct.new (blank)") { n.times { YARD::OpenStruct.new } } | ||
x.report("YARD::OpenStruct (assign)") { n.times { yostruct.a = 1 } } | ||
x.report("YARD::OpenStruct (read)") { n.times { yostruct.a } } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
module YARD | ||
module CodeObjects | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
module YARD | ||
module Handlers | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module YARD | ||
# An OpenStruct compatible struct class that allows for basic access of attributes | ||
# via +struct.attr_name+ and +struct.attr_name = value+. | ||
class OpenStruct | ||
def initialize(hash = {}) | ||
@table = hash.each_pair { |k, v| [k.to_sym, v] } | ||
end | ||
|
||
# @private | ||
def method_missing(name, *args) | ||
if name.to_s.end_with?('=') | ||
varname = name.to_s[0..-2].to_sym | ||
__cache_lookup__(varname) | ||
self[varname] = args.first | ||
else | ||
__cache_lookup__(name) | ||
self[name] | ||
end | ||
end | ||
|
||
def to_h | ||
@table.dup | ||
end | ||
|
||
def ==(other) | ||
other.is_a?(self.class) && to_h == other.to_h | ||
end | ||
|
||
def hash | ||
@table.hash | ||
end | ||
|
||
def dig(*keys) | ||
@table.dig(*keys) | ||
end | ||
|
||
def []=(key, value) | ||
@table[key.to_sym] = value | ||
end | ||
|
||
def [](key) | ||
@table[key.to_sym] | ||
end | ||
|
||
def each_pair(&block) | ||
@table.each_pair(&block) | ||
end | ||
|
||
def marshal_dump | ||
@table | ||
end | ||
|
||
def marshal_load(data) | ||
@table = data | ||
end | ||
|
||
private | ||
|
||
def __cache_lookup__(name) | ||
instance_eval <<-RUBY, __FILE__, __LINE__ + 1 | ||
def #{name}; @table[:#{name}]; end | ||
def #{name}=(v); @table[:#{name}] = v; end | ||
RUBY | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# frozen_string_literal: true | ||
require 'stringio' | ||
require 'ostruct' | ||
|
||
module YARD | ||
module Parser | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
module YARD | ||
module Tags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
module YARD | ||
module Templates | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
module YARD | ||
module Templates | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
require 'rubygems' | ||
|
||
RSpec.describe YARD::CLI::Gems do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# frozen_string_literal: true | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
require 'ostruct' | ||
|
||
include Parser | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'ostruct' | ||
|
||
include Server | ||
include Commands | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters