Skip to content

Commit

Permalink
Remove unnecessary extensions, patches and guards for Ruby 1.8.7 #11
Browse files Browse the repository at this point in the history
  • Loading branch information
hidakatsuya committed Mar 11, 2015
1 parent 7e43972 commit c7e9148
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 217 deletions.
3 changes: 0 additions & 3 deletions Gemfile
@@ -1,6 +1,3 @@
source 'http://rubygems.org'

gemspec

# For 1.8.7
gem 'json', '>= 1.4.6' unless RUBY_VERSION > '1.9'
7 changes: 1 addition & 6 deletions lib/thinreports/core/format/builder.rb
@@ -1,11 +1,6 @@
# coding: utf-8

begin
require 'json'
rescue LoadError
puts 'ThinReports requires json >= 1.4.6. ' +
'Please `gem install json` and try again.'
end
require 'json'

module ThinReports
module Core::Format
Expand Down
39 changes: 0 additions & 39 deletions lib/thinreports/core/ordered_hash.rb

This file was deleted.

16 changes: 8 additions & 8 deletions lib/thinreports/core/shape/manager/format.rb
Expand Up @@ -2,27 +2,27 @@

module ThinReports
module Core::Shape

# @private
class Manager::Format < Core::Format::Base
# @return [Symbol, Integer]
attr_reader :identifier

config_reader layout: %w( svg )

def initialize(config, id = nil, &block)
super(config, &block)
@identifier = id || self.object_id
end

def find_shape(id)
shapes[id]
end

def shapes
@shapes ||= ThinReports::Core::OrderedHash.new
@shapes ||= {}
end
end

end
end
end
36 changes: 7 additions & 29 deletions lib/thinreports/core/shape/text_block/formatter/padding.rb
Expand Up @@ -2,44 +2,22 @@

module ThinReports
module Core::Shape::TextBlock

# @private
class Formatter::Padding < Formatter::Basic

private

ruby_18 do
def apply_format_to(value)
value = value.to_s

char_length = value.unpack('U*').length
pad_length = format.format_padding_length

if pad_length > char_length
pad_strs = format.format_padding_char * (pad_length - char_length)
if format.format_padding_rdir?
value + pad_strs
else
pad_strs + value
end
else
value
end
end
end

ruby_19 do

private

def apply_format_to(value)
value.to_s.send(format.format_padding_rdir? ? :ljust : :rjust,
format.format_padding_length,
format.format_padding_char)
end
end


def applicable?(value)
!format.format_padding_char.blank? && format.format_padding_length > 0
end
end

end
end
end
24 changes: 4 additions & 20 deletions lib/thinreports/core/utils.rb
Expand Up @@ -2,39 +2,23 @@

module ThinReports
module Core

# @private
module Utils
def block_exec_on(context, &block)
return context unless block_given?

if block.arity == 1
block.call(context)
else
context.instance_eval(&block)
end
context
end

if RUBY_VERSION < '1.9'
def ruby_18
yield
end
def ruby_19
false
end
else
def ruby_18
false
end
def ruby_19
yield
end
end
end

end
end

# Include global methods.
include ThinReports::Core::Utils
include ThinReports::Core::Utils
13 changes: 0 additions & 13 deletions test/test_helper.rb
@@ -1,6 +1,5 @@
# coding: utf-8

require 'rubygems'
require 'minitest/autorun'
require 'minitest/spec'
require 'minitest/unit'
Expand All @@ -23,18 +22,6 @@ def teardown
clear_output
end

def skip_if_ruby19
if RUBY_VERSION > '1.9'
skip('This test is not required more than Ruby 1.9.')
end
end

def skip_if_ruby18
if RUBY_VERSION < '1.9'
skip('This test is not required Ruby 1.8 below.')
end
end

def create_basic_report(file, &block)
report = ThinReports::Report.new layout: data_file(file)
block.call(report) if block_given?
Expand Down
51 changes: 0 additions & 51 deletions test/unit/core/ordered_hash_spec.rb

This file was deleted.

16 changes: 6 additions & 10 deletions test/unit/core/shape/manager/test_format.rb
Expand Up @@ -4,31 +4,27 @@

class ThinReports::Core::Shape::Manager::TestFormat < Minitest::Test
include ThinReports::TestHelper

class TestFormat < ThinReports::Core::Shape::Manager::Format; end

def test_identifier_should_return_the_same_as_object_id_when_id_is_not_given
format = TestFormat.new({})
assert_equal format.identifier, format.object_id
end

def test_identifier_should_return_the_specified_id_when_id_is_given
assert_equal TestFormat.new({}, :any_id).identifier, :any_id
end

def test_shapes_should_return_instance_of_OrderedHash
assert_instance_of ThinReports::Core::OrderedHash, TestFormat.new({}).shapes
end


def test_find_shape_should_return_format_of_shape_when_shape_is_found
format = TestFormat.new({}) do |f|
f.shapes[:foo] = ThinReports::Core::Shape::TextBlock::Format.new('id' => 'foo',
'type' => 's-tblock')
end
assert_equal format.find_shape(:foo).id, 'foo'
end

def test_find_shape_should_return_nil_when_shape_is_not_found
assert_nil TestFormat.new({}).find_shape(:unknown)
end
end
end
40 changes: 2 additions & 38 deletions test/unit/core/utils_spec.rb
Expand Up @@ -9,48 +9,12 @@
expected = '123'
block_exec_on(expected).must_be_same_as expected
end

it 'should be run correctly without receiver if no block argument' do
block_exec_on('123', &proc{ reverse! }).must_equal '321'
end

it 'should be run correctly with an receiver if block has an argument' do
block_exec_on([2, 1, 3], &proc{ |a| a.sort! }).must_equal [1, 2, 3]
end
end

describe '#ruby_18' do
it 'should not be run and return false if ruby version more than 1.8' do
skip_if_ruby18

ruby_18 {
flunk '#ruby_18 should not be executed!'
}.must_equal false
end

it 'should be run if ruby version less than 1.9' do
skip_if_ruby19

ruby_18 {
pass '#ruby_18 was executed correctly!'; true
}.must_equal true
end
end

describe '#ruby_19' do
it 'should not be run and return false if ruby version less than 1.9' do
skip_if_ruby19

ruby_19 {
flunk '#ruby_19 should not be executed!'
}.must_equal false
end

it 'should be run if ruby version more than 1.9' do
skip_if_ruby18

ruby_19 {
pass '#ruby_19 was executed correctly!'; true
}.must_equal true
end
end

0 comments on commit c7e9148

Please sign in to comment.