Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AllCops:
Exclude:
- vendor/**/*

inherit_from: .rubocop_todo.yml

Style/AndOr:
EnforcedStyle: conditionals
87 changes: 87 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-11-17 14:29:53 -0500 using RuboCop version 0.35.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 3
Metrics/AbcSize:
Max: 24

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 98
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 140

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 20

# Offense count: 4
Metrics/PerceivedComplexity:
Max: 12

# Offense count: 2
Style/AccessorMethodName:
Exclude:
- 'lib/virtus/attribute/accessor.rb'
- 'lib/virtus/support/options.rb'

# Offense count: 2
Style/CaseEquality:
Exclude:
- 'lib/virtus.rb'
- 'lib/virtus/module_extensions.rb'

# Offense count: 15
# Configuration parameters: Exclude.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/virtus.rb'
- 'lib/virtus/attribute/lazy_default.rb'
- 'lib/virtus/class_inclusions.rb'
- 'lib/virtus/const_missing_extensions.rb'
- 'lib/virtus/extensions.rb'
- 'lib/virtus/instance_methods.rb'
- 'lib/virtus/model.rb'
- 'lib/virtus/value_object.rb'
- 'lib/virtus/version.rb'

# Offense count: 3
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/virtus/class_methods.rb'
- 'lib/virtus/instance_methods.rb'
- 'lib/virtus/support/type_lookup.rb'

# Offense count: 1
Style/ModuleFunction:
Exclude:
- 'spec/shared/constants_helpers.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/virtus/module_extensions.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
Style/SpaceInsideHashLiteralBraces:
Enabled: false
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Virtus recently hit it's 1.0 release (2013-10-16). The focus now is on bug-fixes
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* Run `rubocop -a` to fix any Ruby style issues and re-run `rubocop --auto-gen-config` for any acceptable exceptions.
* Commit, do not mess with Rakefile or version
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.
Expand Down
10 changes: 7 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ gem 'bogus', '~> 0.1'
gem 'inflecto', '~> 0.0.2'
gem 'rspec', '~> 3.1'

gem "codeclimate-test-reporter", group: :test, require: false
group :development, :test do
gem 'rubocop', '0.35.1'
end

group :test do
gem 'codeclimate-test-reporter', require: false
end

group :tools do
gem 'guard'
gem 'guard-rspec'

gem 'rubocop'

platform :mri do
gem 'mutant'
gem 'mutant-rspec'
Expand Down
4 changes: 2 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
guard :rspec, spec_paths: 'spec/unit' do
#run all specs if configuration is modified
# run all specs if configuration is modified
watch('Guardfile') { 'spec' }
watch('Gemfile.lock') { 'spec' }
watch('spec/spec_helper.rb') { 'spec' }
Expand All @@ -15,5 +15,5 @@ guard :rspec, spec_paths: 'spec/unit' do
# run a spec if it is modified
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})

notification :tmux, :display_message => true
notification :tmux, display_message: true
end
14 changes: 5 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
require "rspec/core/rake_task"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
task default: [:spec]

begin
require "rubocop/rake_task"
require 'rubocop/rake_task'
Rake::Task[:default].enhance [:rubocop]

Rake::Task[:default].enhance [:rubocop]

RuboCop::RakeTask.new do |task|
task.options << "--display-cop-names"
end
rescue LoadError
RuboCop::RakeTask.new do |task|
task.options << '--display-cop-names'
end
9 changes: 4 additions & 5 deletions lib/virtus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

# Base module which adds Attribute API to your classes
module Virtus

# Provides args for const_get and const_defined? to make them behave
# consistently across different versions of ruby
EXTRA_CONST_ARGS = (RUBY_VERSION < '1.9' ? [] : [ false ]).freeze
EXTRA_CONST_ARGS = (RUBY_VERSION < '1.9' ? [] : [false]).freeze

# Represents an undefined parameter used by auto-generated option methods
Undefined = Object.new.freeze
Expand All @@ -14,7 +13,8 @@ class CoercionError < StandardError
attr_reader :output, :attribute

def initialize(output, attribute)
@output, @attribute = output, attribute
@output = output
@attribute = attribute
super(build_message)
end

Expand Down Expand Up @@ -120,7 +120,7 @@ def self.coerce
# @return [Configuration]
#
# @api public
def self.config(&block)
def self.config(&_block)
yield configuration if block_given?
configuration
end
Expand Down Expand Up @@ -237,7 +237,6 @@ def self.finalize
def self.warn(msg)
Kernel.warn(msg)
end

end # module Virtus

require 'descendants_tracker'
Expand Down
13 changes: 5 additions & 8 deletions lib/virtus/attribute.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Virtus

