Sha256: 97d69cfd8d3956a822b9c889013b9a7d4557cdeeb671bdaa20e63540d66cd97a

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

require 'json'
require 'yaml'

module Faalis
  module Generators
    module Concerns
      # This module Provide an argument for generator which
      # is needed by other `Concerns`.
      # Each Concern will have its own entry in scaffold json
      # file. For documentation on each entry checkout its concern class
      module InputFile

        def self.included(base)
          # Name of the resource to create.
          base.argument :input_file , :type => :string, :required => true
        end

        private

        # Return absolute path to input file
        def file_path
          File.expand_path(input_file)
        end
        # Get the extension name of input file
        def extname
          File.extname(file_path)
        end

        # Read the json or yaml file and returns its raw data
        def input_file_data
          File.read(file_path)
        end

        # Return the hash related to json or yaml structure from cache or by
        # reading file.
        def resource_data
          if @data
            @data
          else
            @data = JSON.parse(input_file_data) if extname == '.json'
            @data = YAML.load_file(file_path) if extname == '.yml'
            @data
          end
        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
faalis-2.0.0.rc6 lib/faalis/generators/concerns/input_file.rb
faalis-2.0.0.rc5 lib/faalis/generators/concerns/input_file.rb
faalis-2.0.0.rc4 lib/faalis/generators/concerns/input_file.rb
faalis-2.0.0.rc3 lib/faalis/generators/concerns/input_file.rb
faalis-2.0.0.rc2 lib/faalis/generators/concerns/input_file.rb
faalis-1.0.0 lib/faalis/generators/concerns/input_file.rb
faalis-1.0.0.alpha4 lib/faalis/generators/concerns/input_file.rb
faalis-1.0.0.alpha3 lib/faalis/generators/concerns/input_file.rb
faalis-1.0.0.alpha2 lib/faalis/generators/concerns/input_file.rb