OSDN Git Service
(root)
/
pettanr
/
pettanr.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: fetch fail
[pettanr/pettanr.git]
/
app
/
models
/
license.rb
diff --git
a/app/models/license.rb
b/app/models/license.rb
index
ab72aab
..
f0ebd78
100644
(file)
--- a/
app/models/license.rb
+++ b/
app/models/license.rb
@@
-1,68
+1,56
@@
#
#
-class License < ActiveRecord::Base
+class License < Peta::SystemResource
+ load_manifest
belongs_to :license_group
belongs_to :system_picture
belongs_to :license_group
belongs_to :system_picture
+ has_many :resource_pictures
validates :license_group_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :license_group_id, :presence => true, :numericality => true, :existence => {:both => false}
+ validates :license_group_module_name, :presence => true, :length => {:maximum => 50}
validates :name, :presence => true, :length => {:maximum => 50}
validates :caption, :presence => true, :length => {:maximum => 30}
validates :name, :presence => true, :length => {:maximum => 50}
validates :caption, :presence => true, :length => {:maximum => 30}
- validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness =>
true
, :url => {:message => I18n.t('errors.messages.url')} #{:allow_blank => true}
+ validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness =>
{:scope => :name}
, :url => {:message => I18n.t('errors.messages.url')} #{:allow_blank => true}
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
+ validates :license_group_settings, :boost => {:boost_name => :license_group}
+ validates :credit_picture_settings, :boost => {:boost_name => :credit_picture}
- before_validation :valid_encode
-
- def valid_encode
- ['name', 'caption', 'url', 'settings', 'credit_pictures'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ scope :find_index, -> do
+ self.all
end
end
- def supply_default
+ scope :find_by_license_group, -> (license_group_id) do
+ where(license_group_id: license_group_id)
end
end
- def overwrite
+ scope :find_by_system_picture, -> (system_picture_id) do
+ where(system_picture_id: system_picture_id)
end
end
- def self.list
- opt = {}
- opt.merge!(License.list_opt)
- opt.merge!({:order => 'name'})
- License.find(:all, opt)
+ def overwrite
end
end
- def
self.list_opt
- {:include => {:license_group => {}}}
+ def
caption_with_group
+ self.license_group.caption + '/' + self.caption
end
end
- def self.list_json_opt
- {:include => {:license_group => {}}}
- end
-
- def self.show rid
- opt = {}
- opt.merge!(License.show_opt)
- res = License.find(rid, opt)
-# raise ActiveRecord::Forbidden unless res.visible?(au)
- res
+ def self.index_list_where list
+ ''
end
def self.show_opt
{:include => {:license_group => {}}}
end
end
def self.show_opt
{:include => {:license_group => {}}}
end
- def self.show_json_opt
- {:include => {:license_group => {}}}
- end
-
def self.list_by_name name
def self.list_by_name name
- License.
find :all, :conditions => ['licenses.name = ?', name], :order => 'licenses.updated_at desc'
+ License.
where(name: name).order(updated_at: :desc)
end
def self.store name, attr
r = License.replace_system_picture attr
end
def self.store name, attr
r = License.replace_system_picture attr
- attr['credit_pictures'] = attr['credit_pictures'].to_json
+ attr['credit_picture_settings'] = attr['credit_picture_settings'].to_json
+ attr['license_group_settings'] = attr['license_group_settings'].to_json
l = License.modify_object name, attr
l = License.modify_object name, attr
+ l.boosts 'post'
if r == false
l.errors.add :base, SystemPicture.model_name.human + I18n.t('errors.not_create')
else
if r == false
l.errors.add :base, SystemPicture.model_name.human + I18n.t('errors.not_create')
else
@@
-82,21
+70,10
@@
class License < ActiveRecord::Base
res
end
res
end
- def credit_pictures_attr
- return @credit_pictures_attr if @credit_pictures_attr
- begin
- @credit_pictures_attr = JSON.parse(self.credit_pictures)
- rescue
- end
- @credit_pictures_attr = {} unless @credit_pictures_attr
- @credit_pictures_attr
- end
-
def self.export(dt = nil)
def self.export(dt = nil)
- opt = {}
- opt.merge!({:conditions => ['updated_at >= ?', dt]}) if dt
-# opt.merge!({:order => 'name'})
- License.find(:all, opt)
+ licenses = License.all
+ licenses = licenses.where(['licenses.updated_at >= ?', dt]) if dt
+ licenses.order(:id)
end
end
end
end