Skip to content

Commit

Permalink
implement attr_accessor_initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Sep 16, 2015
1 parent 3046b79 commit 88f62b4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ PATH
specs:
locomotivecms_common (0.0.4)
activesupport (~> 4.2.1)
attr_extras (~> 4.4.0)
colorize
stringex (~> 2.5.2)

GEM
remote: https://rubygems.org/
specs:
activesupport (4.2.1)
activesupport (4.2.4)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
attr_extras (4.4.0)
codeclimate-test-reporter (0.4.7)
simplecov (>= 0.7.1, < 1.0.0)
colorize (0.7.7)
Expand All @@ -31,9 +33,9 @@ GEM
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
json (1.8.2)
json (1.8.3)
mime-types (2.4.3)
minitest (5.6.0)
minitest (5.8.0)
multi_json (1.11.0)
netrc (0.10.3)
rake (10.2.2)
Expand Down Expand Up @@ -81,3 +83,6 @@ DEPENDENCIES
locomotivecms_common!
rake (~> 10.1)
rspec (~> 3.2.0)

BUNDLED WITH
1.10.6
1 change: 1 addition & 0 deletions lib/locomotive/common.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative 'common/version'
require_relative 'common/core_ext'
require_relative 'common/attr_extras_ext'
require_relative 'common/logger'
require_relative 'common/exception'
require_relative 'common/notifier'
Expand Down
23 changes: 23 additions & 0 deletions lib/locomotive/common/attr_extras_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'attr_extras'

# https://github.com/barsoom/attr_extras/issues/18
module AttrExtrasExt

def self.mixin
self::Mixin
end

module Mixin

def attr_accessor_initialize(*names, &block)
attr_initialize(*names, &block)
attr_accessor(*AttrExtras::Utils.flat_names(names))
end

end

end

class Module
include AttrExtrasExt.mixin
end
1 change: 1 addition & 0 deletions locomotivecms_common.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'activesupport', '~> 4.2.1'
spec.add_dependency 'stringex', '~> 2.5.2'
spec.add_dependency 'attr_extras', '~> 4.4.0'
spec.add_dependency 'colorize'

spec.required_ruby_version = '~> 2.0'
Expand Down
26 changes: 26 additions & 0 deletions spec/unit/attr_extras_ext_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe AttrExtrasExt do

subject { Person.new('Hank', 'Moody') }

describe 'reader' do

it { expect(subject.first_name).to eq 'Hank' }
it { expect(subject.last_name).to eq 'Moody' }

end

describe 'writer' do

before { subject.first_name = 'Karen' }

it { expect(subject.first_name).to eq 'Karen' }

end


class Person
attr_accessor_initialize :first_name, :last_name
end
end

0 comments on commit 88f62b4

Please sign in to comment.