# Attribute objects handle coercion and provide interface to hook into an
# attribute set instance that's included into a class or object
#
Expand Down Expand Up @@ -112,7 +111,7 @@ def coerce(input)
#
# @api public
def rename(name)
self.class.build(type, options.merge(:name => name))
self.class.build(type, options.merge(name: name))
end

# Return if the given value was coerced
Expand Down Expand Up @@ -140,7 +139,7 @@ def value_coerced?(value)
#
# @api public
def coercible?
kind_of?(Coercible)
is_a?(Coercible)
end

# Return if the attribute has lazy default value evaluation
Expand All @@ -157,7 +156,7 @@ def coercible?
#
# @api public
def lazy?
kind_of?(LazyDefault)
is_a?(LazyDefault)
end

# Return if the attribute is in the strict coercion mode
Expand All @@ -174,7 +173,7 @@ def lazy?
#
# @api public
def strict?
kind_of?(Strict)
is_a?(Strict)
end

# Return if the attribute is in the nullify blank coercion mode
Expand All @@ -191,7 +190,7 @@ def strict?
#
# @api public
def nullify_blank?
kind_of?(NullifyBlank)
is_a?(NullifyBlank)
end

# Return if the attribute is accepts nil values as valid coercion output
Expand Down Expand Up @@ -239,7 +238,5 @@ def finalize
freeze
self
end

end # class Attribute

end # module Virtus
4 changes: 0 additions & 4 deletions lib/virtus/attribute/accessor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Virtus
class Attribute

# Accessor extension provides methods to read and write attributes
#
# @example
Expand All @@ -13,7 +12,6 @@ class Attribute
# attribute.get(object) # => 'jane@doe.com'
#
module Accessor

# Return name of this accessor attribute
#
# @return [Symbol]
Expand Down Expand Up @@ -96,8 +94,6 @@ def public_reader?
def public_writer?
options[:writer] == :public
end

end # Accessor

end # Attribute
end # Virtus
2 changes: 0 additions & 2 deletions lib/virtus/attribute/boolean.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Virtus
class Attribute

# Boolean attribute allows true or false values to be set
# Additionally it adds boolean reader method, like "admin?"
#
Expand Down Expand Up @@ -49,7 +48,6 @@ def define_accessor_methods(attribute_set)
super
attribute_set.define_reader_method(self, "#{name}?", options[:reader])
end

end # class Boolean
end # class Attribute
end # module Virtus
22 changes: 9 additions & 13 deletions lib/virtus/attribute/builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Virtus

# Attribute placeholder used when type constant is passed as a string or symbol
#
# @private
Expand All @@ -8,7 +7,8 @@ class PendingAttribute

# @api private
def initialize(type, options)
@type, @options = type.to_s, options
@type = type.to_s
@options = options
@name = options[:name]
end

Expand All @@ -30,13 +30,12 @@ def determine_type
if defined?(Inflecto)
Inflecto.constantize(type)
else
raise NotImplementedError, 'Virtus needs inflecto gem to constantize namespaced constant names'
fail NotImplementedError, 'Virtus needs inflecto gem to constantize namespaced constant names'
end
else
Object.const_get(type)
end
end

end # PendingAttribute

# Extracts the actual type primitive from input type
Expand Down Expand Up @@ -64,13 +63,13 @@ def initialize_primitive
if type.instance_of?(String) || type.instance_of?(Symbol)
if !type.to_s.include?('::') && Object.const_defined?(type)
Object.const_get(type)
elsif not Attribute::Builder.determine_type(type)
elsif !Attribute::Builder.determine_type(type)
@pending = true
type
else
type
end
elsif not type.is_a?(Class)
elsif !type.is_a?(Class)
type.class
else
type
Expand All @@ -79,7 +78,6 @@ def initialize_primitive
end

class Attribute

# Builder is used to set up an attribute instance based on input type and options
#
# @private
Expand Down Expand Up @@ -141,19 +139,19 @@ def initialize_type

# @api private
def initialize_options(options)
@options = klass.options.merge(:coerce => Virtus.coerce).update(options)
@options = klass.options.merge(coerce: Virtus.coerce).update(options)
klass.merge_options!(type, @options)
determine_visibility
end

# @api private
def initialize_default_value
options.update(:default_value => DefaultValue.build(options[:default]))
options.update(default_value: DefaultValue.build(options[:default]))
end

# @api private
def initialize_coercer
options.update(:coercer => determine_coercer)
options.update(coercer: determine_coercer)
end

# @api private
Expand All @@ -179,10 +177,8 @@ def determine_visibility
default_accessor = options.fetch(:accessor)
reader_visibility = options.fetch(:reader, default_accessor)
writer_visibility = options.fetch(:writer, default_accessor)
options.update(:reader => reader_visibility, :writer => writer_visibility)
options.update(reader: reader_visibility, writer: writer_visibility)
end

end # class Builder

end # class Attribute
end # module Virtus
Loading