Methods
Attributes
[R] | publish_states | |
[R] | publish_states_for_validation |
Instance Public methods
all(*args)
Link
Overriding the normal all method to add some extra sugar.
Examples
Article.all => returns all Articles as usual Article.all( :publish_status => :live ) => returns all Articles with :publish_status == :lve Article.all(:draft) => returns all Articles with :publish_status == :draft Article.all(:draft, :author => @author_joe ) => finds all Articles with :publish_status = :draft and author == Joe
@api public/private
Source: show
# File lib/is/published.rb, line 216 def all(*args) # incoming can either be: # -- nil (nothing passed in, so just use super ) # -- (Hash) => all(:key => "value") ( normal operations, so just pass on the Hash ) # -- (Symbol) => all(:draft) ( just get the symbol, ) # -- (Symbol, Hash ) => :draft, { extra options } # -- (DataMapper somethings) => leave it alone if args.empty? return super elsif args.first.is_a?(Symbol) # set the from args Array, remove first item if Symbol, and then check for 2nd item's presence state, options = args.shift.to_s, (args.blank? ? {} : args.first) # puts " and state=[#{state}] and options=[#{options.class}] options.inspect=[#{options.inspect}] [#{__FILE__}:#{__LINE__}]" return super({ :publish_status => state }.merge(options) ) elsif args.first.is_a?(Hash) # puts "dm-is-published args.first was a HASH ] [#{__FILE__}:#{__LINE__}]" return super(args.first) else # puts "dm-is-published (ELSE) [#{__FILE__}:#{__LINE__}]" return super end end
publish_states_as_json()
Link
Returns a JSON representation of the publish states, where each state is represented as a lowercase key and an uppercase value.
Examples
Model.publish_states_as_json => { 'live': 'LIVE','draft': 'DRAFT','hidden': 'HIDDEN' }
@api public
Source: show
# File lib/is/published.rb, line 197 def publish_states_as_json %Q[{ #{self.publish_states_for_validation.collect{ |state| "'#{state.to_s.downcase}': '#{state.to_s.upcase}'" }.join(',')} }] end