Skip to content

Commit

Permalink
Merge pull request #6 from robmckinnon/ruby-2.6-update
Browse files Browse the repository at this point in the history
Drop Ruby < 1.9 support
  • Loading branch information
robmckinnon authored Mar 25, 2019
2 parents 7cfb9ce + 3ff9243 commit f48d762
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 45 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: ruby
rvm:
- 2.4.0
- 2.3.1
- 2.2.5
- 2.6.2
- 2.5.5
- 2.4.5
- 2.3.8
- 2.2.10
- ruby-head
bundler_args: --without test
script: bundle exec rspec spec
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v0.6.0. drop Ruby < 1.9 support, test against Ruby 2.5/2.6, require activesupport >= 4.1.11

v0.5.1. replace Fixnum with Integer to prevent deprecation warning in Ruby 2.4

v0.5.0. set accessor methods when attribute value is blank, instead of ignoring
Expand Down
12 changes: 2 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ end

group :development do
gem 'rspec'
end

if RUBY_VERSION < '1.9'
gem 'i18n', '0.6.11'
gem 'activesupport', '~> 3.2.0'
gem 'fastercsv'
gem 'rake', '~> 0.9.2.2' # required for travis builds
gem 'json'
else
gem 'activesupport'
gem 'rake'
end

gem 'activesupport', ">= 4.1.11"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Rob McKinnon
Copyright (c) 2019 Rob McKinnon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To use Morph:
require 'morph'
```

Tested to work with Ruby 1.8 - 2.3, JRuby 9, and Rubinius 3.
Tested to work with Ruby 2.2 - 2.6.

## Morph creating classes `from_json`

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec = Gem::Specification.new do |s|
s.version = Morph::VERSION
s.summary = 'Morph allows you to emerge Ruby class definitions from data or by calling assignment methods.'
s.author = 'Rob McKinnon'
s.email = 'rob ~@nospam@~ rubyforge.org'
s.email = 'rob ~@nospam@~ movingflow'
s.homepage = 'https://github.com/robmckinnon/morph'

s.has_rdoc = true
Expand All @@ -27,7 +27,7 @@ spec = Gem::Specification.new do |s|
s.files = %w(CHANGELOG LICENSE) + Dir.glob('{lib}/**/*')
s.require_paths = ['lib']

s.add_runtime_dependency('activesupport', '>= 2.0.2')
s.add_runtime_dependency('activesupport', '>= 4.1.11')
s.add_development_dependency('rspec')
end

Expand Down
38 changes: 10 additions & 28 deletions lib/morph.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
if RUBY_VERSION >= "1.9"
require 'csv'
end
require 'csv'

begin
# require 'active_support'
require 'active_support/core_ext/object/blank'
require 'active_support/inflector'
require 'active_support/core_ext/string/inflections'
Expand Down Expand Up @@ -63,11 +61,7 @@ def self.morph_attributes klass
end

def self.morph_methods klass
methods = if RUBY_VERSION >= "1.9"
@morph_methods[klass].keys.sort
else
@morph_methods[klass].keys.map(&:to_s).sort
end
methods = @morph_methods[klass].keys.sort

if klass.superclass.respond_to?(:morph_attributes)
methods += klass.superclass.morph_methods
Expand Down Expand Up @@ -97,9 +91,7 @@ def self.add_morph_attribute klass, attribute

def self.morph_method_missing object, symbol, *args
attribute = symbol.to_s.chomp '='
if RUBY_VERSION >= "1.9"
attribute = attribute.to_sym
end
attribute = attribute.to_sym

if Object.instance_methods.include?(attribute)
raise "'#{attribute}' is an instance_method on Object, cannot create accessor methods for '#{attribute}'"
Expand Down Expand Up @@ -132,7 +124,7 @@ def self.convert_to_morph_method_name label
end

module Morph
VERSION = '0.5.1' unless defined? Morph::VERSION
VERSION = '0.6.0' unless defined? Morph::VERSION

class << self
def classes
Expand All @@ -157,23 +149,13 @@ def generate_migrations object, options={}

def from_csv csv, class_name, namespace=Morph
objects = []
if !(RUBY_VERSION >= "1.9")
begin
require 'fastercsv'
rescue LoadError
puts "\nYou need to install the fastercsv gem to use Morph.from_csv() with Ruby 1.8"
puts " gem install fastercsv\n"
CSV.parse(csv, { :headers => true }) do |row|
object = object_from_name class_name, namespace
row.each do |key, value|
object.morph(key, value)
end
objects << object
end

csv_utility = (RUBY_VERSION >= "1.9") ? CSV : 'FasterCSV'.constantize
csv_utility.parse(csv, { :headers => true }) do |row|
object = object_from_name class_name, namespace
row.each do |key, value|
object.morph(key, value)
end
objects << object
end
objects
end

Expand Down

0 comments on commit f48d762

Please sign in to comment.