Sha256: 942a17d7d02c2e891662384624ed464b01c6bfd47f4d9ca2ab979d53add2fd35

Contents?: true

Size: 1.54 KB

Versions: 22

Compression:

Stored size: 1.54 KB

Contents

module Rubicure
  # Precure All Stars Movie
  #
  # this is record of "config/movies.yml"
  class Movie < Hash
    include Hashie::Extensions::MethodAccess

    class << self
      include Rubicure::Concerns::Util

      # @return [Array<Symbol>]
      def names
        config.keys
      end

      # @return [Array<Symbol>]
      def uniq_names
        uniq_names = []
        config.each do |name, series|
          uniq_names << name unless uniq_names.any? {|uniq_name| config[uniq_name][:title] == series[:title] }
        end
        uniq_names
      end

      # @return [Hash] content of config/movies.yml
      def config
        unless @config
          config_file = "#{File.dirname(__FILE__)}/../../config/movies.yml"
          @config = load_yaml_file(config_file).deep_symbolize_keys
        end
        @config
      end

      # @return [Hash] content of config/movies.yml
      def reload_config!
        @cache = {}
        @config = nil
        config
      end

      # @param [Symbol] series_name
      def valid?(series_name)
        names.include?(series_name)
      end

      # @param movie_name [Symbol]
      # @return [Rubicure::Movie]
      # @raise arg is invalid
      def find(movie_name)
        raise UnknownMovieError, "unknown movie: #{movie_name}" unless valid?(movie_name)

        @cache ||= {}
        unless @cache[movie_name]
          movie_config = config[movie_name] || {}
          movie_config.compact!

          @cache[movie_name] = Rubicure::Movie[movie_config]
        end

        @cache[movie_name]
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rubicure-3.3.3 lib/rubicure/movie.rb
rubicure-3.3.2 lib/rubicure/movie.rb
rubicure-3.3.1 lib/rubicure/movie.rb
rubicure-3.3.0 lib/rubicure/movie.rb
rubicure-3.3.0.rc2 lib/rubicure/movie.rb
rubicure-3.3.0.rc1 lib/rubicure/movie.rb
rubicure-3.2.6 lib/rubicure/movie.rb
rubicure-3.2.5 lib/rubicure/movie.rb
rubicure-3.2.4 lib/rubicure/movie.rb
rubicure-3.2.3 lib/rubicure/movie.rb
rubicure-3.2.2 lib/rubicure/movie.rb
rubicure-3.2.1 lib/rubicure/movie.rb
rubicure-3.2.0 lib/rubicure/movie.rb
rubicure-3.2.0.rc1 lib/rubicure/movie.rb
rubicure-3.1.5 lib/rubicure/movie.rb
rubicure-3.1.4 lib/rubicure/movie.rb
rubicure-3.1.3 lib/rubicure/movie.rb
rubicure-3.1.2 lib/rubicure/movie.rb
rubicure-3.1.1 lib/rubicure/movie.rb
rubicure-3.1.0 lib/rubicure/movie.rb