Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4 support #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
109 changes: 106 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,106 @@
Gemfile.lock
rdoc
pkg
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# generated by bundle viz
gem_graph.png

# temp files
,*
*~
*~HEAD

# from netbeans
/nbproject/*

# from rake spec:rcov
/coverage

coverage.data

# from rubymine
.idea/*

# From Linux dolphin etc
.directory

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
log/*.log
*.sql
*.sqlite[3]

# OS generated files #
######################
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db

# Miscellaneous
######################
rerun.txt
*~
.~*
*.csv
.sass-cache/
.bundle
tmp/**/*
tmp/*
doc/api
doc/app
doc/*.svg
.*.swp
*.swp
*~
*.orig
*.pdf
components
vendor/

Downloads/

# Vagrant stuff
acceptance_config.yml
boxes/*
#/Vagrantfile
/.vagrant

# Bundler/Rubygems
*.gem
pkg/*
tags
test/tmp/

# Python
*.pyc

# Rubinius
*.rbc

# IDE junk
.idea/*
*.iml

# static public/assets
public/assets

24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PATH
remote: .
specs:
active_presenter (4.1.5)

GEM
remote: http://rubygems.org/
specs:
expectations (2.0.0)
mocha (>= 0.5.5)
metaclass (0.0.4)
minitest (4.7.5)
mocha (1.1.0)
metaclass (~> 0.0.1)
sqlite3 (1.3.9)

PLATFORMS
ruby

DEPENDENCIES
active_presenter!
expectations (~> 2.0)
minitest (~> 4.2)
sqlite3 (>= 1.3)
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'rdoc/task'
require File.dirname(__FILE__)+'/lib/active_presenter'
Dir.glob(File.dirname(__FILE__)+'/lib/tasks/**/*.rake').each { |l| load l }

task :default => :test
task default: :test

task :test do
Dir['test/**/*_test.rb'].each { |l| require File.join(File.dirname(__FILE__),l)}
Expand Down
9 changes: 5 additions & 4 deletions active_presenter.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = %q{active_presenter}
s.version = "3.2.2"
s.version = "4.1.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Golick", "Daniel Haran", "Josh Martin", "Johnno Loggie"]
s.date = %q{2012-03-26}
Expand Down Expand Up @@ -35,7 +35,8 @@ Gem::Specification.new do |s|
"test/lint_test.rb",
"test/test_helper.rb"
]
s.add_runtime_dependency(%q<activerecord>, [">= 3.0.10"])
s.add_development_dependency(%q<expectations>, [">= 2.0.0"])
s.add_development_dependency(%q<sqlite3>, [">= 1.3.5"])
s.add_runtime_dependency(%q<activerecord>, ["~> 4.1"])
s.add_development_dependency(%q<expectations>, ["~> 2.0"])
s.add_development_dependency(%q<sqlite3>, ["~> 1.3"])
s.add_development_dependency(%q<minitest>, ["~> 4.2"])
end
28 changes: 13 additions & 15 deletions lib/active_presenter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ module ActivePresenter
# Base class for presenters. See README for usage.
#
class Base
extend ActiveModel::Callbacks
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::MassAssignmentSecurity
include ActiveModel::Conversion
include ActiveModel::Model

attr_reader :errors

Expand Down Expand Up @@ -39,7 +35,7 @@ def self.presents(*types)
send(t).errors
end

# We must reassign in derrived classes rather than mutating the attribute in Base
# We must reassign in derived classes rather than mutating the attribute in Base
self.presented = self.presented.merge(t => types_and_classes[t])
end
end
Expand Down Expand Up @@ -72,7 +68,7 @@ def self.human_name(options = {}) # :nodoc:
:"#{klass.name.underscore}"
end
defaults << self.name.humanize
I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
I18n.translate(defaults.shift, {scope: [:activerecord, :models], count: 1, default: defaults}.merge(options))
end

# Accepts arguments in two forms. For example, if you had a SignupPresenter that presented User, and Account, you could specify arguments in the following two forms:
Expand Down Expand Up @@ -106,7 +102,7 @@ def attributes=(attrs)

attrs = attrs.stringify_keys
multi_parameter_attributes = {}
attrs = sanitize_for_mass_assignment(attrs)
# attrs = sanitize_for_mass_assignment(attrs)

attrs.each do |k,v|
if (base_attribute = k.to_s.split("(").first) != k.to_s
Expand Down Expand Up @@ -140,7 +136,7 @@ def method_missing(method_name, *args, &block)
def valid?
validated = false
errors.clear
result = _run_validation_callbacks do
result = run_callbacks :validation do
presented.keys.each do |type|
presented_inst = send(type)
next unless save?(type, presented_inst)
Expand All @@ -164,7 +160,7 @@ def save
saved = false
ActiveRecord::Base.transaction do
if valid?
_run_save_callbacks do
run_callbacks :save do
saved = presented.keys.select {|key| save?(key, send(key))}.all? {|key| send(key).save}
raise ActiveRecord::Rollback unless saved
end
Expand All @@ -181,7 +177,7 @@ def save!
saved = false
ActiveRecord::Base.transaction do
raise ActiveRecord::RecordInvalid.new(self) unless valid?
_run_save_callbacks do
run_callbacks :save do
presented.keys.select {|key| save?(key, send(key))}.all? {|key| send(key).save!}
saved = true
end
Expand Down Expand Up @@ -268,10 +264,12 @@ def merge_errors(presented_inst, type)
end

def attribute_protected?(name)
presentable = presentable_for(name)
return false unless presentable
flat_attribute = {flatten_attribute_name(name, presentable) => ''} #remove_att... normally takes a hash, so we use a ''
presented[presentable].new.send(:sanitize_for_mass_assignment, flat_attribute).empty?

return false
# presentable = presentable_for(name)
# return false unless presentable
# flat_attribute = {flatten_attribute_name(name, presentable) => ''} #remove_att... normally takes a hash, so we use a ''
# presented[presentable].new.send(:sanitize_for_mass_assignment, flat_attribute).empty?
end
end
end
6 changes: 3 additions & 3 deletions lib/active_presenter/version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module ActivePresenter
module VERSION
MAJOR = 3
MINOR = 2
TINY = 2
MAJOR = 4
MINOR = 1
TINY = 5

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
8 changes: 4 additions & 4 deletions lib/tasks/gem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
s.rubyforge_project = 'active_presenter'
s.has_rdoc = true

s.required_ruby_version = '>= 1.8.5'
s.required_ruby_version = '>= 2'

s.files = %w(README LICENSE Rakefile) +
Dir.glob("{lib,test}/**/*")
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace :gem do
namespace :upload do

desc 'Upload gems (ruby & win32) to rubyforge.org'
task :rubyforge => :gem do
task rubyforge: :gem do
sh 'rubyforge login'
sh "rubyforge add_release giraffesoft active_presenter #{ActivePresenter::VERSION::STRING} pkg/#{spec.full_name}.gem"
sh "rubyforge add_file giraffesoft active_presenter #{ActivePresenter::VERSION::STRING} pkg/#{spec.full_name}.gem"
Expand All @@ -53,10 +53,10 @@ namespace :gem do
end
end

task :install => [:clobber, :package] do
task install: [:clobber, :package] do
sh "sudo gem install pkg/#{spec.full_name}.gem"
end

task :uninstall => :clean do
task uninstall: :clean do
sh "sudo gem uninstall -v #{ActivePresenter::VERSION::STRING} -x #{ActivePresenter::NAME}"
end
Loading